def getPathBetween(self, loop, points): "Add a path between the edge and the fill." paths = getPathsByIntersectedLoop(points[1], points[2], loop) shortestPath = paths[int( euclidean.getPathLength(paths[1]) < euclidean.getPathLength( paths[0]))] if len(shortestPath) < 2: return shortestPath if abs(points[1] - shortestPath[0]) > abs(points[1] - shortestPath[-1]): shortestPath.reverse() loopWiddershins = euclidean.isWiddershins(loop) pathBetween = [] for pointIndex in xrange(len(shortestPath)): center = shortestPath[pointIndex] centerPerpendicular = None beginIndex = pointIndex - 1 if beginIndex >= 0: begin = shortestPath[beginIndex] # with "self.edgeWidth*2.0" better "combed". See calibration file comb_test.stl . centerPerpendicular = intercircle.getWiddershinsByLength( center, begin, self.edgeWidth * 2.0) centerEnd = None endIndex = pointIndex + 1 if endIndex < len(shortestPath): end = shortestPath[endIndex] # with "self.edgeWidth*2.0" better "combed". See calibration file comb_test.stl . centerEnd = intercircle.getWiddershinsByLength( end, center, self.edgeWidth * 2.0) if centerPerpendicular == None: centerPerpendicular = centerEnd elif centerEnd != None: centerPerpendicular = 0.5 * (centerPerpendicular + centerEnd) between = None if centerPerpendicular == None: between = center if between == None: centerSideWiddershins = center + centerPerpendicular if euclidean.isPointInsideLoop( loop, centerSideWiddershins) == loopWiddershins: between = centerSideWiddershins if between == None: centerSideClockwise = center - centerPerpendicular if euclidean.isPointInsideLoop( loop, centerSideClockwise) == loopWiddershins: between = centerSideClockwise if between == None: between = center pathBetween.append(between) return pathBetween
def getSmallestEnclosureIndex(self, point): 'Get the index of the smallest boundary loop which encloses the point.' boundaryLayer = self.boundaryLayers[self.layerIndex] for loopIndex, loop in enumerate(boundaryLayer.loops): if euclidean.isPointInsideLoop(loop, point): return loopIndex return None
def getInsetLoopsFromLoop(loop, radius, thresholdRatio=0.9,outsetInnerMagic=1.0): 'Get the inset loops, which might overlap.' if radius == 0.0: return [loop] # figureout cw or ccw sum = 0; for index,v in enumerate(loop): sum+=(loop[(index+1)%len(loop)].imag-v.imag)*(loop[(index+1)%len(loop)].real+v.real) isInner = sum<0 innerMagic = 1.0 if isInner: innerMagic = outsetInnerMagic; #if isInner: # arounds = getAroundsFromLoop(loop, radius, thresholdRatio) #else: # arounds = getAroundsFromLoop(loop, radius, thresholdRatio) isInset = radius > 0 insetLoops = [] isLoopWiddershins = euclidean.isWiddershins(loop) arounds = getAroundsFromLoop(loop, radius, thresholdRatio,innerMagic) for around in arounds: leftPoint = euclidean.getLeftPoint(around) shouldBeWithin = (isInset == isLoopWiddershins) if euclidean.isPointInsideLoop(loop, leftPoint) == shouldBeWithin: if isLoopWiddershins != euclidean.isWiddershins(around): around.reverse() insetLoops.append(around) return insetLoops
def getIsPathEntirelyOutsideTriangle(begin, center, end, vector3Path): 'Determine if a path is entirely outside another loop.' loop = [begin.dropAxis(), center.dropAxis(), end.dropAxis()] for vector3 in vector3Path: point = vector3.dropAxis() if euclidean.isPointInsideLoop(loop, point): return False return True
def getJumpPointIfInside(boundary, otherPoint, perimeterWidth, runningJumpSpace): 'Get the jump point if it is inside the boundary, otherwise return None.' insetBoundary = intercircle.getSimplifiedInsetFromClockwiseLoop(boundary, -perimeterWidth) closestJumpDistanceIndex = euclidean.getClosestDistanceIndexToLine(otherPoint, insetBoundary) jumpIndex = (closestJumpDistanceIndex.index + 1) % len(insetBoundary) jumpPoint = euclidean.getClosestPointOnSegment(insetBoundary[closestJumpDistanceIndex.index], insetBoundary[jumpIndex], otherPoint) jumpPoint = getJumpPoint(jumpPoint, otherPoint, boundary, runningJumpSpace) if euclidean.isPointInsideLoop(boundary, jumpPoint): return jumpPoint return None
def getInsideness( path, loop ): "Get portion of the path which is inside the loop." if len( path ) < 2: return 0.0 pathLength = euclidean.getPathLength( path ) incrementRatio = 0.017 increment = incrementRatio * pathLength oldPoint = path[ 0 ] numberOfPointsInside = float( euclidean.isPointInsideLoop( loop, oldPoint ) ) for point in path[ 1 : ]: segment = point - oldPoint distance = abs( segment ) numberOfPosts = int( math.ceil( distance / increment ) ) if numberOfPosts > 0: segmentIncrement = segment / float( numberOfPosts ) for post in xrange( numberOfPosts ): postPoint = oldPoint + float( post ) * segmentIncrement numberOfPointsInside += float( euclidean.isPointInsideLoop( loop, postPoint ) ) oldPoint = point return incrementRatio * numberOfPointsInside
def getPathBetween(self, loop, points): "Add a path between the edge and the fill." paths = getPathsByIntersectedLoop(points[1], points[2], loop) shortestPath = paths[int(euclidean.getPathLength(paths[1]) < euclidean.getPathLength(paths[0]))] if len(shortestPath) < 2: return shortestPath if abs(points[1] - shortestPath[0]) > abs(points[1] - shortestPath[-1]): shortestPath.reverse() loopWiddershins = euclidean.isWiddershins(loop) pathBetween = [] for pointIndex in xrange(len(shortestPath)): center = shortestPath[pointIndex] centerPerpendicular = None beginIndex = pointIndex - 1 if beginIndex >= 0: begin = shortestPath[beginIndex] centerPerpendicular = intercircle.getWiddershinsByLength(center, begin, self.edgeWidth) centerEnd = None endIndex = pointIndex + 1 if endIndex < len(shortestPath): end = shortestPath[endIndex] centerEnd = intercircle.getWiddershinsByLength(end, center, self.edgeWidth) if centerPerpendicular == None: centerPerpendicular = centerEnd elif centerEnd != None: centerPerpendicular = 0.5 * (centerPerpendicular + centerEnd) between = None if centerPerpendicular == None: between = center if between == None: centerSideWiddershins = center + centerPerpendicular if euclidean.isPointInsideLoop(loop, centerSideWiddershins) == loopWiddershins: between = centerSideWiddershins if between == None: centerSideClockwise = center - centerPerpendicular if euclidean.isPointInsideLoop(loop, centerSideClockwise) == loopWiddershins: between = centerSideClockwise if between == None: between = center pathBetween.append(between) return pathBetween
def getInsideness(path, loop): "Get portion of the path which is inside the loop." if len(path) < 2: return 0.0 pathLength = euclidean.getPathLength(path) incrementRatio = 0.017 increment = incrementRatio * pathLength oldPoint = path[0] numberOfPointsInside = float(euclidean.isPointInsideLoop(loop, oldPoint)) for point in path[1:]: segment = point - oldPoint distance = abs(segment) numberOfPosts = int(math.ceil(distance / increment)) if numberOfPosts > 0: segmentIncrement = segment / float(numberOfPosts) for post in xrange(numberOfPosts): postPoint = oldPoint + float(post) * segmentIncrement numberOfPointsInside += float( euclidean.isPointInsideLoop(loop, postPoint)) oldPoint = point return incrementRatio * numberOfPointsInside
def __init__(self, begin, loop, runningJumpSpace, segment): 'Initialize' self.distance = 0.0 self.point = begin steps = 10 spaceOverSteps = runningJumpSpace / float(steps) for numerator in xrange(1, steps + 1): distance = float(numerator) * spaceOverSteps point = begin + segment * distance if euclidean.isPointInsideLoop(loop, point): self.distance = distance self.point = point else: return
def getInsetLoopsFromLoop(loop, radius, thresholdRatio=0.9): 'Get the inset loops, which might overlap.' isInset = radius > 0 insetLoops = [] isLoopWiddershins = euclidean.isWiddershins(loop) arounds = getAroundsFromLoop(loop, radius, thresholdRatio) for around in arounds: leftPoint = euclidean.getLeftPoint(around) shouldBeWithin = (isInset == isLoopWiddershins) if euclidean.isPointInsideLoop(loop, leftPoint) == shouldBeWithin: if isLoopWiddershins != euclidean.isWiddershins(around): around.reverse() insetLoops.append(around) return insetLoops
def getJumpPointIfInside(boundary, otherPoint, edgeWidth, runningJumpSpace): 'Get the jump point if it is inside the boundary, otherwise return None.' insetBoundary = intercircle.getSimplifiedInsetFromClockwiseLoop( boundary, -edgeWidth) closestJumpDistanceIndex = euclidean.getClosestDistanceIndexToLine( otherPoint, insetBoundary) jumpIndex = (closestJumpDistanceIndex.index + 1) % len(insetBoundary) jumpPoint = euclidean.getClosestPointOnSegment( insetBoundary[closestJumpDistanceIndex.index], insetBoundary[jumpIndex], otherPoint) jumpPoint = getJumpPoint(jumpPoint, otherPoint, boundary, runningJumpSpace) if euclidean.isPointInsideLoop(boundary, jumpPoint): return jumpPoint return None
def getInsetLoopsFromLoop(inset, loop, thresholdRatio=0.9): "Get the inset loops, which might overlap." isInset = inset > 0 insetLoops = [] isLoopWiddershins = euclidean.isWiddershins(loop) arounds = getAroundsFromLoop(loop, inset, thresholdRatio) for around in arounds: leftPoint = euclidean.getLeftPoint(around) shouldBeWithin = (isInset == isLoopWiddershins) if euclidean.isPointInsideLoop(loop, leftPoint) == shouldBeWithin: if isLoopWiddershins != euclidean.isWiddershins(around): around.reverse() insetLoops.append(around) return insetLoops
def __init__(self, begin, loop, runningJumpSpace, segment): "Initialize" self.distance = 0.0 self.point = begin steps = 10 spaceOverSteps = runningJumpSpace / float(steps) for numerator in xrange(1, steps + 1): distance = float(numerator) * spaceOverSteps point = begin + segment * distance if euclidean.isPointInsideLoop(loop, point): self.distance = distance self.point = point else: return
def getPathBetween( self, loop, points ): "Add a path between the perimeter and the fill." paths = getPathsByIntersectedLoop( points[ 1 ], points[ 2 ], loop ) shortestPath = paths[ int( euclidean.getPathLength( paths[ 1 ] ) < euclidean.getPathLength( paths[ 0 ] ) ) ] if not euclidean.isWiddershins( shortestPath ): shortestPath.reverse() loopAround = intercircle.getLargestInsetLoopFromLoopNoMatterWhat( shortestPath, - self.combInset ) endMinusBegin = points[ 3 ] - points[ 0 ] endMinusBegin = 1.3 * self.combInset * euclidean.getNormalized( endMinusBegin ) aroundPaths = getPathsByIntersectedLoop( points[ 0 ] - endMinusBegin, points[ 3 ] + endMinusBegin, loopAround ) insidePath = aroundPaths[ int( getInsideness( aroundPaths[ 1 ], loop ) > getInsideness( aroundPaths[ 0 ], loop ) ) ] pathBetween = [] for point in insidePath: if euclidean.isPointInsideLoop( loop, point ): pathBetween.append(point ) return pathBetween
def getPathBetween(self, loop, points): "Add a path between the perimeter and the fill." paths = getPathsByIntersectedLoop(points[1], points[2], loop) shortestPath = paths[int( euclidean.getPathLength(paths[1]) < euclidean.getPathLength( paths[0]))] if not euclidean.isWiddershins(shortestPath): shortestPath.reverse() loopAround = intercircle.getLargestInsetLoopFromLoopNoMatterWhat( shortestPath, -self.combInset) endMinusBegin = points[3] - points[0] endMinusBegin = 1.3 * self.combInset * euclidean.getNormalized( endMinusBegin) aroundPaths = getPathsByIntersectedLoop(points[0] - endMinusBegin, points[3] + endMinusBegin, loopAround) insidePath = aroundPaths[int( getInsideness(aroundPaths[1], loop) > getInsideness( aroundPaths[0], loop))] pathBetween = [] for point in insidePath: if euclidean.isPointInsideLoop(loop, point): pathBetween.append(point) return pathBetween
def getIsPointInsideALoop(loops, point): "Determine if a point is inside a loop of a loop list." for loop in loops: if euclidean.isPointInsideLoop(loop, point): return True return False
def getIsPointInsideALoop(loops, point): 'Determine if a point is inside a loop of a loop list.' for loop in loops: if euclidean.isPointInsideLoop(loop, point): return True return False