Pular para o conteúdo principal

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.

ParameterTypeDescription
p1Point3DStart point of the line segment.
p2Point3DEnd point of the line segment.
regionsSequence[Sequence[Point]]Polygon regions to clip against.
Returnslist[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.

ParameterTypeDescription
p1Point3DStart point of the line segment.
p2Point3DEnd point of the line segment.
rectRectClipping rectangle (x_min, y_min, x_max, y_max).
ReturnsOptional[tuple[Point3D, Point3D]]

from_clipper()

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

Convert a polygon from Clipper coordinates.

Returns: Polygon with float coordinates.

ParameterTypeDescription
polygonIntPolygonInteger polygon from Clipper.
scaleint = 10000000Scale factor used during conversion.
ReturnsPolygon

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.

ParameterTypeDescription
p1Point3DStart point of the line segment.
p2Point3DEnd point of the line segment.
regionsSequence[Sequence[Point]]List of polygon regions to subtract.
Returnslist[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.

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