Skip to main content

raygeo.geo.algo.offset

Polygon offsetting operations for geometry data.

Provides concentric inward offset generation for adaptive clearing and pocketing toolpath generation.

Functions

compute_inset_region()

compute_inset_region(
boundary: Sequence[tuple[float, float]],
radius: float,
obstacles: Sequence[Sequence[tuple[float, float]]] = [],
) -> tuple[list[list[tuple[float, float]]], float]

Compute the inset region: boundary shrunk by radius, minus obstacle buffers (each obstacle expanded by radius).

ParameterTypeDescription
boundarySequence[tuple[float, float]]Outer boundary polygon as a list of (x, y) points.
radiusfloatInset / expansion radius.
obstaclesSequence[Sequence[tuple[float, float]]] = []List of obstacle polygons (default []).
Returnstuple[list[list[tuple[float, float]]], float](region_polygons, total_area).
ComplexityO((n + m) log(n + m)) where n and m are boundary and obstacle point counts

Inset region: boundary shrunk, obstacles removed. Left: simple. Right: with central obstacle.

Inset region: boundary shrunk, obstacles removed. Left: simple. Right: with central obstacle.

Multi-obstacle inset: the region splits into multiple disconnected polygons.

Multi-obstacle inset: the region splits into multiple disconnected polygons.

Mixed convex/concave boundary + L-shaped island: verifies Round inset arcs at all joint types.

Mixed convex/concave boundary + L-shaped island: verifies Round inset arcs at all joint types.

concentric_offsets()

concentric_offsets(
geom: geo.Geometry,
step: float,
max_passes: int = 10,
min_area: float = 1,
) -> list[geo.Geometry]

Generate concentric inward offsets of a geometry.

Each successive offset shrinks the boundary by step. Stops early when the enclosed area drops below min_area or max_passes is reached. Returns offsets outermost-first.

ParameterTypeDescription
geomgeo.GeometryA closed geometry.
stepfloatInward offset distance per pass.
max_passesint = 10Maximum number of offset passes (default 10).
min_areafloat = 1Minimum area to stop at (default 1.0).
Returnslist[geo.Geometry]List of offset geometries, outermost first.
ComplexityO(n * p) time, O(n) space where n is the number of contour vertices and p the number of passes

Concentric inward offsets for adaptive clearing / pocketing

Concentric inward offsets for adaptive clearing / pocketing

find_deepest_cores()

find_deepest_cores(
regions: Sequence[geo.types.Polygon],
step_over: float,
) -> list[geo.types.Point]

Find the deepest (most open) regions of a polygon set.

Iteratively offsets each polygon inward by step_over until all polygons collapse. Returns the centroids of the final polygons.

ParameterTypeDescription
regionsSequence[geo.types.Polygon]List of polygons to search.
step_overfloatInward offset distance per iteration.
Returnslist[geo.types.Point]List of (x, y) centroid points.
ComplexityO(n * k) where k is the number of iterations

Deepest-core detection: finds max clearance in valid tool area — best helical-entry for the pocket

Deepest-core detection: finds max clearance in valid tool area — best helical-entry for the pocket

Multi-island pocket: clockwise contours are islands; core is deepest point in largest valid region.

Multi-island pocket: clockwise contours are islands; core is deepest point in largest valid region.

Central-island (annular): ring of valid tool area; deepest core is max clearance, never in island.

Central-island (annular): ring of valid tool area; deepest core is max clearance, never in island.

offset_contour_group()

offset_contour_group(
solid_path: Sequence[geo.types.Point],
hole_paths: Sequence[Sequence[geo.types.Point]],
offset: float,
join_style: geo.shape.polygon.JoinStyle = raygeo.geo.shape.polygon.JoinStyle.Miter,
) -> list[geo.types.Polygon]

Offset a solid contour with its hole contours.

Offsets the solid outward (or inward for negative offset) while offsetting holes in the opposite direction and subtracting them from the solid result.

ParameterTypeDescription
solid_pathSequence[geo.types.Point]Outer boundary polygon as (x, y) points.
hole_pathsSequence[Sequence[geo.types.Point]]List of hole polygons.
offsetfloatOffset distance (positive to inflate, negative to deflate).
join_stylegeo.shape.polygon.JoinStyle = raygeo.geo.shape.polygon.JoinStyle.MiterCorner join style (default: JoinStyle.Miter).
Returnslist[geo.types.Polygon]Offset polygon(s) with holes subtracted.
ComplexityO(n log n)