code: def substring(geom, start_dist, end_dist, normalized=False):
      """Return a line segment between specified distances along a LineString
  
      Negative distance values are taken as measured in the reverse
      direction from the end of the geometry. Out-of-range index
      values are handled by clamping them to the valid range of values.
  
      If the start distance equals the end distance, a Point is returned.
  
      If the start distance is actually beyond the end distance, then the
      reversed substring is returned such that the start distance is
      at the first coordinate.
  
      Parameters
      ----------
      geom : LineString
          The geometry to get a substring of.
      start_dist : float
          The distance along `geom` of the start of the substring.
      end_dist : float
          The distance along `geom` of the end of the substring.
      normalized : bool, False
          Whether the distance parameters are interpreted as a
          fraction of the geometry's length.
  
      Returns
      -------
      Union[Point, LineString]
          The substring between `start_dist` and `end_dist` or a Point
          if they are at the same location.
  
      Raises
      ------
      TypeError
          If `geom` is not a LineString.
  
      Examples
      --------
      >>> from shapely.geometry import LineString
      >>> from shapely.ops import substring
      >>> ls = LineString((i, 0) for i in range(6))
      >>> ls.wkt
      'LINESTRING (0 0, 1 0, 2 0, 3 0, 4 0, 5 0)'
      >>> substring(ls, start_dist=1, end_dist=3).wkt
      'LINESTRING (1 0, 2 0, 3 0)'
      >>> substring(ls, start_dist=3, end_dist=1).wkt
      'LINESTRING (3 0, 2 0, 1 0)'
      >>> substring(ls, start_dist=1, end_dist=-3).wkt
      'LINESTRING (1 0, 2 0)'
      >>> substring(ls, start_dist=0.2, end_dist=-0.6, normalized=True).wkt
      'LINESTRING (1 0, 2 0)'
  
      Returning a `Point` when `start_dist` and `end_dist` are at the
      same location.
  
      >>> substring(ls, 2.5, -2.5).wkt
      'POINT (2.5 0)'
      """
  
      if not isinstance(geom, LineString):
          raise GeometryTypeError(
              "Can only calculate a substring of LineString geometries. "
              f"A {geom.geom_type} was provided."
          )
  
      # Filter out cases in which to return a point
      if start_dist == end_dist:
          return geom.interpolate(start_dist, normalized)
      elif (
          not normalized
          and start_dist >= geom.length
          and end_dist >= geom.length
      ):
          return geom.interpolate(geom.length, normalized)
      elif (
          not normalized
          and -start_dist >= geom.length
          and -end_dist >= geom.length
      ):
          return geom.interpolate(0, normalized)
      elif normalized and start_dist >= 1 and end_dist >= 1:
          return geom.interpolate(1, normalized)
      elif normalized and -start_dist >= 1 and -end_dist >= 1:
          return geom.interpolate(0, normalized)
  
      if normalized:
          start_dist *= geom.length
          end_dist *= geom.length
  
      # Filter out cases where distances meet at a middle point from opposite ends.
      if (
          start_dist < 0 < end_dist
          and abs(start_dist) + end_dist == geom.length
      ):
          return geom.interpolate(end_dist)
      elif (
          end_dist < 0 < start_dist
          and abs(end_dist) + start_dist == geom.length
      ):
          return geom.interpolate(start_dist)
  
      start_point = geom.interpolate(start_dist)
      end_point = geom.interpolate(end_dist)
  
      if start_dist < 0:
          start_dist = (
              geom.length + start_dist
          )  # Values may still be negative,
      if end_dist < 0:  # but only in the out-of-range
          end_dist = (
              geom.length + end_dist
          )  # sense, not the wrap-around sense.
  
      reverse = start_dist > end_dist
      if reverse:
          start_dist, end_dist = end_dist, start_dist
  
      if start_dist < 0:
          start_dist = 0  # to avoid duplicating the first vertex
  
      if reverse:
          vertex_list = [tuple(*end_point.coords)]
      else:
          vertex_list = [tuple(*start_point.coords)]
  
      coords = list(geom.coords)
      current_distance = 0
      for p1, p2 in zip(coords, coords[1:]):
          if start_dist < current_distance < end_dist:
              vertex_list.append(p1)
          elif current_distance >= end_dist:
              break
  
          current_distance += (
              (p2[0] - p1[0]) ** 2 + (p2[1] - p1[1]) ** 2
          ) ** 0.5
  
      if reverse:
          vertex_list.append(tuple(*start_point.coords))
          # reverse direction result
          vertex_list = reversed(vertex_list)
      else:
          vertex_list.append(tuple(*end_point.coords))
  
      return LineString(vertex_list)
  
imports: from warnings import warn
  import shapely
  from shapely.algorithms.polylabel import polylabel
  from shapely.errors import GeometryTypeError, ShapelyDeprecationWarning
  from shapely.geometry import GeometryCollection, LineString, MultiLineString, MultiPoint, Point, Polygon, shape
  from shapely.geometry.base import BaseGeometry, BaseMultipartGeometry
  from shapely.geometry.polygon import orient
  from shapely.prepared import prep
label_desc: Use image node_id 8 for calling a global function with example usage: substring(geom, start_dist, end_dist, normalized) and returns: LineString, geom, geom, geom, geom, geom, geom, geom