def removeIntersection( loop ): "Get loop without the first intersection." withoutIntersection = [] for pointIndex in xrange( len( loop ) ): behind = loop[ ( pointIndex + len( loop ) - 1 ) % len( loop ) ] behindEnd = loop[ ( pointIndex + len( loop ) - 2 ) % len( loop ) ] behindMidpoint = 0.5 * ( behind + behindEnd ) ahead = loop[ pointIndex ] 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 isYAboveFirst = y > aheadRotated.imag isYAboveSecond = y > aheadMidpointRotated.imag if isYAboveFirst != isYAboveSecond: xIntersection = euclidean.getXIntersection( aheadRotated, aheadMidpointRotated, y ) 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 addLineXSegmentIntersection( lineLoopsIntersections, segmentFirstX, segmentSecondX, vector3First, vector3Second, y ): "Add intersections of the line with the x segment." isYAboveFirst = y > vector3First.imag isYAboveSecond = y > vector3Second.imag if isYAboveFirst == isYAboveSecond: return xIntersection = euclidean.getXIntersection( vector3First, vector3Second, y ) if xIntersection <= min( segmentFirstX, segmentSecondX ): return if xIntersection >= max( segmentFirstX, segmentSecondX ): return lineLoopsIntersections.append( xIntersection )
def removeIntersection(loop): "Get loop without the first intersection." withoutIntersection = [] for pointIndex in xrange(len(loop)): behind = loop[(pointIndex + len(loop) - 1) % len(loop)] behindEnd = loop[(pointIndex + len(loop) - 2) % len(loop)] behindMidpoint = 0.5 * (behind + behindEnd) ahead = loop[pointIndex] 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 isYAboveFirst = y > aheadRotated.imag isYAboveSecond = y > aheadMidpointRotated.imag if isYAboveFirst != isYAboveSecond: xIntersection = euclidean.getXIntersection( aheadRotated, aheadMidpointRotated, y) 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