Skip to main content

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: types.Point3D, p2: types.Point3D, regions: collections.abc.Sequence[collections.abc.Sequence[types.Point]]) -> list[tuple[types.Point3D, types.Point3D]]

Clip line segments that fall within polygon regions.

Returns: List of clipped segments.

ParameterTypeDescription
p1types.Point3DStart point of the line segment.
p2types.Point3DEnd point of the line segment.
regionscollections.abc.Sequence[collections.abc.Sequence[types.Point]]Polygon regions to clip against.
Returnslist[tuple[types.Point3D, types.Point3D]]

clip_line_segment_with_rect()

clip_line_segment_with_rect(p1: types.Point3D, p2: types.Point3D, rect: types.Rect) -> Optional[tuple[types.Point3D, types.Point3D]]

Clip a line segment with a rectangle.

Returns: Clipped segment or None if fully outside.

ParameterTypeDescription
p1types.Point3DStart point of the line segment.
p2types.Point3DEnd point of the line segment.
recttypes.RectClipping rectangle (x_min, y_min, x_max, y_max).
ReturnsOptional[tuple[types.Point3D, types.Point3D]]

from_clipper()

from_clipper(polygon: types.IntPolygon, scale: int = 10000000) -> types.Polygon

Convert a polygon from Clipper coordinates.

Returns: Polygon with float coordinates.

ParameterTypeDescription
polygontypes.IntPolygonInteger polygon from Clipper.
scaleint = 10000000Scale factor used during conversion.
Returnstypes.Polygon

subtract_polygons_from_line_segment()

subtract_polygons_from_line_segment(p1: types.Point3D, p2: types.Point3D, regions: collections.abc.Sequence[collections.abc.Sequence[types.Point]]) -> list[tuple[types.Point3D, types.Point3D]]

Subtract polygon regions from a line segment.

Returns: List of remaining segments after subtraction.

ParameterTypeDescription
p1types.Point3DStart point of the line segment.
p2types.Point3DEnd point of the line segment.
regionscollections.abc.Sequence[collections.abc.Sequence[types.Point]]List of polygon regions to subtract.
Returnslist[tuple[types.Point3D, types.Point3D]]

to_clipper()

to_clipper(polygon: types.Polygon, scale: int = 10000000) -> list[tuple[int, int]]

Convert a polygon to Clipper coordinates.

Returns: Polygon with integer coordinates for Clipper.

ParameterTypeDescription
polygontypes.PolygonInput polygon as a list of (x, y) points.
scaleint = 10000000Scale factor for integer conversion.
Returnslist[tuple[int, int]]