code: def rectangle_point_intersection(rec, p):
      """
      Returns the intersection point between the Rectangle
      (w,h) that characterize the rec object and the line that goes
      from the recs' object center to the 'p' point.
  
      """
      x2, y2 = p[0] - rec.xy[0], p[1] - rec.xy[1]
      x1, y1 = 0, 0
      # bounding box:
      bbx2 = rec.w // 2
      bbx1 = -bbx2
      bby2 = rec.h // 2
      bby1 = -bby2
  
      segments = [
          ((x1, y1), (x2, y2), (bbx1, bby1), (bbx2, bby1)),
          ((x1, y1), (x2, y2), (bbx2, bby1), (bbx2, bby2)),
          ((x1, y1), (x2, y2), (bbx1, bby2), (bbx2, bby2)),
          ((x1, y1), (x2, y2), (bbx1, bby2), (bbx1, bby1)),
      ]
      for segs in segments:
          xy = lines_intersection(*segs)
          if xy is not None:
              x, y = xy
              x += rec.xy[0]
              y += rec.xy[1]
              return x, y
      # can't be an intersection unless the endpoint was inside the bb
      raise ValueError(
          "no intersection found (point inside ?!). rec: %s p: %s"
          % (rec, p)
      )
  
file_path: pygraphistry/graphistry/layout/utils/geometry.py
imports: from numpy import array, cos, sin
  from math import atan2, sqrt
label_desc: Use image node_id 2 for calling a global function with example usage: rectangle_point_intersection(rec, p) and returns: x,  y