def addLineLoopsIntersections(loopLoopsIntersections, loops, pointBegin, pointEnd):
 normalizedSegment = (pointEnd - pointBegin)
 normalizedSegmentLength = abs(normalizedSegment)
 if (normalizedSegmentLength <= 0.0):
  return
 lineLoopsIntersections = []
 normalizedSegment /= normalizedSegmentLength
 segmentYMirror = complex(normalizedSegment.real, (- normalizedSegment.imag))
 pointBeginRotated = (segmentYMirror * pointBegin)
 pointEndRotated = (segmentYMirror * pointEnd)
 addLoopsXSegmentIntersections(lineLoopsIntersections, loops, pointBeginRotated.real, pointEndRotated.real, segmentYMirror, pointBeginRotated.imag)
 for lineLoopsIntersection in lineLoopsIntersections:
  point = (complex(lineLoopsIntersection, pointBeginRotated.imag) * normalizedSegment)
  loopLoopsIntersections.append(point)

def addLineLoopsIntersections ( loopLoopsIntersections , loops , pointBegin , pointEnd ) : normalizedSegment = ( pointEnd - pointBegin ) normalizedSegmentLength = abs ( normalizedSegment ) if ( normalizedSegmentLength <= 0.0 ) : return lineLoopsIntersections = [ ] normalizedSegment /= normalizedSegmentLength segmentYMirror = complex ( normalizedSegment . real , ( - normalizedSegment . imag ) ) pointBeginRotated = ( segmentYMirror * pointBegin ) pointEndRotated = ( segmentYMirror * pointEnd ) addLoopsXSegmentIntersections ( lineLoopsIntersections , loops , pointBeginRotated . real , pointEndRotated . real , segmentYMirror , pointBeginRotated . imag ) for lineLoopsIntersection in lineLoopsIntersections : point = ( complex ( lineLoopsIntersection , pointBeginRotated . imag ) * normalizedSegment ) loopLoopsIntersections . append ( point )
add intersections of the line with the loops .