def removeIntersection( loop ): 'Get loop without the first intersection.' for pointIndex, ahead in enumerate(loop): behind = loop[ ( pointIndex + len( loop ) - 1 ) % len( loop ) ] behindEnd = loop[ ( pointIndex + len( loop ) - 2 ) % len( loop ) ] behindMidpoint = 0.5 * ( behind + behindEnd ) aheadEnd = loop[ (pointIndex + 1) % len( loop ) ] aheadMidpoint = 0.5 * ( ahead + aheadEnd ) normalizedSegment = behind - behindMidpoint normalizedSegmentLength = abs( normalizedSegment ) if normalizedSegmentLength > 0.0: normalizedSegment /= normalizedSegmentLength segmentYMirror = complex(normalizedSegment.real, -normalizedSegment.imag) behindRotated = segmentYMirror * behind behindMidpointRotated = segmentYMirror * behindMidpoint aheadRotated = segmentYMirror * ahead aheadMidpointRotated = segmentYMirror * aheadMidpoint y = behindRotated.imag xIntersection = euclidean.getXIntersectionIfExists( aheadRotated, aheadMidpointRotated, y ) if xIntersection != None: if xIntersection > min( behindMidpointRotated.real, behindRotated.real ) and xIntersection < max( behindMidpointRotated.real, behindRotated.real ): intersectionPoint = normalizedSegment * complex( xIntersection, y ) loop[ ( pointIndex + len( loop ) - 1 ) % len( loop ) ] = intersectionPoint del loop[pointIndex] return
def getDistance(self): "Get distance between point and nearest 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.getPointsRoundZAxis( 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()
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()
def addLineXSegmentIntersection( lineLoopsIntersections, segmentFirstX, segmentSecondX, vector3First, vector3Second, y ): "Add intersections of the line with the x segment." xIntersection = euclidean.getXIntersectionIfExists( vector3First, vector3Second, y ) if xIntersection == None: return if xIntersection < min( segmentFirstX, segmentSecondX ): return if xIntersection <= max( segmentFirstX, segmentSecondX ): lineLoopsIntersections.append( xIntersection )
def addLineXSegmentIntersection( lineLoopsIntersections, segmentFirstX, segmentSecondX, vector3First, vector3Second, y ): 'Add intersections of the line with the x segment.' xIntersection = euclidean.getXIntersectionIfExists( vector3First, vector3Second, y ) if xIntersection == None: return if xIntersection < min( segmentFirstX, segmentSecondX ): return if xIntersection <= max( segmentFirstX, segmentSecondX ): lineLoopsIntersections.append( xIntersection )