def getLoopStartingNearest(extrusionHalfWidth, location, loop):
 nearestIndex = getNearestDistanceIndex(location, loop).index
 loop = getAroundLoop(nearestIndex, nearestIndex, loop)
 nearestPoint = getNearestPointOnSegment(loop[0], loop[1], location)
 if ((abs((nearestPoint - loop[0])) > extrusionHalfWidth) and (abs((nearestPoint - loop[1])) > extrusionHalfWidth)):
  loop = (([nearestPoint] + loop[1:]) + [loop[0]])
 elif (abs((nearestPoint - loop[0])) > abs((nearestPoint - loop[1]))):
  loop = (loop[1:] + [loop[0]])
 return loop

def getLoopStartingNearest ( extrusionHalfWidth , location , loop ) : nearestIndex = getNearestDistanceIndex ( location , loop ) . index loop = getAroundLoop ( nearestIndex , nearestIndex , loop ) nearestPoint = getNearestPointOnSegment ( loop [ 0 ] , loop [ 1 ] , location ) if ( ( abs ( ( nearestPoint - loop [ 0 ] ) ) > extrusionHalfWidth ) and ( abs ( ( nearestPoint - loop [ 1 ] ) ) > extrusionHalfWidth ) ) : loop = ( ( [ nearestPoint ] + loop [ 1 : ] ) + [ loop [ 0 ] ] ) elif ( abs ( ( nearestPoint - loop [ 0 ] ) ) > abs ( ( nearestPoint - loop [ 1 ] ) ) ) : loop = ( loop [ 1 : ] + [ loop [ 0 ] ] ) return loop
add to threads from the last location from loop .