def _find_closest_point_on_path(lc, point):
 ds = np.sum(((lc - point[None, :]) ** 2), 1)
 imin = np.argmin(ds)
 dmin = np.inf
 xcmin = None
 legmin = (None, None)
 closed = mlab.is_closed_polygon(lc)
 legs = []
 if ((imin > 0) or closed):
  legs.append((((imin - 1) % len(lc)), imin))
 if ((imin < (len(lc) - 1)) or closed):
  legs.append((imin, ((imin + 1) % len(lc))))
 for leg in legs:
  (d, xc) = _find_closest_point_on_leg(lc[leg[0]], lc[leg[1]], point)
  if (d < dmin):
   dmin = d
   xcmin = xc
   legmin = leg
 return (dmin, xcmin, legmin)

def _find_closest_point_on_path ( lc , point ) : ds = np . sum ( ( ( lc - point [ None , : ] ) ** 2 ) , 1 ) imin = np . argmin ( ds ) dmin = np . inf xcmin = None legmin = ( None , None ) closed = mlab . is_closed_polygon ( lc ) legs = [ ] if ( ( imin > 0 ) or closed ) : legs . append ( ( ( ( imin - 1 ) % len ( lc ) ) , imin ) ) if ( ( imin < ( len ( lc ) - 1 ) ) or closed ) : legs . append ( ( imin , ( ( imin + 1 ) % len ( lc ) ) ) ) for leg in legs : ( d , xc ) = _find_closest_point_on_leg ( lc [ leg [ 0 ] ] , lc [ leg [ 1 ] ] , point ) if ( d < dmin ) : dmin = d xcmin = xc legmin = leg return ( dmin , xcmin , legmin )
lc: coordinates of vertices point: coordinates of test point .