Exemple #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
Exemple #2
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
Exemple #3
0
def getSegmentsFromLoopListsPoints(loopLists, 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
    rotatedLoopLists = []
    for loopList in loopLists:
        rotatedLoopLists.append(
            euclidean.getRotatedComplexLists(segmentYMirror, loopList))
    xIntersectionIndexList = []
    xIntersectionIndexList.append(
        euclidean.XIntersectionIndex(-1, pointBeginRotated.real))
    xIntersectionIndexList.append(
        euclidean.XIntersectionIndex(-1, pointEndRotated.real))
    euclidean.addXIntersectionIndexesFromLoopListsY(rotatedLoopLists,
                                                    xIntersectionIndexList,
                                                    pointBeginRotated.imag)
    segments = euclidean.getSegmentsFromXIntersectionIndexes(
        xIntersectionIndexList, pointBeginRotated.imag)
    for segment in segments:
        for endpoint in segment:
            endpoint.point *= normalizedSegment
    return segments
Exemple #4
0
 def getDistance(self):
     "Get distance between point and closest intersection or bottom point along line."
     self.pointMinusBottomY = self.alongAway.point.y - self.alongAway.minimumY
     self.diagonalDistance = self.pointMinusBottomY * self.diagonalRatio
     if self.alongAway.pointIndex == None:
         return self.getDistanceToBottom()
     rotatedLoop = euclidean.getRotatedComplexes(
         self.intersectionYMirror,
         euclidean.getComplexPath(self.alongAway.loop))
     rotatedPointComplex = rotatedLoop[self.alongAway.pointIndex]
     beginX = rotatedPointComplex.real
     endX = beginX + self.diagonalDistance + self.diagonalDistance
     xIntersectionIndexList = []
     for pointIndex in self.alongAway.awayIndexes:
         beginComplex = rotatedLoop[pointIndex]
         endComplex = rotatedLoop[(pointIndex + 1) % len(rotatedLoop)]
         xIntersection = euclidean.getXIntersectionIfExists(
             beginComplex, endComplex, rotatedPointComplex.imag)
         if xIntersection != None:
             if xIntersection >= beginX and xIntersection < endX:
                 xIntersectionIndexList.append(
                     euclidean.XIntersectionIndex(pointIndex,
                                                  xIntersection))
     self.closestXDistance = 987654321.0
     self.closestXIntersectionIndex = None
     for xIntersectionIndex in xIntersectionIndexList:
         xDistance = abs(xIntersectionIndex.x - beginX)
         if xDistance < self.closestXDistance:
             self.closestXIntersectionIndex = xIntersectionIndex
             self.closestXDistance = xDistance
     if self.closestXIntersectionIndex != None:
         return self.closestXDistance
     return self.getDistanceToBottom()