code: def dist_point_to_segment(p, s0, s1):
      """
      Get the distance from the point *p* to the segment (*s0*, *s1*), where
      *p*, *s0*, *s1* are ``[x, y]`` arrays.
      """
      s01 = s1 - s0
      s0p = p - s0
      if (s01 == 0).all():
          return np.hypot(*s0p)
      # Project onto segment, without going past segment ends.
      p1 = s0 + np.clip((s0p @ s01) / (s01 @ s01), 0, 1) * s01
      return np.hypot(*(p - p1))
  
file_path: matplotlib/galleries/examples/event_handling/poly_editor.py
imports: import numpy
  from matplotlib.artist import Artist
  from matplotlib.lines import Line2D
label_desc: Use image node_id 1 for calling a global function with example usage: dist_point_to_segment(p, s0, s1) and returns: np, np