(xorig, yorig, xclick, yclick)
return x, y
Find the nearest point on a polyline segment to the point *xclick*
    *yclick*.
Find the nearest point on a polyline segment to the point *xclick*
    *yclick*.
Find the nearest point on a polyline segment to the point * xclick * * yclick * .
def _interpolate_line(xorig, yorig, xclick, yclick):
    """Find the nearest point on a polyline segment to the point *xclick*
    *yclick*."""
    candidates = []
    # The closest point may be a vertex.
    for x, y in zip(xorig, yorig):
        candidates.append((np.hypot(xclick - x, yclick - y), (x, y)))
    # Or it may be a projection on a segment.
    for (x0, x1), (y0, y1) in zip(zip(xorig, xorig[1:]), zip(yorig, yorig[1:])):
        vec1 = np.array([x1 - x0, y1 - y0])
        vec1 /= np.linalg.norm(vec1)
        vec2 = np.array([xclick - x0, yclick - y0])
        dist_along = vec1.dot(vec2)
        x, y = np.array([x0, y0]) + dist_along * vec1
        # Drop if out of the segment.
        if (x - x0) * (x - x1) > 0 or (y - y0) * (y - y1) > 0:
            continue
        candidates.append((np.hypot(xclick - x, yclick - y), (x, y)))
    _, (x, y) = min(candidates)
    return x, y
def _interpolate_line ( xorig , yorig , xclick , yclick ) : candidates = [ ] # The closest point may be a vertex. for x , y in zip ( xorig , yorig ) : candidates . append ( ( np . hypot ( xclick - x , yclick - y ) , ( x , y ) ) ) # Or it may be a projection on a segment. for ( x0 , x1 ) , ( y0 , y1 ) in zip ( zip ( xorig , xorig [ 1 : ] ) , zip ( yorig , yorig [ 1 : ] ) ) : vec1 = np . array ( [ x1 - x0 , y1 - y0 ] ) vec1 /= np . linalg . norm ( vec1 ) vec2 = np . array ( [ xclick - x0 , yclick - y0 ] ) dist_along = vec1 . dot ( vec2 ) x , y = np . array ( [ x0 , y0 ] ) + dist_along * vec1 # Drop if out of the segment. if ( x - x0 ) * ( x - x1 ) > 0 or ( y - y0 ) * ( y - y1 ) > 0 : continue candidates . append ( ( np . hypot ( xclick - x , yclick - y ) , ( x , y ) ) ) _ , ( x , y ) = min ( candidates ) return x , y