def getLoopStartingClosest(extrusionHalfWidth, location, loop):
 closestIndex = getClosestDistanceIndexToLine(location, loop).index
 loop = getAroundLoop(closestIndex, closestIndex, loop)
 closestPoint = getClosestPointOnSegment(loop[0], loop[1], location)
 if ((abs((closestPoint - loop[0])) > extrusionHalfWidth) and (abs((closestPoint - loop[1])) > extrusionHalfWidth)):
  loop = (([closestPoint] + loop[1:]) + [loop[0]])
 elif (abs((closestPoint - loop[0])) > abs((closestPoint - loop[1]))):
  loop = (loop[1:] + [loop[0]])
 return loop

def getLoopStartingClosest ( extrusionHalfWidth , location , loop ) : closestIndex = getClosestDistanceIndexToLine ( location , loop ) . index loop = getAroundLoop ( closestIndex , closestIndex , loop ) closestPoint = getClosestPointOnSegment ( loop [ 0 ] , loop [ 1 ] , location ) if ( ( abs ( ( closestPoint - loop [ 0 ] ) ) > extrusionHalfWidth ) and ( abs ( ( closestPoint - loop [ 1 ] ) ) > extrusionHalfWidth ) ) : loop = ( ( [ closestPoint ] + loop [ 1 : ] ) + [ loop [ 0 ] ] ) elif ( abs ( ( closestPoint - loop [ 0 ] ) ) > abs ( ( closestPoint - loop [ 1 ] ) ) ) : loop = ( loop [ 1 : ] + [ loop [ 0 ] ] ) return loop
add to threads from the last location from loop .