def getClosestDistanceIndexToLine(point, loop):
 smallestDistance = 9.876543219876543e+17
 closestDistanceIndex = None
 for pointIndex in xrange(len(loop)):
  segmentBegin = loop[pointIndex]
  segmentEnd = loop[((pointIndex + 1) % len(loop))]
  distance = getDistanceToPlaneSegment(segmentBegin, segmentEnd, point)
  if (distance < smallestDistance):
   smallestDistance = distance
   closestDistanceIndex = DistanceIndex(distance, pointIndex)
 return closestDistanceIndex

def getClosestDistanceIndexToLine ( point , loop ) : smallestDistance = 9.876543219876543e+17 closestDistanceIndex = None for pointIndex in xrange ( len ( loop ) ) : segmentBegin = loop [ pointIndex ] segmentEnd = loop [ ( ( pointIndex + 1 ) % len ( loop ) ) ] distance = getDistanceToPlaneSegment ( segmentBegin , segmentEnd , point ) if ( distance < smallestDistance ) : smallestDistance = distance closestDistanceIndex = DistanceIndex ( distance , pointIndex ) return closestDistanceIndex
get the distance squared to the closest segment of the loop and index of that segment .