def getTransferClosestSurroundingLoop(oldOrderedLocation, remainingSurroundingLoops, skein):
 if (len(remainingSurroundingLoops) > 0):
  oldOrderedLocation.z = remainingSurroundingLoops[0].z
 closestDistance = 1e+18
 closestSurroundingLoop = None
 for remainingSurroundingLoop in remainingSurroundingLoops:
  distance = getNearestDistanceIndex(oldOrderedLocation.dropAxis(2), remainingSurroundingLoop.boundary).distance
  if (distance < closestDistance):
   closestDistance = distance
   closestSurroundingLoop = remainingSurroundingLoop
 remainingSurroundingLoops.remove(closestSurroundingLoop)
 closestSurroundingLoop.addToThreads(oldOrderedLocation, skein)
 return closestSurroundingLoop

def getTransferClosestSurroundingLoop ( oldOrderedLocation , remainingSurroundingLoops , skein ) : if ( len ( remainingSurroundingLoops ) > 0 ) : oldOrderedLocation . z = remainingSurroundingLoops [ 0 ] . z closestDistance = 1e+18 closestSurroundingLoop = None for remainingSurroundingLoop in remainingSurroundingLoops : distance = getNearestDistanceIndex ( oldOrderedLocation . dropAxis ( 2 ) , remainingSurroundingLoop . boundary ) . distance if ( distance < closestDistance ) : closestDistance = distance closestSurroundingLoop = remainingSurroundingLoop remainingSurroundingLoops . remove ( closestSurroundingLoop ) closestSurroundingLoop . addToThreads ( oldOrderedLocation , skein ) return closestSurroundingLoop
get and transfer the closest remaining surrounding loop .