Skip to main content

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.
ParameterTypeDescription
rowsOptional[numpy.NDArray[numpy.float64]]A numpy array of shape (N, 8)
ReturnsNone

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.

ParameterTypeDescription
xfloatX coordinate.
yfloatY coordinate.
ifloat = 0.0I offset from current point to center.
jfloat = 0.0J offset from current point to center.
clockwisebool = TrueWhether the arc is clockwise.
zfloat = 0.0Z coordinate (default 0.0).
ReturnsNone

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.

ParameterTypeDescription
xfloatEnd X coordinate.
yfloatEnd Y coordinate.
ifloatI offset to center.
jfloatJ offset to center.
clockwisebool = TrueArc direction.
zfloat = 0.0End Z coordinate.
ReturnsNone

area()

area() -> float

Return the signed area of the geometry.

ParameterTypeDescription
Returnsfloat

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.

ParameterTypeDescription
xfloatEnd X coordinate.
yfloatEnd Y coordinate.
c1xfloatFirst control point X.
c1yfloatFirst control point Y.
c2xfloatSecond control point X.
c2yfloatSecond control point Y.
zfloat = 0.0End Z coordinate (default 0.0).
ReturnsNone

cleanup()

cleanup(tolerance: float) -> Geometry

Remove duplicate segments from the geometry.

ParameterTypeDescription
tolerancefloatMaximum deviation for equality.
ReturnsGeometry

clear()

clear() -> None

Remove all commands from the geometry.

ParameterTypeDescription
ReturnsNone

close_all_contours()

close_all_contours() -> Geometry

Close all open contours in the geometry.

ParameterTypeDescription
ReturnsGeometry

close_gaps()

close_gaps(tolerance: Optional[float] = None) -> Geometry

Close gaps between sub-paths.

ParameterTypeDescription
toleranceOptional[float] = NoneMax gap to close.
ReturnsGeometry

close_path()

close_path() -> None

Close the current sub-path.

ParameterTypeDescription
ReturnsNone

copy()

copy() -> Geometry

Return a deep copy of this geometry.

ParameterTypeDescription
ReturnsGeometry

distance()

distance() -> float

Return the total path distance.

ParameterTypeDescription
Returnsfloat

dump()

dump() -> dict

Serialize the geometry to a dictionary.

ParameterTypeDescription
Returnsdict

encloses()

encloses(other: Geometry) -> bool

Check if this geometry encloses another.

ParameterTypeDescription
otherGeometryThe potentially enclosed geometry.
Returnsbool

extend()

extend(other: Geometry) -> None

Append another geometry's commands to this one.

ParameterTypeDescription
otherGeometryThe geometry to append.
ReturnsNone

filter_to_external_contours()

filter_to_external_contours() -> list[Geometry]

Filter to only external (outermost) contours.

ParameterTypeDescription
Returnslist[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.

ParameterTypeDescription
xfloatX coordinate.
yfloatY coordinate.
ReturnsOptional[tuple[int, float, tuple[float, float]]]

fit_arcs()

fit_arcs(tolerance: float) -> Geometry

Fit arcs only to the linearized geometry.

ParameterTypeDescription
tolerancefloatMaximum deviation.
ReturnsGeometry

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.

ParameterTypeDescription
tolerancefloatMaximum deviation.
beziersbool = TrueWhether to fit bezier curves.
arcsbool = TrueWhether to fit arcs.
on_progressOptional[Any] = NoneOptional progress callback.
ReturnsGeometry

flip_x()

flip_x() -> Geometry

Mirror the geometry along the X axis.

ParameterTypeDescription
ReturnsGeometry

flip_y()

flip_y() -> Geometry

Mirror the geometry along the Y axis.

ParameterTypeDescription
ReturnsGeometry

from_dict()

@classmethod from_dict(data: dict) -> Geometry

Create a Geometry from a dictionary.

**to_dict**.
ParameterTypeDescription
datadictA dictionary as produced by
ReturnsGeometry

from_points()

@classmethod from_points(points: Any, close: bool = True) -> Geometry

Create a Geometry from a sequence of points.

(x, y, z) coordinate tuples.
ParameterTypeDescription
pointsAnyA sequence of (x, y) or
closebool = TrueWhether to close the path.
ReturnsGeometry

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.

ParameterTypeDescription
indexintCommand index (negative returns None).
ReturnsOptional[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.

ParameterTypeDescription
segment_indexintIndex of the segment.
tfloatParameter in [0, 1].
ReturnsOptional[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.

ParameterTypeDescription
segment_indexintIndex of the segment.
tfloatParameter in [0, 1].
ReturnsOptional[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.

ParameterTypeDescription
indexintCommand index.
ReturnsOptional[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".

ParameterTypeDescription
Returnslist[dict]

grow()

grow(amount: float) -> Geometry

Offset (grow/shrink) the geometry by the given amount.

ParameterTypeDescription
amountfloatPositive to grow, negative to shrink.
ReturnsGeometry

has_self_intersections()

has_self_intersections(fail_on_t_junction: bool = False) -> bool

Check if the geometry has self-intersections.

ParameterTypeDescription
fail_on_t_junctionbool = FalseWhether to fail on T-junctions.
Returnsbool

intersects_with()

intersects_with(other: Geometry) -> bool

Check if this geometry intersects with another.

ParameterTypeDescription
otherGeometryThe other geometry.
Returnsbool

is_closed()

is_closed(tolerance: float = 1e-06) -> bool

Check if the geometry forms a closed path.

ParameterTypeDescription
tolerancefloat = 1e-06Max gap between start and end point.
Returnsbool

is_empty()

is_empty() -> bool

Check if the geometry has no commands.

ParameterTypeDescription
Returnsbool

iter_commands()

iter_commands() -> list[tuple[float, float, float, float, float, float, float, float]]

Iterate over all commands as raw tuples.

ParameterTypeDescription
Returnslist[tuple[float, float, float, float, float, float, float, float]]

iter_typed_commands()

iter_typed_commands() -> list[PyCommand]

Iterate over all commands as typed PyCommand objects.

ParameterTypeDescription
Returnslist[PyCommand]

line_to()

line_to(x: float, y: float, z: float = 0.0) -> None

Draw a line to the given coordinates.

ParameterTypeDescription
xfloatX coordinate.
yfloatY coordinate.
zfloat = 0.0Z coordinate (default 0.0).
ReturnsNone

linearize()

linearize(tolerance: float) -> Geometry

Convert all curves to line segments.

ParameterTypeDescription
tolerancefloatMaximum deviation from curves.
ReturnsGeometry

load()

@classmethod load(data: dict) -> Geometry

Load a geometry from a dictionary.

**to_dict**.
ParameterTypeDescription
datadictA dictionary as produced by
ReturnsGeometry

map_to_frame()

map_to_frame(origin: tuple[float, float], p_width: tuple[float, float], p_height: tuple[float, float], anchor_y: Optional[float] = None, stable_src_height: Optional[float] = None, anchor_x: Optional[float] = None, stable_src_width: Optional[float] = None) -> Geometry

Map the geometry into a rectangular frame.

ParameterTypeDescription
origintuple[float, float]Frame origin (x, y).
p_widthtuple[float, float]Frame width vector.
p_heighttuple[float, float]Frame height vector.
anchor_yOptional[float] = NoneY anchor position.
stable_src_heightOptional[float] = NoneStable source height for anchoring.
anchor_xOptional[float] = NoneX anchor position.
stable_src_widthOptional[float] = NoneStable source width for anchoring.
ReturnsGeometry

move_to()

move_to(x: float, y: float, z: float = 0.0) -> None

Move the pen to the given coordinates.

ParameterTypeDescription
xfloatX coordinate.
yfloatY coordinate.
zfloat = 0.0Z coordinate (default 0.0).
ReturnsNone

normalize_winding_orders()

normalize_winding_orders() -> list[Geometry]

Normalize winding orders (outer CCW, inner CW) of all contours.

ParameterTypeDescription
Returnslist[Geometry]

rect()

rect() -> tuple[float, float, float, float]

Return the bounding rectangle (x_min, x_max, y_min, y_max).

ParameterTypeDescription
Returnstuple[float, float, float, float]

remove_inner_edges()

remove_inner_edges() -> Geometry

Remove inner edges (shared between contours).

ParameterTypeDescription
ReturnsGeometry

reverse_contour()

reverse_contour() -> Geometry

Reverse the winding direction of all contours.

ParameterTypeDescription
ReturnsGeometry

segments()

segments() -> list[list[tuple[float, float, float]]]

Return the geometry split into segments of connected commands.

ParameterTypeDescription
Returnslist[list[tuple[float, float, float]]]

simplify()

simplify(tolerance: float) -> Geometry

Simplify the geometry using Ramer-Douglas-Peucker.

ParameterTypeDescription
tolerancefloatMaximum deviation from original.
ReturnsGeometry

split_inner_and_outer_contours()

split_inner_and_outer_contours() -> tuple[list[Geometry], list[Geometry]]

Split contours into inner and outer groups.

ParameterTypeDescription
Returnstuple[list[Geometry], list[Geometry]]

split_into_components()

split_into_components() -> list[Geometry]

Split the geometry into connected components.

ParameterTypeDescription
Returnslist[Geometry]

split_into_contours()

split_into_contours() -> list[Geometry]

Split the geometry into individual contours.

ParameterTypeDescription
Returnslist[Geometry]

to_dict()

to_dict() -> dict

Serialize the geometry to a dictionary.

ParameterTypeDescription
Returnsdict

to_polygons()

to_polygons(tolerance: float = 0.01) -> list[list[tuple[float, float]]]

Convert the geometry to a list of polygons.

ParameterTypeDescription
tolerancefloat = 0.01Max deviation for linearization.
Returnslist[list[tuple[float, float]]]

transform()

transform(matrix: geo.types.TransformMatrix) -> Geometry

Apply a 4x4 affine transformation matrix.

See raygeo.geo.types.TransformMatrix for the matrix layout.

Returns: A new transformed Geometry.

ParameterTypeDescription
matrixgeo.types.TransformMatrixA 4x4 affine transformation matrix.
ReturnsGeometry

upgrade_to_scalable()

upgrade_to_scalable() -> Geometry

Convert all arcs to bezier curves for uniform scaling.

ParameterTypeDescription
ReturnsGeometry