raygeo.geo.shape.line
Line segment geometry queries.
Provides line-line intersection (infinite lines), line-segment intersection, closest point on a line or segment to a given point, line-segment-vs-polygon intersections, point-on-segment tests, point-in-rectangle tests, rectangle containment checks, and angle-at-vertex computation.
Functions
does_line_cross_polygon()
does_line_cross_polygon(
a: types.Point,
b: types.Point,
polygon: list[types.Point],
) -> bool
Check if a line segment crosses the interior of a polygon.
Returns True when the segment strictly crosses the polygon boundary — touching a vertex or
grazing an edge at an endpoint is not considered a crossing.
| Parameter | Type | Description |
|---|---|---|
a | types.Point | Segment start point (x, y). |
b | types.Point | Segment end point (x, y). |
polygon | list[types.Point] | Polygon vertices [(x1, y1), (x2, y2), ...]. |
| Returns | bool | True if the segment crosses the polygon interior. |
| Complexity | O(n) time, O(1) space |

Check if line segment crosses polygon interior. Left: crosses (red). Right: touches boundary (gray).
does_line_segment_intersect_circle()
does_line_segment_intersect_circle(
p1: types.Point,
p2: types.Point,
circle_center: types.Point,
circle_radius: float,
) -> bool
Check if a line segment intersects a circle.
| Parameter | Type | Description |
|---|---|---|
p1 | types.Point | Start of the line segment. |
p2 | types.Point | End of the line segment. |
circle_center | types.Point | Circle center (x, y). |
circle_radius | float | Circle radius. |
| Returns | bool | True if the segment intersects the circle. |
| Complexity | O(1) time, O(1) space |
does_line_segment_intersect_rect()
does_line_segment_intersect_rect(
p1: types.Point,
p2: types.Point,
rect: types.Rect,
) -> bool
Check if a line segment intersects a rectangle.
| Parameter | Type | Description |
|---|---|---|
p1 | types.Point | Start of the line segment. |
p2 | types.Point | End of the line segment. |
rect | types.Rect | Rectangle (x_min, y_min, x_max, y_max). |
| Returns | bool | True if the segment intersects the rectangle. |
| Complexity | O(1) time, O(1) space |