raygeo.geo

Various geometry shapes and operations Geometry types and operations for 2D/3D path data.
The central type is Geometry — a mutable sequence of drawing commands (move, line, arc, bezier) that represents one or more closed or open paths. Geometry supports construction (add_rect, add_circle, etc.), analysis (area, distance, bounding rect), and manipulation (transform, simplify, linearize, fit curves, grow/shrink, split, clip).
Shape sub-modules provide primitive-specific operations: arc bounding and intersection, bezier splitting and flattening, circle containment tests, polygon boolean algebra and offsetting, and line intersection.
Algorithm sub-modules provide higher-level geometric processing such as polyline simplification, smoothing, curve fitting, and Minkowski sums for toolpath generation.
Arc
A circular-arc cutting command.
center_offset
center_offset: tuple[float, float, float]
Centre offset from the start point (3D).
clockwise
clockwise: bool
Whether the arc is clockwise (computed from the normal).
end
end: tuple[float, float, float]
Endpoint of the arc in 3D space.
normal
normal: tuple[float, float, float]
Plane normal of the arc. A positive Z component means CCW in XY.
Bezier
A cubic-Bezier curve cutting command.
control1
control1: tuple[float, float, float]
First control point in 3D space.
control2
control2: tuple[float, float, float]
Second control point in 3D space.
end
end: tuple[float, float, float]
Endpoint of the curve in 3D space.
Geometry
A sequence of geometric commands (Move, Line, Arc, Bezier).
The primary building block for vector geometry in raygeo. Geometry objects can be constructed procedurally, parsed from SVG, or obtained by converting an ~raygeo.ops.Ops sequence.
data
data: list[Any]
The commands as a list of typed command objects.
last_move_to
last_move_to: tuple[float, float, float]
The coordinates of the last move-to command.
uniform_scalable
uniform_scalable: bool
Whether the geometry uses uniform scalable arcs.
arc_to()
arc_to(
x: float,
y: float,
i: float = 0.0,
j: float = 0.0,
clockwise: bool = True,
z: float = 0.0,
) -> Geometry
Draw an arc to the given coordinates.
| Parameter | Type | Description |
|---|---|---|
x | float | X coordinate. |
y | float | Y coordinate. |
i | float = 0.0 | I offset from current point to center. |
j | float = 0.0 | J offset from current point to center. |
clockwise | bool = True | Whether the arc is clockwise. |
z | float = 0.0 | Z coordinate (default 0.0). |
| Returns | Geometry | The geometry (for method chaining). |
| Complexity | O(1) time, O(1) space |
arc_to_as_bezier()
arc_to_as_bezier(
x: float,
y: float,
i: float,
j: float,
clockwise: bool = True,
z: float = 0.0,
) -> Geometry
Draw an arc, converting it to bezier curves.
| Parameter | Type | Description |
|---|---|---|
x | float | End X coordinate. |
y | float | End Y coordinate. |
i | float | I offset to center. |
j | float | J offset to center. |
clockwise | bool = True | Arc direction. |
z | float = 0.0 | End Z coordinate. |
| Returns | Geometry | The geometry (for method chaining). |
| Complexity | O(1) time, O(1) space |
area()
area() -> float
Return the signed area of the geometry.
| Parameter | Type | Description |
|---|---|---|
| Returns | float | The signed area in mm². |
| Complexity | O(n) time, O(1) space |
bezier_to()
bezier_to(
x: float,
y: float,
c1x: float,
c1y: float,
c2x: float,
c2y: float,
*,
c1z: float = 0.0,
c2z: float = 0.0,
z: float = 0.0,
) -> Geometry
Draw a cubic bezier curve.
| Parameter | Type | Description |
|---|---|---|
x | float | End X coordinate. |
y | float | End Y coordinate. |
c1x | float | First control point X. |
c1y | float | First control point Y. |
c2x | float | Second control point X. |
c2y | float | Second control point Y. |
c1z | float | First control point Z (default 0.0). |
c2z | float | Second control point Z (default 0.0). |
z | float | End Z coordinate (default 0.0). |
| Returns | Geometry | The geometry (for method chaining). |
| Complexity | O(1) time, O(1) space |
cleanup()
cleanup(tolerance: float) -> Geometry
Remove duplicate segments from the geometry.
| Parameter | Type | Description |
|---|---|---|
tolerance | float | Maximum deviation for equality. |
| Returns | Geometry | The geometry (for method chaining). |
| Complexity | O(n log n) average time, O(n) space |
clear()
clear() -> Geometry
Remove all commands from the geometry.
| Parameter | Type | Description |
|---|---|---|
| Returns | Geometry | The geometry (for method chaining). |
| Complexity | O(1) time, O(1) space |
close_all_contours()
close_all_contours() -> Geometry
Close all open contours in the geometry.
| Parameter | Type | Description |
|---|---|---|
| Returns | Geometry | The geometry (for method chaining). |
| Complexity | O(n) time, O(n) space |
close_gaps()
close_gaps(tolerance: Optional[float] = None) -> Geometry
Close gaps between sub-paths.
| Parameter | Type | Description |
|---|---|---|
tolerance | Optional[float] = None | Max gap to close. |
| Returns | Geometry | The geometry (for method chaining). |
| Complexity | O(n) time, O(n) space |
close_path()
close_path() -> Geometry
Close the current sub-path.
| Parameter | Type | Description |
|---|---|---|
| Returns | Geometry | The geometry (for method chaining). |
| Complexity | O(1) time, O(1) space |
convert_arcs_to_beziers()
convert_arcs_to_beziers() -> None
Convert all Arc commands to Bezier curve approximations in-place.
After this call, the geometry will only contain Move, Line, and Bezier commands.
| Parameter | Type | Description |
|---|---|---|
| Returns | None | |
| Complexity | O(n) time, O(n) space where n = number of commands |

Overlay showing Bezier curves (with control points) closely matching the original arcs
copy()
copy() -> Geometry
Return a deep copy of this geometry.
| Parameter | Type | Description |
|---|---|---|
| Returns | Geometry | A deep copy of the geometry. |
| Complexity | O(n) time, O(n) space |
distance()
distance() -> float
Return the total path distance.
| Parameter | Type | Description |
|---|---|---|
| Returns | float | The total path distance in mm. |
| Complexity | O(n) time, O(1) space |
encloses()
encloses(other: Geometry) -> bool
Check if this geometry encloses another.
| Parameter | Type | Description |
|---|---|---|
other | Geometry | The potentially enclosed geometry. |
| Returns | bool | True if this geometry encloses the other. |
| Complexity | O(n log n) average time, O(n) space |
extend()
extend(other: Geometry) -> Geometry
Append another geometry's commands to this one.
| Parameter | Type | Description |
|---|---|---|
other | Geometry | The geometry to append. |
| Returns | Geometry | The geometry (for method chaining). |
| Complexity | O(n) time, O(n) space |
filter()
filter(indices: set[int]) -> Geometry
Return a new Geometry containing only commands at the given indices.
| Parameter | Type | Description |
|---|---|---|
indices | set[int] | Set of command indices to keep. |
| Returns | Geometry | A new Geometry with the filtered commands. |
| Complexity | O(n) time, O(n) space |
filter_to_external_contours()
filter_to_external_contours() -> Geometry
Filter to only external (outermost) contours.
| Parameter | Type | Description |
|---|---|---|
| Returns | Geometry | The geometry (for method chaining). |
| Complexity | O(n log n) average time, O(n) space |
find_closest_point()
find_closest_point(
x: float,
y: float,
) -> Optional[tuple[int, float, tuple[float, float]]]
Find the closest point on the path to (x, y).
| Parameter | Type | Description |
|---|---|---|
x | float | X coordinate. |
y | float | Y coordinate. |
| Returns | Optional[tuple[int, float, tuple[float, float]]] | Tuple of (segment_index, t, point) or None. |
| Complexity | O(n) time, O(1) space |
fit_arcs()
fit_arcs(tolerance: float) -> Geometry
Fit arcs only to the linearized geometry.
| Parameter | Type | Description |
|---|---|---|
tolerance | float | Maximum deviation. |
| Returns | Geometry | The geometry (for method chaining). |
| Complexity | O(n log n) average time, O(n) space |
fit_curves()
fit_curves(
tolerance: float,
beziers: bool = True,
arcs: bool = True,
on_progress: Optional[Any] = None,
) -> Geometry
Fit curves (beziers and arcs) to the linearized geometry.
| Parameter | Type | Description |
|---|---|---|
tolerance | float | Maximum deviation. |
beziers | bool = True | Whether to fit bezier curves. |
arcs | bool = True | Whether to fit arcs. |
on_progress | Optional[Any] = None | Optional progress callback called with (current, total). |
| Returns | Geometry | The geometry (for method chaining). |
| Complexity | O(n log n) average time, O(n) space |