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

Clip line segments that fall within polygon regions.

ParameterTypeDescription
p1types.Point3DStart point of the line segment.
p2types.Point3DEnd point of the line segment.
regionsSequence[Sequence[types.Point]]Polygon regions to clip against.
Returnslist[tuple[types.Point3D, types.Point3D]]List of clipped segments.
ComplexityO(n * m) time, O(n) space where n is the number of regions and m their average vertex count

Line clipped to polygon

Line clipped to polygon

clip_line_segment_with_polygons_2d()

clip_line_segment_with_polygons_2d(
p1: types.Point,
p2: types.Point,
regions: Sequence[Sequence[types.Point]],
) -> list[tuple[types.Point, types.Point]]

Clip 2D line segments that fall within polygon regions (XY-plane only).

ParameterTypeDescription
p1types.PointStart point (x, y).
p2types.PointEnd point (x, y).
regionsSequence[Sequence[types.Point]]Polygon regions to clip against.
Returnslist[tuple[types.Point, types.Point]]List of clipped segments.
ComplexityO(n * m) time, O(n) space where n is the number of regions and m their average vertex count

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.

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]]Clipped segment or None if fully outside.
ComplexityO(1) time, O(1) space

Line clipped to rectangle

Line clipped to rectangle

clip_line_segment_with_rect_2d()

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

Clip a 2D line segment with a rectangle (XY-plane only).

ParameterTypeDescription
p1types.PointStart point (x, y).
p2types.PointEnd point (x, y).
recttypes.RectClipping rectangle (x_min, y_min, x_max, y_max).
ReturnsOptional[tuple[types.Point, types.Point]]Clipped segment or None if fully outside.
ComplexityO(1) time, O(1) space

from_clipper()

from_clipper(polygon: list[tuple[int, int]]) -> list[tuple[float, float]]

Convert a polygon from Clipper coordinates.

ParameterTypeDescription
polygonlist[tuple[int, int]]Integer polygon from Clipper.
Returnslist[tuple[float, float]]Polygon with float coordinates.
ComplexityO(n) time, O(n) space

subtract_polygons_from_line_segment()

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

Subtract polygon regions from a line segment.

ParameterTypeDescription
p1types.Point3DStart point of the line segment.
p2types.Point3DEnd point of the line segment.
regionsSequence[Sequence[types.Point]]List of polygon regions to subtract.
Returnslist[tuple[types.Point3D, types.Point3D]]List of remaining segments after subtraction.
ComplexityO(n * m) time, O(n) space where n is the number of regions and m their average vertex count

Subtract polygon from line

Subtract polygon from line

subtract_polygons_from_line_segment_2d()

subtract_polygons_from_line_segment_2d(
p1: types.Point,
p2: types.Point,
regions: Sequence[Sequence[types.Point]],
) -> list[tuple[types.Point, types.Point]]

Subtract polygon regions from a 2D line segment (XY-plane only).

ParameterTypeDescription
p1types.PointStart point (x, y).
p2types.PointEnd point (x, y).
regionsSequence[Sequence[types.Point]]List of polygon regions to subtract.
Returnslist[tuple[types.Point, types.Point]]List of remaining segments after subtraction.
ComplexityO(n * m) time, O(n) space where n is the number of regions and m their average vertex count

to_clipper()

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

Convert a polygon to Clipper coordinates.

ParameterTypeDescription
polygontypes.PolygonInput polygon as a list of (x, y) points.
Returnslist[tuple[int, int]]Polygon with integer coordinates for Clipper.
ComplexityO(n) time, O(n) space