code: def extrapolate_ahead(dj, xj, vj, contourpath=None):
      """Make `di` steps of size `vj` from `xj`.
  
      Reflect off unit cube if necessary.
      """
      assert dj == int(dj)
  
      # optimistically try to go there directly
  
      xk, vk = linear_steps_with_reflection(xj, vj, dj)
  
      return xk, vk  # deactivate feature below
  
      if contourpath is None:
          return xk, vk
  
      # check if we can already tell that the point will be outside
      region = contourpath.region
      if contourpath.region.inside(xk.reshape((1, -1))):
          return xk, vk
  
      # find first point outside region
      sign = 1 if dj > 0 else -1
      d = np.arange(0, dj, sign)
      first_point_outside = dj, xk, vk
      for di in d:
          xi, vi = linear_steps_with_reflection(xj, vj, di)
          if not region.inside(xk.reshape((1, -1))):
              first_point_outside = di, xi, vi
              break
  
      # reflect at this point (first outside)
      dout, reflpoint, v = first_point_outside
  
      if dout == 0:
          # already the starting point is outside.
          # return extrapolation and hope caller handles it
          return xk, vk
  
      # reversing:
      normal = contourpath.gradient(reflpoint)  # , v * sign)
      if normal is None:
          vnew = -v
      else:
          vnew = (v - 2 * angle(normal, v) * normal) * sign
      assert vnew.shape == v.shape, (vnew.shape, v.shape)
      assert np.isclose(norm(vnew), norm(v)), (
          vnew,
          v,
          norm(vnew),
          norm(v),
      )
  
      # make one step (xl replaces first_point_outside/reflpoint)
      xl, vl = linear_steps_with_reflection(reflpoint, vnew, sign)
      # how many steps are still to do?
      dleft = dj - dout
  
      # make that many step in that direction, by recursing.
  
      # it is possible that this point is also outside. The next iteration
      # will catch that case.
  
      return extrapolate_ahead(dleft, xl, vl, contourpath=contourpath)
  
imports: import numpy
  from numpy.linalg import norm
  import matplotlib.pyplot
label_desc: Use image node_id 10 for calling a global function with example usage: extrapolate_ahead(dj, xj, vj, contourpath) and returns: xk,  vk, extrapolate_ahead, xk,  vk, xk,  vk, xk,  vk