def getPathBetween(self, betweenFirst, betweenSecond, isLeavingPerimeter, loopFirst): "Add a path between the perimeter and the fill." loopFirst = intercircle.getLargestInsetLoopFromLoopNoMatterWhat( loopFirst, self.combInset) nearestFirstDistanceIndex = euclidean.getNearestDistanceIndex( betweenFirst, loopFirst) nearestSecondDistanceIndex = euclidean.getNearestDistanceIndex( betweenSecond, loopFirst) firstBeginIndex = (nearestFirstDistanceIndex.index + 1) % len(loopFirst) secondBeginIndex = (nearestSecondDistanceIndex.index + 1) % len(loopFirst) nearestFirst = euclidean.getNearestPointOnSegment( loopFirst[nearestFirstDistanceIndex.index], loopFirst[firstBeginIndex], betweenFirst) nearestSecond = euclidean.getNearestPointOnSegment( loopFirst[nearestSecondDistanceIndex.index], loopFirst[secondBeginIndex], betweenSecond) clockwisePath = [nearestFirst] widdershinsPath = [nearestFirst] loopBeforeLeaving = euclidean.getAroundLoop(firstBeginIndex, firstBeginIndex, loopFirst) if nearestFirstDistanceIndex.index == nearestSecondDistanceIndex.index: if euclidean.getPathLength( widdershinsPath) < self.minimumDepartureDistance: widdershinsPath = [nearestFirst] + loopBeforeLeaving reversedLoop = loopBeforeLeaving[:] reversedLoop.reverse() clockwisePath = [nearestFirst] + reversedLoop else: widdershinsLoop = euclidean.getAroundLoop(firstBeginIndex, secondBeginIndex, loopFirst) widdershinsPath += widdershinsLoop clockwiseLoop = euclidean.getAroundLoop(secondBeginIndex, firstBeginIndex, loopFirst) clockwiseLoop.reverse() clockwisePath += clockwiseLoop clockwisePath.append(nearestSecond) widdershinsPath.append(nearestSecond) if euclidean.getPathLength(widdershinsPath) > euclidean.getPathLength( clockwisePath): loopBeforeLeaving.reverse() widdershinsPath = clockwisePath if isLeavingPerimeter: totalDistance = euclidean.getPathLength(widdershinsPath) loopLength = euclidean.getPolygonLength(loopBeforeLeaving) while totalDistance < self.minimumDepartureDistance: widdershinsPath = [nearestFirst ] + loopBeforeLeaving + widdershinsPath[1:] totalDistance += loopLength return widdershinsPath
def addPathBetween(self, aroundBetweenPath, betweenFirst, betweenSecond, isLeavingPerimeter, loopFirst): "Add a path between the perimeter and the fill." clockwisePath = [betweenFirst] widdershinsPath = [betweenFirst] nearestFirstDistanceIndex = euclidean.getNearestDistanceIndex( betweenFirst, loopFirst) nearestSecondDistanceIndex = euclidean.getNearestDistanceIndex( betweenSecond, loopFirst) firstBeginIndex = (nearestFirstDistanceIndex.index + 1) % len(loopFirst) secondBeginIndex = (nearestSecondDistanceIndex.index + 1) % len(loopFirst) loopBeforeLeaving = euclidean.getAroundLoop(firstBeginIndex, firstBeginIndex, loopFirst) if nearestFirstDistanceIndex.index == nearestSecondDistanceIndex.index: nearestPoint = euclidean.getNearestPointOnSegment( loopFirst[nearestSecondDistanceIndex.index], loopFirst[secondBeginIndex], betweenSecond) widdershinsPath += [nearestPoint] clockwisePath += [nearestPoint] if euclidean.getPathLength( widdershinsPath) < self.minimumPerimeterDepartureDistance: widdershinsPath = [betweenFirst ] + loopBeforeLeaving + [nearestPoint] reversedLoop = loopBeforeLeaving[:] reversedLoop.reverse() clockwisePath = [betweenFirst] + reversedLoop + [nearestPoint] else: widdershinsLoop = euclidean.getAroundLoop(firstBeginIndex, secondBeginIndex, loopFirst) widdershinsPath += widdershinsLoop clockwiseLoop = euclidean.getAroundLoop(secondBeginIndex, firstBeginIndex, loopFirst) clockwiseLoop.reverse() clockwisePath += clockwiseLoop clockwisePath.append(betweenSecond) widdershinsPath.append(betweenSecond) if euclidean.getPathLength(widdershinsPath) > euclidean.getPathLength( clockwisePath): loopBeforeLeaving.reverse() widdershinsPath = clockwisePath if isLeavingPerimeter: totalDistance = euclidean.getPathLength(widdershinsPath) loopLength = euclidean.getPolygonLength(loopBeforeLeaving) while totalDistance < self.minimumPerimeterDepartureDistance: widdershinsPath = [betweenFirst ] + loopBeforeLeaving + widdershinsPath[1:] totalDistance += loopLength aroundBetweenPath += widdershinsPath
def getJitteredLoop( self, jitterDistance, jitterLoop ): "Get a jittered loop path." loopLength = euclidean.getPolygonLength( jitterLoop ) lastLength = 0.0 pointIndex = 0 totalLength = 0.0 jitterPosition = ( jitterDistance + 256.0 * loopLength ) % loopLength while totalLength < jitterPosition and pointIndex < len( jitterLoop ): firstPoint = jitterLoop[ pointIndex ] secondPoint = jitterLoop[ ( pointIndex + 1 ) % len( jitterLoop ) ] pointIndex += 1 lastLength = totalLength totalLength += abs( firstPoint - secondPoint ) remainingLength = jitterPosition - lastLength pointIndex = pointIndex % len( jitterLoop ) ultimateJitteredPoint = jitterLoop[ pointIndex ] penultimateJitteredPointIndex = ( pointIndex + len( jitterLoop ) - 1 ) % len( jitterLoop ) penultimateJitteredPoint = jitterLoop[ penultimateJitteredPointIndex ] segment = ultimateJitteredPoint - penultimateJitteredPoint segmentLength = abs( segment ) originalOffsetLoop = euclidean.getAroundLoop( pointIndex, pointIndex, jitterLoop ) if segmentLength <= 0.0: return originalOffsetLoop newUltimatePoint = penultimateJitteredPoint + segment * remainingLength / segmentLength return [ newUltimatePoint ] + originalOffsetLoop
def getJitteredLoop(self, jitterDistance, jitterLoop): "Get a jittered loop path." loopLength = euclidean.getPolygonLength(jitterLoop) lastLength = 0.0 pointIndex = 0 totalLength = 0.0 jitterPosition = (jitterDistance + 256.0 * loopLength) % loopLength while totalLength < jitterPosition and pointIndex < len(jitterLoop): firstPoint = jitterLoop[pointIndex] secondPoint = jitterLoop[(pointIndex + 1) % len(jitterLoop)] pointIndex += 1 lastLength = totalLength totalLength += abs(firstPoint - secondPoint) remainingLength = jitterPosition - lastLength pointIndex = pointIndex % len(jitterLoop) ultimateJitteredPoint = jitterLoop[pointIndex] penultimateJitteredPointIndex = (pointIndex + len(jitterLoop) - 1) % len(jitterLoop) penultimateJitteredPoint = jitterLoop[penultimateJitteredPointIndex] segment = ultimateJitteredPoint - penultimateJitteredPoint segmentLength = abs(segment) originalOffsetLoop = euclidean.getAroundLoop(pointIndex, pointIndex, jitterLoop) if segmentLength <= 0.0: return [penultimateJitteredPoint] + originalOffsetLoop[-1] newUltimatePoint = penultimateJitteredPoint + segment * remainingLength / segmentLength return [newUltimatePoint] + originalOffsetLoop
def getPathBetween(self, betweenFirst, betweenSecond, isLeavingPerimeter, loopFirst): "Add a path between the perimeter and the fill." loopFirst = intercircle.getLargestInsetLoopFromLoopNoMatterWhat(loopFirst, self.combInset) nearestFirstDistanceIndex = euclidean.getNearestDistanceIndex(betweenFirst, loopFirst) nearestSecondDistanceIndex = euclidean.getNearestDistanceIndex(betweenSecond, loopFirst) firstBeginIndex = (nearestFirstDistanceIndex.index + 1) % len(loopFirst) secondBeginIndex = (nearestSecondDistanceIndex.index + 1) % len(loopFirst) nearestFirst = euclidean.getNearestPointOnSegment( loopFirst[nearestFirstDistanceIndex.index], loopFirst[firstBeginIndex], betweenFirst ) nearestSecond = euclidean.getNearestPointOnSegment( loopFirst[nearestSecondDistanceIndex.index], loopFirst[secondBeginIndex], betweenSecond ) clockwisePath = [nearestFirst] widdershinsPath = [nearestFirst] loopBeforeLeaving = euclidean.getAroundLoop(firstBeginIndex, firstBeginIndex, loopFirst) if nearestFirstDistanceIndex.index == nearestSecondDistanceIndex.index: if euclidean.getPathLength(widdershinsPath) < self.minimumDepartureDistance: widdershinsPath = [nearestFirst] + loopBeforeLeaving reversedLoop = loopBeforeLeaving[:] reversedLoop.reverse() clockwisePath = [nearestFirst] + reversedLoop else: widdershinsLoop = euclidean.getAroundLoop(firstBeginIndex, secondBeginIndex, loopFirst) widdershinsPath += widdershinsLoop clockwiseLoop = euclidean.getAroundLoop(secondBeginIndex, firstBeginIndex, loopFirst) clockwiseLoop.reverse() clockwisePath += clockwiseLoop clockwisePath.append(nearestSecond) widdershinsPath.append(nearestSecond) if euclidean.getPathLength(widdershinsPath) > euclidean.getPathLength(clockwisePath): loopBeforeLeaving.reverse() widdershinsPath = clockwisePath if isLeavingPerimeter: totalDistance = euclidean.getPathLength(widdershinsPath) loopLength = euclidean.getPolygonLength(loopBeforeLeaving) while totalDistance < self.minimumDepartureDistance: widdershinsPath = [nearestFirst] + loopBeforeLeaving + widdershinsPath[1:] totalDistance += loopLength return widdershinsPath
def addPathBetween( self, aroundBetweenPath, betweenFirst, betweenSecond, isLeavingPerimeter, loopFirst ): "Add a path between the perimeter and the fill." clockwisePath = [ betweenFirst ] widdershinsPath = [ betweenFirst ] nearestFirstDistanceIndex = euclidean.getNearestDistanceIndex( betweenFirst, loopFirst ) nearestSecondDistanceIndex = euclidean.getNearestDistanceIndex( betweenSecond, loopFirst ) firstBeginIndex = ( nearestFirstDistanceIndex.index + 1 ) % len( loopFirst ) secondBeginIndex = ( nearestSecondDistanceIndex.index + 1 ) % len( loopFirst ) loopBeforeLeaving = euclidean.getAroundLoop( firstBeginIndex, firstBeginIndex, loopFirst ) if nearestFirstDistanceIndex.index == nearestSecondDistanceIndex.index: nearestPoint = euclidean.getNearestPointOnSegment( loopFirst[ nearestSecondDistanceIndex.index ], loopFirst[ secondBeginIndex ], betweenSecond ) widdershinsPath += [ nearestPoint ] clockwisePath += [ nearestPoint ] if euclidean.getPathLength( widdershinsPath ) < self.minimumPerimeterDepartureDistance: widdershinsPath = [ betweenFirst ] + loopBeforeLeaving + [ nearestPoint ] reversedLoop = loopBeforeLeaving[ : ] reversedLoop.reverse() clockwisePath = [ betweenFirst ] + reversedLoop + [ nearestPoint ] else: widdershinsLoop = euclidean.getAroundLoop( firstBeginIndex, secondBeginIndex, loopFirst ) widdershinsPath += widdershinsLoop clockwiseLoop = euclidean.getAroundLoop( secondBeginIndex, firstBeginIndex, loopFirst ) clockwiseLoop.reverse() clockwisePath += clockwiseLoop clockwisePath.append( betweenSecond ) widdershinsPath.append( betweenSecond ) if euclidean.getPathLength( widdershinsPath ) > euclidean.getPathLength( clockwisePath ): loopBeforeLeaving.reverse() widdershinsPath = clockwisePath if isLeavingPerimeter: totalDistance = euclidean.getPathLength( widdershinsPath ) loopLength = euclidean.getPolygonLength( loopBeforeLeaving ) while totalDistance < self.minimumPerimeterDepartureDistance: widdershinsPath = [ betweenFirst ] + loopBeforeLeaving + widdershinsPath[ 1 : ] totalDistance += loopLength aroundBetweenPath += widdershinsPath