code: def _find_closest_point_on_path(xys, p):
      """
      Parameters
      ----------
      xys : (N, 2) array-like
          Coordinates of vertices.
      p : (float, float)
          Coordinates of point.
  
      Returns
      -------
      d2min : float
          Minimum square distance of *p* to *xys*.
      proj : (float, float)
          Projection of *p* onto *xys*.
      imin : (int, int)
          Consecutive indices of vertices of segment in *xys* where *proj* is.
          Segments are considered as including their end-points; i.e. if the
          closest point on the path is a node in *xys* with index *i*, this
          returns ``(i-1, i)``.  For the special case where *xys* is a single
          point, this returns ``(0, 0)``.
      """
      if len(xys) == 1:
          return (((p - xys[0]) ** 2).sum(), xys[0], (0, 0))
      dxys = xys[1:] - xys[:-1]  # Individual segment vectors.
      norms = (dxys**2).sum(axis=1)
      norms[
          norms == 0
      ] = 1  # For zero-length segment, replace 0/0 by 0/1.
      rel_projs = (
          np.clip(  # Project onto each segment in relative 0-1 coords.
              ((p - xys[:-1]) * dxys).sum(axis=1) / norms, 0, 1
          )[:, None]
      )
      projs = (
          xys[:-1] + rel_projs * dxys
      )  # Projs. onto each segment, in (x, y).
      d2s = ((projs - p) ** 2).sum(axis=1)  # Squared distances.
      imin = np.argmin(d2s)
      return (d2s[imin], projs[imin], (imin, imin + 1))
  
imports: from contextlib import ExitStack
  import functools
  import math
  from numbers import Integral
  import numpy
  from numpy import ma
  import matplotlib
  from matplotlib import _api, _docstring
  from matplotlib.backend_bases import MouseButton
  from matplotlib.lines import Line2D
  from matplotlib.path import Path
  from matplotlib.text import Text
  import matplotlib.ticker
  import matplotlib.cm
  import matplotlib.colors
  import matplotlib.collections
  import matplotlib.font_manager
  import matplotlib.cbook
  import matplotlib.patches
  import matplotlib.transforms
label_desc: Use image node_id 3 for calling a global function with example usage: _find_closest_point_on_path(xys, p) and returns: d2s,  projs,  imin,  unknown, unknown,  xys,  int,  int