Пример #1
0
def getSegmentsFromPoints(loops, pointBegin, pointEnd):
    "Get endpoint segments from the beginning and end of a line segment."
    normalizedSegment = pointEnd - pointBegin
    normalizedSegmentLength = abs(normalizedSegment)
    if normalizedSegmentLength == 0.0:
        return []
    normalizedSegment /= normalizedSegmentLength
    segmentYMirror = complex(normalizedSegment.real, -normalizedSegment.imag)
    pointBeginRotated = segmentYMirror * pointBegin
    pointEndRotated = segmentYMirror * pointEnd
    xIntersectionIndexList = []
    xIntersectionIndexList.append(
        euclidean.XIntersectionIndex(-1, pointBeginRotated.real))
    xIntersectionIndexList.append(
        euclidean.XIntersectionIndex(-1, pointEndRotated.real))
    for loopIndex in xrange(len(loops)):
        rotatedLoop = euclidean.getPointsRoundZAxis(segmentYMirror,
                                                    loops[loopIndex])
        euclidean.addXIntersectionIndexesFromLoopY(rotatedLoop, loopIndex,
                                                   xIntersectionIndexList,
                                                   pointBeginRotated.imag)
    segments = euclidean.getSegmentsFromXIntersectionIndexes(
        xIntersectionIndexList, pointBeginRotated.imag)
    for segment in segments:
        for endpoint in segment:
            endpoint.point *= normalizedSegment
    return segments
Пример #2
0
 def getBoundaryIndexes(self, begin, boundaries, end, points):
     'Get boundary indexes and set the points in the way of the original line segment.'
     boundaryIndexes = []
     points.append(begin)
     switchX = []
     segment = euclidean.getNormalized(end - begin)
     segmentYMirror = complex(segment.real, -segment.imag)
     beginRotated = segmentYMirror * begin
     endRotated = segmentYMirror * end
     y = beginRotated.imag
     for boundaryIndex in xrange(len(boundaries)):
         boundary = boundaries[boundaryIndex]
         boundaryRotated = euclidean.getRotatedComplexes(
             segmentYMirror, boundary)
         euclidean.addXIntersectionIndexesFromLoopY(boundaryRotated,
                                                    boundaryIndex, switchX,
                                                    y)
     switchX.sort()
     maximumX = max(beginRotated.real, endRotated.real)
     minimumX = min(beginRotated.real, endRotated.real)
     for xIntersection in switchX:
         if xIntersection.x > minimumX and xIntersection.x < maximumX:
             point = segment * complex(xIntersection.x, y)
             points.append(point)
             boundaryIndexes.append(xIntersection.index)
     points.append(end)
     return boundaryIndexes
Пример #3
0
def getOverhangDirection(belowOutsetLoops, segmentBegin, segmentEnd):
    'Add to span direction from the endpoint segments which overhang the layer below.'
    segment = segmentEnd - segmentBegin
    normalizedSegment = euclidean.getNormalized(
        complex(segment.real, segment.imag))
    segmentYMirror = complex(normalizedSegment.real, -normalizedSegment.imag)
    segmentBegin = segmentYMirror * segmentBegin
    segmentEnd = segmentYMirror * segmentEnd
    solidXIntersectionList = []
    y = segmentBegin.imag
    solidXIntersectionList.append(
        euclidean.XIntersectionIndex(-1.0, segmentBegin.real))
    solidXIntersectionList.append(
        euclidean.XIntersectionIndex(-1.0, segmentEnd.real))
    for belowLoopIndex in xrange(len(belowOutsetLoops)):
        belowLoop = belowOutsetLoops[belowLoopIndex]
        rotatedOutset = euclidean.getRotatedComplexes(segmentYMirror,
                                                      belowLoop)
        euclidean.addXIntersectionIndexesFromLoopY(rotatedOutset,
                                                   belowLoopIndex,
                                                   solidXIntersectionList, y)
    overhangingSegments = euclidean.getSegmentsFromXIntersectionIndexes(
        solidXIntersectionList, y)
    overhangDirection = complex()
    for overhangingSegment in overhangingSegments:
        overhangDirection += getDoubledRoundZ(overhangingSegment,
                                              normalizedSegment)
    return overhangDirection
Пример #4
0
    def getPathsBetween(self, begin, end):
        "Insert paths between the perimeter and the fill."
        aroundBetweenPath = []
        points = [begin]
        lineX = []
        switchX = []
        segment = euclidean.getNormalized(end - begin)
        segmentYMirror = complex(segment.real, -segment.imag)
        beginRotated = segmentYMirror * begin
        endRotated = segmentYMirror * end
        y = beginRotated.imag
        boundaries = self.getBoundaries()
        for boundaryIndex in xrange(len(boundaries)):
            boundary = boundaries[boundaryIndex]
            boundaryRotated = euclidean.getPointsRoundZAxis(
                segmentYMirror, boundary)
            euclidean.addXIntersectionIndexesFromLoopY(boundaryRotated,
                                                       boundaryIndex, switchX,
                                                       y)
        switchX.sort()
        maximumX = max(beginRotated.real, endRotated.real)
        minimumX = min(beginRotated.real, endRotated.real)
        for xIntersection in switchX:
            if xIntersection.x > minimumX and xIntersection.x < maximumX:
                point = segment * complex(xIntersection.x, y)
                points.append(point)
                lineX.append(xIntersection)
        points.append(end)
        lineXIndex = 0
        #		pathBetweenAdded = False
        while lineXIndex < len(lineX) - 1:
            lineXFirst = lineX[lineXIndex]
            lineXSecond = lineX[lineXIndex + 1]
            loopFirst = boundaries[lineXFirst.index]
            if lineXSecond.index == lineXFirst.index:
                pathBetween = self.getPathBetween(
                    loopFirst, points[lineXIndex:lineXIndex + 4])
                pathBetween = self.getSimplifiedAroundPath(
                    points[lineXIndex], points[lineXIndex + 3], loopFirst,
                    pathBetween)
                aroundBetweenPath += pathBetween
                lineXIndex += 2
            else:
                lineXIndex += 1


#			isLeavingPerimeter = False
#			if lineXSecond.index != lineXFirst.index:
#				isLeavingPerimeter = True
#			pathBetween = self.getPathBetween( points[ lineXIndex + 1 ], points[ lineXIndex + 2 ], isLeavingPerimeter, loopFirst )
#			if isLeavingPerimeter:
#				pathBetweenAdded = True
#			else:
#				pathBetween = self.getSimplifiedAroundPath( points[ lineXIndex ], points[ lineXIndex + 3 ], loopFirst, pathBetween )
#				pathBetweenAdded = True
#			aroundBetweenPath += pathBetween
#			lineXIndex += 2
        return aroundBetweenPath
Пример #5
0
 def getPathsBetween(self, begin, end):
     "Insert paths between the perimeter and the fill."
     aroundBetweenPath = []
     points = [begin]
     lineX = []
     switchX = []
     segment = euclidean.getNormalized(end - begin)
     segmentYMirror = complex(segment.real, -segment.imag)
     beginRotated = segmentYMirror * begin
     endRotated = segmentYMirror * end
     y = beginRotated.imag
     boundaries = self.getBoundaries()
     for boundaryIndex in xrange(len(boundaries)):
         boundary = boundaries[boundaryIndex]
         boundaryRotated = euclidean.getRotatedComplexes(segmentYMirror, boundary)
         euclidean.addXIntersectionIndexesFromLoopY(boundaryRotated, boundaryIndex, switchX, y)
     switchX.sort()
     maximumX = max(beginRotated.real, endRotated.real)
     minimumX = min(beginRotated.real, endRotated.real)
     for xIntersection in switchX:
         if xIntersection.x > minimumX and xIntersection.x < maximumX:
             point = segment * complex(xIntersection.x, y)
             points.append(point)
             lineX.append(xIntersection)
     points.append(end)
     lineXIndex = 0
     # 		pathBetweenAdded = False
     while lineXIndex < len(lineX) - 1:
         lineXFirst = lineX[lineXIndex]
         lineXSecond = lineX[lineXIndex + 1]
         loopFirst = boundaries[lineXFirst.index]
         if lineXSecond.index == lineXFirst.index:
             pathBetween = self.getPathBetween(loopFirst, points[lineXIndex : lineXIndex + 4])
             pathBetween = self.getSimplifiedAroundPath(
                 points[lineXIndex], points[lineXIndex + 3], loopFirst, pathBetween
             )
             aroundBetweenPath += pathBetween
             lineXIndex += 2
         else:
             lineXIndex += 1
     # 			isLeavingPerimeter = False
     # 			if lineXSecond.index != lineXFirst.index:
     # 				isLeavingPerimeter = True
     # 			pathBetween = self.getPathBetween( points[ lineXIndex + 1 ], points[ lineXIndex + 2 ], isLeavingPerimeter, loopFirst )
     # 			if isLeavingPerimeter:
     # 				pathBetweenAdded = True
     # 			else:
     # 				pathBetween = self.getSimplifiedAroundPath( points[ lineXIndex ], points[ lineXIndex + 3 ], loopFirst, pathBetween )
     # 				pathBetweenAdded = True
     # 			aroundBetweenPath += pathBetween
     # 			lineXIndex += 2
     return aroundBetweenPath
Пример #6
0
def getOverhangDirection( belowOutsetLoops, segmentBegin, segmentEnd ):
	'Add to span direction from the endpoint segments which overhang the layer below.'
	segment = segmentEnd - segmentBegin
	normalizedSegment = euclidean.getNormalized( complex( segment.real, segment.imag ) )
	segmentYMirror = complex(normalizedSegment.real, -normalizedSegment.imag)
	segmentBegin = segmentYMirror * segmentBegin
	segmentEnd = segmentYMirror * segmentEnd
	solidXIntersectionList = []
	y = segmentBegin.imag
	solidXIntersectionList.append( euclidean.XIntersectionIndex( - 1.0, segmentBegin.real ) )
	solidXIntersectionList.append( euclidean.XIntersectionIndex( - 1.0, segmentEnd.real ) )
	for belowLoopIndex in xrange( len( belowOutsetLoops ) ):
		belowLoop = belowOutsetLoops[ belowLoopIndex ]
		rotatedOutset = euclidean.getRotatedComplexes( segmentYMirror, belowLoop )
		euclidean.addXIntersectionIndexesFromLoopY( rotatedOutset, belowLoopIndex, solidXIntersectionList, y )
	overhangingSegments = euclidean.getSegmentsFromXIntersectionIndexes( solidXIntersectionList, y )
	overhangDirection = complex()
	for overhangingSegment in overhangingSegments:
		overhangDirection += getDoubledRoundZ( overhangingSegment, normalizedSegment )
	return overhangDirection
Пример #7
0
def getSegmentsFromPoints( loops, pointBegin, pointEnd ):
	"Get endpoint segments from the beginning and end of a line segment."
	normalizedSegment = pointEnd - pointBegin
	normalizedSegmentLength = abs( normalizedSegment )
	if normalizedSegmentLength == 0.0:
		return []
	normalizedSegment /= normalizedSegmentLength
	segmentYMirror = complex( normalizedSegment.real, - normalizedSegment.imag )
	pointBeginRotated = segmentYMirror * pointBegin
	pointEndRotated = segmentYMirror * pointEnd
	xIntersectionIndexList = []
	xIntersectionIndexList.append( euclidean.XIntersectionIndex( - 1, pointBeginRotated.real ) )
	xIntersectionIndexList.append( euclidean.XIntersectionIndex( - 1, pointEndRotated.real ) )
	for loopIndex in xrange( len( loops ) ):
		rotatedLoop = euclidean.getPointsRoundZAxis( segmentYMirror, loops[ loopIndex ] )
		euclidean.addXIntersectionIndexesFromLoopY( rotatedLoop, loopIndex, xIntersectionIndexList, pointBeginRotated.imag )
	segments = euclidean.getSegmentsFromXIntersectionIndexes( xIntersectionIndexList, pointBeginRotated.imag )
	for segment in segments:
		for endpoint in segment:
			endpoint.point *= normalizedSegment
	return segments
Пример #8
0
 def getBoundaryIndexes(self, begin, boundaries, end, points):
     "Get boundary indexes and set the points in the way of the original line segment."
     boundaryIndexes = []
     points.append(begin)
     switchX = []
     segment = euclidean.getNormalized(end - begin)
     segmentYMirror = complex(segment.real, -segment.imag)
     beginRotated = segmentYMirror * begin
     endRotated = segmentYMirror * end
     y = beginRotated.imag
     for boundaryIndex in xrange(len(boundaries)):
         boundary = boundaries[boundaryIndex]
         boundaryRotated = euclidean.getRotatedComplexes(segmentYMirror, boundary)
         euclidean.addXIntersectionIndexesFromLoopY(boundaryRotated, boundaryIndex, switchX, y)
     switchX.sort()
     maximumX = max(beginRotated.real, endRotated.real)
     minimumX = min(beginRotated.real, endRotated.real)
     for xIntersection in switchX:
         if xIntersection.x > minimumX and xIntersection.x < maximumX:
             point = segment * complex(xIntersection.x, y)
             points.append(point)
             boundaryIndexes.append(xIntersection.index)
     points.append(end)
     return boundaryIndexes