code: def intersect_line_segments(
      lines1: jnp.ndarray, lines2: jnp.ndarray, eps: float = 1e-8
  ) -> jnp.ndarray:
      """Intersect two line segments.
  
      Given two 2D line segments, where a line segment is defined as two 2D points.
      Finds the point of intersection or returns [nan, nan] if no point exists.
  
      See https://en.wikipedia.org/wiki/Line%E2%80%93line_intersection (Given two
      points on each line segment).
  
      Performance Note: At the calling point, we expect user to appropriately vmap
      function to work on batches of lines.
      Args:
        lines1: [..., 2, 2]-ndarray, [[x1, y1], [x2, y2]] for lines.
        lines2: [..., 2, 2]-ndarray, [[x3, y3], [x4, y4]] for other lines.
        eps: Epsilon for numerical stability.
  
      Returns:
        Intersection points [..., 2]-ndarray or [..., [nan, nan]] if no point
        exists. Since we are intersecting line segments in 2D, this happens if
        lines are parallel or the intersection of the infinite line would occur
        outside of both segments.
      """
      assert lines1.shape[-2:] == (2, 2) and lines2.shape[-2:] == (2, 2)
      x1, y1 = jnp.split(lines1[..., 0, :], 2, -1)
      x2, y2 = jnp.split(lines1[..., 1, :], 2, -1)
      x3, y3 = jnp.split(lines2[..., 0, :], 2, -1)
      x4, y4 = jnp.split(lines2[..., 1, :], 2, -1)
      den = (x1 - x2) * (y3 - y4) - (y1 - y2) * (x3 - x4)
      num_t = (x1 - x3) * (y3 - y4) - (y1 - y3) * (x3 - x4)
      num_u = (x1 - x2) * (y1 - y3) - (y1 - y2) * (x1 - x3)
      # t and u are parameterizations of line1 and line2 respectively and are left
      # as variable names from the original algorithm documentation.
      t = num_t / (den + eps)
      u = -num_u / (den + eps)
  
      intersection_pt = jnp.concatenate(
          [x1 + t * (x2 - x1), y1 + t * (y2 - y1)], -1
      )
      are_parallel = jnp.abs(den) < eps
      not_on_line1 = jnp.logical_or(u < 0, u > 1)
      not_on_line2 = jnp.logical_or(t < 0, t > 1)
  
      not_possible = jnp.any(
          jnp.concatenate(
              [are_parallel, not_on_line1, not_on_line2], -1
          ),
          -1,
      )
      nan_pt = jnp.ones_like(intersection_pt) * jnp.nan
      return jnp.where(not_possible[..., None], nan_pt, intersection_pt)
  
file_path: scenic/scenic/model_lib/base_models/box_utils.py
imports: from typing import Any, Union
  import jax.numpy
  import numpy
label_desc: Use image node_id 9 for calling a global function with example usage: intersect_line_segments(lines1, lines2, eps) and returns: jnp