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 |
get_angle_at_vertex()
get_angle_at_vertex(p0: types.Point, p1: types.Point, p2: types.Point) -> float
Compute the angle at vertex p1.
| Parameter | Type | Description |
|---|---|---|
p0 | types.Point | Previous point. |
p1 | types.Point | Vertex point. |
p2 | types.Point | Next point. |
| Returns | float | Angle in radians. |
| Complexity | O(1) time, O(1) space |
get_interior_angle()
get_interior_angle(p0: types.Point, p1: types.Point, p2: types.Point) -> float
Interior angle at vertex p1 formed by edges p0→p1 and p1→p2.
Returns 0.0 when any two adjacent points coincide (degenerate input).
| Parameter | Type | Description |
|---|---|---|
p0 | types.Point | Previous point. |
p1 | types.Point | Vertex point. |
p2 | types.Point | Next point. |
| Returns | float | Angle in radians in [0, π]. |
| Complexity | O(1) time, O(1) space |
get_line_closest_point()
get_line_closest_point(
line_p1: types.Point,
line_p2: types.Point,
x: float,
y: float,
) -> types.Point
Get the closest point on an infinite line to a given point. The result may lie beyond the segment endpoints (unclamped projection).
| Parameter | Type | Description |
|---|---|---|
line_p1 | types.Point | First point on the line. |
line_p2 | types.Point | Second point on the line. |
x | float | X coordinate of target point. |
y | float | Y coordinate of target point. |
| Returns | types.Point | Closest point (x, y) on the infinite line. |
| Complexity | O(1) time, O(1) space |
get_line_line_intersection()
get_line_line_intersection(
p1: types.Point,
p2: types.Point,
p3: types.Point,
p4: types.Point,
) -> Optional[types.Point]
Get the intersection of two infinite lines.
| Parameter | Type | Description |
|---|---|---|
p1 | types.Point | First point on line 1. |
p2 | types.Point | Second point on line 1. |
p3 | types.Point | First point on line 2. |
p4 | types.Point | Second point on line 2. |
| Returns | Optional[types.Point] | Intersection point (x, y) or None. |
| Complexity | O(1) time, O(1) space |

Line-line and segment intersection
get_line_segment_closest_point()
get_line_segment_closest_point(
seg_p1: types.Point,
seg_p2: types.Point,
x: float,
y: float,
) -> tuple[float, types.Point, float]
Get closest point on a line segment to a point.
| Parameter | Type | Description |
|---|---|---|
seg_p1 | types.Point | Start of the line segment. |
seg_p2 | types.Point | End of the line segment. |
x | float | X coordinate of target point. |
y | float | Y coordinate of target point. |
| Returns | tuple[float, types.Point, float] | Tuple of (parameter, closest_point, distance). |
| Complexity | O(1) time, O(1) space |
get_line_segment_intersection()
get_line_segment_intersection(
p1: types.Point,
p2: types.Point,
p3: types.Point,
p4: types.Point,
) -> Optional[types.Point]
Get the intersection of two line segments.
| Parameter | Type | Description |
|---|---|---|
p1 | types.Point | Start of segment 1. |
p2 | types.Point | End of segment 1. |
p3 | types.Point | Start of segment 2. |
p4 | types.Point | End of segment 2. |
| Returns | Optional[types.Point] | Intersection point (x, y) or None. |
| Complexity | O(1) time, O(1) space |
get_line_segment_length()
get_line_segment_length(p1: types.Point, p2: types.Point) -> float
Compute the length of a line segment.
| Parameter | Type | Description |
|---|---|---|
p1 | types.Point | Start point (x, y). |
p2 | types.Point | End point (x, y). |
| Returns | float | Distance between the two points. |
| Complexity | O(1) time, O(1) space |