raygeo.geo.algo.clipping
Line and polygon clipping operations.
Provides functions for clipping line segments against rectangles and polygon regions, as well as converting between float and Clipper integer coordinate systems.
Functions
clip_line_segment_with_polygons()
clip_line_segment_with_polygons(p1: Point3D, p2: Point3D, regions: Sequence[Sequence[Point]]) -> list[tuple[Point3D, Point3D]]
Clip line segments that fall within polygon regions.
Returns: List of clipped segments.
| Parameter | Type | Description |
|---|---|---|
p1 | Point3D | Start point of the line segment. |
p2 | Point3D | End point of the line segment. |
regions | Sequence[Sequence[Point]] | Polygon regions to clip against. |
| Returns | list[tuple[Point3D, Point3D]] |
clip_line_segment_with_rect()
clip_line_segment_with_rect(p1: Point3D, p2: Point3D, rect: Rect) -> Optional[tuple[Point3D, Point3D]]
Clip a line segment with a rectangle.
Returns: Clipped segment or None if fully outside.
| Parameter | Type | Description |
|---|---|---|
p1 | Point3D | Start point of the line segment. |
p2 | Point3D | End point of the line segment. |
rect | Rect | Clipping rectangle (x_min, y_min, x_max, y_max). |
| Returns | Optional[tuple[Point3D, Point3D]] |
from_clipper()
from_clipper(polygon: IntPolygon, scale: int = 10000000) -> Polygon
Convert a polygon from Clipper coordinates.
Returns: Polygon with float coordinates.
| Parameter | Type | Description |
|---|---|---|
polygon | IntPolygon | Integer polygon from Clipper. |
scale | int = 10000000 | Scale factor used during conversion. |
| Returns | Polygon |
subtract_polygons_from_line_segment()
subtract_polygons_from_line_segment(p1: Point3D, p2: Point3D, regions: Sequence[Sequence[Point]]) -> list[tuple[Point3D, Point3D]]
Subtract polygon regions from a line segment.
Returns: List of remaining segments after subtraction.
| Parameter | Type | Description |
|---|---|---|
p1 | Point3D | Start point of the line segment. |
p2 | Point3D | End point of the line segment. |
regions | Sequence[Sequence[Point]] | List of polygon regions to subtract. |
| Returns | list[tuple[Point3D, Point3D]] |
to_clipper()
to_clipper(polygon: Polygon, scale: int = 10000000) -> list[tuple[int, int]]
Convert a polygon to Clipper coordinates.
Returns: Polygon with integer coordinates for Clipper.
| Parameter | Type | Description |
|---|---|---|
polygon | Polygon | Input polygon as a list of (x, y) points. |
scale | int = 10000000 | Scale factor for integer conversion. |
| Returns | list[tuple[int, int]] |