raygeo.geo
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.
Geometry
data
data: Optional[numpy.NDArray[numpy.float64]]
The command data as a numpy array of shape (N, 8), or None if empty.
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.
append_data()
append_data(rows: Optional[numpy.NDArray[numpy.float64]]) -> None
Append rows of command data to the geometry.
containing command rows, or None.
| Parameter | Type | Description |
|---|---|---|
rows | Optional[numpy.NDArray[numpy.float64]] | A numpy array of shape (N, 8) |
| Returns | None |
arc_to()
arc_to(x: float, y: float, i: float = 0.0, j: float = 0.0, clockwise: bool = True, z: float = 0.0) -> None
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 | None |
arc_to_as_bezier()
arc_to_as_bezier(x: float, y: float, i: float, j: float, clockwise: bool = True, z: float = 0.0) -> None
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 | None |
area()
area() -> float
Return the signed area of the geometry.
| Parameter | Type | Description |
|---|---|---|
| Returns | float |
bezier_to()
bezier_to(x: float, y: float, c1x: float, c1y: float, c2x: float, c2y: float, z: float = 0.0) -> None
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. |
z | float = 0.0 | End Z coordinate (default 0.0). |
| Returns | None |
cleanup()
cleanup(tolerance: float) -> Geometry
Remove duplicate segments from the geometry.
| Parameter | Type | Description |
|---|---|---|
tolerance | float | Maximum deviation for equality. |
| Returns | Geometry |
clear()
clear() -> None
Remove all commands from the geometry.
| Parameter | Type | Description |
|---|---|---|
| Returns | None |
close_all_contours()
close_all_contours() -> Geometry
Close all open contours in the geometry.
| Parameter | Type | Description |
|---|---|---|
| Returns | Geometry |
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 |
close_path()
close_path() -> None
Close the current sub-path.
| Parameter | Type | Description |
|---|---|---|
| Returns | None |
copy()
copy() -> Geometry
Return a deep copy of this geometry.
| Parameter | Type | Description |
|---|---|---|
| Returns | Geometry |
distance()
distance() -> float
Return the total path distance.
| Parameter | Type | Description |
|---|---|---|
| Returns | float |
dump()
dump() -> dict
Serialize the geometry to a dictionary.
| Parameter | Type | Description |
|---|---|---|
| Returns | dict |
encloses()
encloses(other: Geometry) -> bool
Check if this geometry encloses another.
| Parameter | Type | Description |
|---|---|---|
other | Geometry | The potentially enclosed geometry. |
| Returns | bool |
extend()
extend(other: Geometry) -> None
Append another geometry's commands to this one.
| Parameter | Type | Description |
|---|---|---|
other | Geometry | The geometry to append. |
| Returns | None |
filter_to_external_contours()
filter_to_external_contours() -> list[Geometry]
Filter to only external (outermost) contours.
| Parameter | Type | Description |
|---|---|---|
| Returns | list[Geometry] |
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).
Returns: Tuple of (segment_index, t, point) or None.
| Parameter | Type | Description |
|---|---|---|
x | float | X coordinate. |
y | float | Y coordinate. |
| Returns | Optional[tuple[int, float, tuple[float, float]]] |
fit_arcs()
fit_arcs(tolerance: float) -> Geometry
Fit arcs only to the linearized geometry.
| Parameter | Type | Description |
|---|---|---|
tolerance | float | Maximum deviation. |
| Returns | Geometry |
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. |
| Returns | Geometry |
flip_x()
flip_x() -> Geometry
Mirror the geometry along the X axis.
| Parameter | Type | Description |
|---|---|---|
| Returns | Geometry |
flip_y()
flip_y() -> Geometry
Mirror the geometry along the Y axis.
| Parameter | Type | Description |
|---|---|---|
| Returns | Geometry |
from_dict()
@classmethod from_dict(data: dict) -> Geometry
Create a Geometry from a dictionary.
**to_dict**.
| Parameter | Type | Description |
|---|---|---|
data | dict | A dictionary as produced by |
| Returns | Geometry |
from_points()
@classmethod from_points(points: Any, close: bool = True) -> Geometry
Create a Geometry from a sequence of points.
(x, y, z) coordinate tuples.
| Parameter | Type | Description |
|---|---|---|
points | Any | A sequence of (x, y) or |
close | bool = True | Whether to close the path. |
| Returns | Geometry |
get_command_at()
get_command_at(index: int) -> Optional[tuple[float, float, float, float, float, float, float, float]]
Get the command at the given index as a raw tuple.
| Parameter | Type | Description |
|---|---|---|
index | int | Command index (negative returns None). |
| Returns | Optional[tuple[float, float, float, float, float, float, float, float]] |
get_outward_normal_at()
get_outward_normal_at(segment_index: int, t: float) -> Optional[tuple[float, float]]
Get the outward normal at parameter t on a segment.
Returns: Normal vector or None.
| Parameter | Type | Description |
|---|---|---|
segment_index | int | Index of the segment. |
t | float | Parameter in [0, 1]. |
| Returns | Optional[tuple[float, float]] |
get_point_and_tangent_at()
get_point_and_tangent_at(segment_index: int, t: float) -> Optional[tuple[tuple[float, float], tuple[float, float]]]
Get the point and tangent vector at parameter t on a segment.
Returns: Tuple of (point, tangent) or None.
| Parameter | Type | Description |
|---|---|---|
segment_index | int | Index of the segment. |
t | float | Parameter in [0, 1]. |
| Returns | Optional[tuple[tuple[float, float], tuple[float, float]]] |
get_typed_command_at()
get_typed_command_at(index: int) -> Optional[PyCommand]
Get the typed command at the given index.
| Parameter | Type | Description |
|---|---|---|
index | int | Command index. |
| Returns | Optional[PyCommand] |
get_valid_contours_data()
get_valid_contours_data() -> list[dict]
Get valid contour data from the geometry's contours.
Returns: List of dicts with keys "geo", "vertices", "is_closed", "original_index".
| Parameter | Type | Description |
|---|---|---|
| Returns | list[dict] |