Pular para o conteúdo principal

raygeo.geo

Various geometry shapes and operations

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.

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).
ReturnsGeometryThe geometry (for method chaining).
ComplexityO(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.

ParameterTypeDescription
xfloatEnd X coordinate.
yfloatEnd Y coordinate.
ifloatI offset to center.
jfloatJ offset to center.
clockwisebool = TrueArc direction.
zfloat = 0.0End Z coordinate.
ReturnsGeometryThe geometry (for method chaining).
ComplexityO(1) time, O(1) space

area()

area() -> float

Return the signed area of the geometry.

ParameterTypeDescription
ReturnsfloatThe signed area in mm².
ComplexityO(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.

ParameterTypeDescription
xfloatEnd X coordinate.
yfloatEnd Y coordinate.
c1xfloatFirst control point X.
c1yfloatFirst control point Y.
c2xfloatSecond control point X.
c2yfloatSecond control point Y.
c1zfloatFirst control point Z (default 0.0).
c2zfloatSecond control point Z (default 0.0).
zfloatEnd Z coordinate (default 0.0).
ReturnsGeometryThe geometry (for method chaining).
ComplexityO(1) time, O(1) space

cleanup()

cleanup(tolerance: float) -> Geometry

Remove duplicate segments from the geometry.

ParameterTypeDescription
tolerancefloatMaximum deviation for equality.
ReturnsGeometryThe geometry (for method chaining).
ComplexityO(n log n) average time, O(n) space

clear()

clear() -> Geometry

Remove all commands from the geometry.

ParameterTypeDescription
ReturnsGeometryThe geometry (for method chaining).
ComplexityO(1) time, O(1) space

close_all_contours()

close_all_contours() -> Geometry

Close all open contours in the geometry.

ParameterTypeDescription
ReturnsGeometryThe geometry (for method chaining).
ComplexityO(n) time, O(n) space

close_gaps()

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

Close gaps between sub-paths.

ParameterTypeDescription
toleranceOptional[float] = NoneMax gap to close.
ReturnsGeometryThe geometry (for method chaining).
ComplexityO(n) time, O(n) space

close_path()

close_path() -> Geometry

Close the current sub-path.

ParameterTypeDescription
ReturnsGeometryThe geometry (for method chaining).
ComplexityO(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.

ParameterTypeDescription
ReturnsNone
ComplexityO(n) time, O(n) space where n = number of commands

Overlay showing Bezier curves (with control points) closely matching the original arcs

Overlay showing Bezier curves (with control points) closely matching the original arcs

copy()

copy() -> Geometry

Return a deep copy of this geometry.

ParameterTypeDescription
ReturnsGeometryA deep copy of the geometry.
ComplexityO(n) time, O(n) space

distance()

distance() -> float

Return the total path distance.

ParameterTypeDescription
ReturnsfloatThe total path distance in mm.
ComplexityO(n) time, O(1) space

encloses()

encloses(other: Geometry) -> bool

Check if this geometry encloses another.

ParameterTypeDescription
otherGeometryThe potentially enclosed geometry.
ReturnsboolTrue if this geometry encloses the other.
ComplexityO(n log n) average time, O(n) space

extend()

extend(other: Geometry) -> Geometry

Append another geometry's commands to this one.

ParameterTypeDescription
otherGeometryThe geometry to append.
ReturnsGeometryThe geometry (for method chaining).
ComplexityO(n) time, O(n) space

filter()

filter(indices: set[int]) -> Geometry

Return a new Geometry containing only commands at the given indices.

ParameterTypeDescription
indicesset[int]Set of command indices to keep.
ReturnsGeometryA new Geometry with the filtered commands.
ComplexityO(n) time, O(n) space

filter_to_external_contours()

filter_to_external_contours() -> Geometry

Filter to only external (outermost) contours.

ParameterTypeDescription
ReturnsGeometryThe geometry (for method chaining).
ComplexityO(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).

ParameterTypeDescription
xfloatX coordinate.
yfloatY coordinate.
ReturnsOptional[tuple[int, float, tuple[float, float]]]Tuple of (segment_index, t, point) or None.
ComplexityO(n) time, O(1) space

fit_arcs()

fit_arcs(tolerance: float) -> Geometry

Fit arcs only to the linearized geometry.

ParameterTypeDescription
tolerancefloatMaximum deviation.
ReturnsGeometryThe geometry (for method chaining).
ComplexityO(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.

ParameterTypeDescription
tolerancefloatMaximum deviation.
beziersbool = TrueWhether to fit bezier curves.
arcsbool = TrueWhether to fit arcs.
on_progressOptional[Any] = NoneOptional progress callback called with (current, total).
ReturnsGeometryThe geometry (for method chaining).
ComplexityO(n log n) average time, O(n) space

flip_x()

flip_x() -> Geometry

Mirror the geometry along the X axis.

ParameterTypeDescription
ReturnsGeometryThe geometry (for method chaining).
ComplexityO(n) time, O(1) space

flip_y()

flip_y() -> Geometry

Mirror the geometry along the Y axis.

ParameterTypeDescription
ReturnsGeometryThe geometry (for method chaining).
ComplexityO(n) time, O(1) space

from_dict()

@classmethod from_dict(data: dict) -> Geometry

Create a Geometry from a dictionary.

ParameterTypeDescription
datadictA dictionary as produced by to_dict.
ReturnsGeometryA new Geometry instance.
ComplexityO(n) time, O(n) space

from_points()

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

Create a Geometry from a sequence of points.

ParameterTypeDescription
pointsAnyA sequence of (x, y) or (x, y, z) coordinate tuples.
closebool = TrueWhether to close the path.
ReturnsGeometryA new Geometry instance.
ComplexityO(n) time, O(n) space

get_command_at()

get_command_at(index: int) -> Optional[Any]

Get the command at the given index as a typed command object.

ParameterTypeDescription
indexintCommand index (negative returns None).
ReturnsOptional[Any]The typed command or None.
ComplexityO(1) time, O(1) space

get_last_point()

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

Get the last point in the geometry.

ParameterTypeDescription
Returnstuple[float, float, float]The last point as (x, y, z), or (0, 0, 0) if empty.
ComplexityO(1) time, O(1) space

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.

ParameterTypeDescription
segment_indexintIndex of the segment.
tfloatParameter in [0, 1].
ReturnsOptional[tuple[float, float]]Normal vector or None.
ComplexityO(1) time, O(1) space

get_point_at()

get_point_at(
segment_index: int,
t: float,
) -> Optional[tuple[float, float, float]]

Get the point at parameter t on a segment.

ParameterTypeDescription
segment_indexintIndex of the segment.
tfloatParameter in [0, 1].
ReturnsOptional[tuple[float, float, float]]The 3D point or None.
ComplexityO(1) time, O(1) space

get_positions_at_distances()

get_positions_at_distances(
distances: Sequence[float],
) -> list[tuple[int, float, tuple[float, float]]]

Given a list of distances along the path, returns the corresponding (segment_index, t, point) for each distance.

Distances are clamped to [0, total_length].

ParameterTypeDescription
distancesSequence[float]List of distances along the path.
Returnslist[tuple[int, float, tuple[float, float]]]List of (segment_index, t, (x, y)) tuples.
ComplexityO(n + m) time, O(m) space where n is the number of segments and m the number of distances

get_tangent_at()

get_tangent_at(segment_index: int, t: float) -> Optional[tuple[float, float]]

Get the tangent vector at parameter t on a segment.

ParameterTypeDescription
segment_indexintIndex of the segment.
tfloatParameter in [0, 1].
ReturnsOptional[tuple[float, float]]The normalized tangent vector or None.
ComplexityO(1) time, O(1) space

get_typed_command_at()

get_typed_command_at(index: int) -> Move | Line | Arc | Bezier | None

Get the typed command at the given index.

ParameterTypeDescription
indexintCommand index.
ReturnsMove | Line | Arc | Bezier | None
ComplexityO(1) time, O(1) space

get_valid_contours_data()

get_valid_contours_data() -> list[dict]

Get valid contour data from the geometry's contours.

ParameterTypeDescription
Returnslist[dict]List of dicts with keys "geo", "vertices", "is_closed", "original_index".
ComplexityO(n) time, O(n) space

grow()

grow(amount: float) -> Geometry

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

ParameterTypeDescription
amountfloatPositive to grow, negative to shrink.
ReturnsGeometryThe geometry (for method chaining).
ComplexityO(n log n) average time, O(n) space

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.
ReturnsboolTrue if the geometry has self-intersections.
ComplexityO(n²) worst-case time, O(1) space

intersects_with()

intersects_with(other: Geometry) -> bool

Check if this geometry intersects with another.

ParameterTypeDescription
otherGeometryThe other geometry.
ReturnsboolTrue if the geometries intersect.
ComplexityO(n * m) worst-case time, O(1) space where n and m are the number of segments in each geometry

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.
ReturnsboolTrue if the geometry forms a closed path.
ComplexityO(n) time, O(1) space

is_empty()

is_empty() -> bool

Check if the geometry has no commands.

ParameterTypeDescription
ReturnsboolTrue if the geometry has no commands.
ComplexityO(1) time, O(1) space

iter_commands()

iter_commands() -> list[Any]

Iterate over all commands as typed command objects.

ParameterTypeDescription
Returnslist[Any]List of typed command objects.
ComplexityO(n) time, O(n) space

iter_typed_commands()

iter_typed_commands() -> list[Move | Line | Arc | Bezier]

Iterate over all commands as typed command objects.

ParameterTypeDescription
Returnslist[Move | Line | Arc | Bezier]
ComplexityO(n) time, O(n) space

line_to()

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

Draw a line to the given coordinates.

ParameterTypeDescription
xfloatX coordinate.
yfloatY coordinate.
zfloat = 0.0Z coordinate (default 0.0).
ReturnsGeometryThe geometry (for method chaining).
ComplexityO(1) time, O(1) space

linearize()

linearize(tolerance: float) -> Geometry

Convert all curves to line segments.

ParameterTypeDescription
tolerancefloatMaximum deviation from curves.
ReturnsGeometryThe geometry (for method chaining).
ComplexityO(n) time, O(n) space

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.
ReturnsGeometryThe geometry (for method chaining).
ComplexityO(n) time, O(n) space

move_to()

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

Move the pen to the given coordinates.

ParameterTypeDescription
xfloatX coordinate.
yfloatY coordinate.
zfloat = 0.0Z coordinate (default 0.0).
ReturnsGeometryThe geometry (for method chaining).
ComplexityO(1) time, O(1) space

normalize_winding_orders()

normalize_winding_orders() -> Geometry

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

ParameterTypeDescription
ReturnsGeometryThe geometry (for method chaining).
ComplexityO(n log n) average time, O(n) space

rect()

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

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

ParameterTypeDescription
Returnstuple[float, float, float, float](x_min, y_min, x_max, y_max).
ComplexityO(n) time, O(1) space

remove_inner_edges()

remove_inner_edges() -> Geometry

Remove inner edges (shared between contours).

ParameterTypeDescription
ReturnsGeometryThe geometry (for method chaining).
ComplexityO(n) time, O(n) space

reverse_contour()

reverse_contour() -> Geometry

Reverse the winding direction of all contours.

ParameterTypeDescription
ReturnsGeometryThe geometry (for method chaining).
ComplexityO(n) time, O(n) space

segment_bounds()

segment_bounds(index: int) -> Optional[tuple[float, float, float, float]]

Return the bounding box of a single segment at the given index. Returns None for Move commands or if the index is out of bounds.

ParameterTypeDescription
indexintSegment index.
ReturnsOptional[tuple[float, float, float, float]](x_min, y_min, x_max, y_max) or None.
ComplexityO(1) time, O(1) space

segments()

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

Return the geometry split into segments of connected commands.

ParameterTypeDescription
Returnslist[list[tuple[float, float, float]]]List of segments, each a list of 3D points.
ComplexityO(n) time, O(n) space

segments_in_frame()

segments_in_frame(x1: float, y1: float, x2: float, y2: float) -> list[int]

Return indices of all segments whose bounding box intersects the given rectangle. Excludes Move commands.

ParameterTypeDescription
x1floatFirst corner X.
y1floatFirst corner Y.
x2floatSecond corner X.
y2floatSecond corner Y.
Returnslist[int]List of segment indices.
ComplexityO(n) time, O(n) space

simplify()

simplify(tolerance: float) -> Geometry

Simplify the geometry using Ramer-Douglas-Peucker.

ParameterTypeDescription
tolerancefloatMaximum deviation from original.
ReturnsGeometryThe geometry (for method chaining).
ComplexityO(n log n) average time, O(n) space

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]]Tuple of (inner_contours, outer_contours), each a list of Geometry.
ComplexityO(n log n) average time, O(n) space

split_into_components()

split_into_components() -> list[Geometry]

Split the geometry into connected components.

ParameterTypeDescription
Returnslist[Geometry]List of Geometry objects, one per connected component.
ComplexityO(n log n) average time, O(n) space

split_into_contours()

split_into_contours() -> list[Geometry]

Split the geometry into individual contours.

ParameterTypeDescription
Returnslist[Geometry]List of Geometry objects, one per contour.
ComplexityO(n) time, O(n) space

to_dict()

to_dict() -> dict

Serialize the geometry to a dictionary.

ParameterTypeDescription
ReturnsdictA dictionary representation of the geometry.
ComplexityO(n) time, O(n) space

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]]]List of polygons, each a list of (x, y) vertices.
ComplexityO(n) time, O(n) space

transform()

transform(matrix: Matrix | types.TransformMatrix) -> Geometry

Apply an affine transformation matrix.

ParameterTypeDescription
matrixMatrix | types.TransformMatrixA ~raygeo.geo.Matrix or a 4x4 matrix as list of lists.
ReturnsGeometryA new transformed Geometry.
ComplexityO(n) time, O(n) space

upgrade_to_scalable()

upgrade_to_scalable() -> Geometry

Convert all arcs to bezier curves for uniform scaling.

ParameterTypeDescription
ReturnsGeometryThe geometry (for method chaining).
ComplexityO(n) time, O(n) space

Line

A straight-line cutting command.

end

end: tuple[float, float, float]

Endpoint of the line in 3D space.

Matrix

A 3x3 affine transformation matrix for 2D graphics.

Provides an object-oriented interface for matrix operations, including translations, rotations, and scaling.

compose()

@classmethod
compose(
tx: float,
ty: float,
angle_deg: float,
sx: float,
sy: float,
skew_angle_deg: float,
) -> Matrix

Compose a matrix from translation, rotation, scale, and skew.

ParameterTypeDescription
txfloatTranslation x.
tyfloatTranslation y.
angle_degfloatRotation angle in degrees.
sxfloatScale x.
syfloatScale y.
skew_angle_degfloatSkew angle in degrees.
ReturnsMatrixA new Matrix.

copy()

copy() -> Matrix

Return a deep copy of this matrix.

ParameterTypeDescription
ReturnsMatrix

decompose()

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

Decompose the matrix into translation, rotation, scale, and skew.

ParameterTypeDescription
Returnstuple[float, float, float, float, float, float](tx, ty, angle_deg, sx, sy, skew_angle_deg).

flip_horizontal()

@classmethod
flip_horizontal(
center: Optional[tuple[float, float]] = None,
) -> Matrix

Create a horizontal flip matrix.

ParameterTypeDescription
centerOptional[tuple[float, float]] = None
ReturnsMatrix

flip_vertical()

@classmethod
flip_vertical(
center: Optional[tuple[float, float]] = None,
) -> Matrix

Create a vertical flip matrix.

ParameterTypeDescription
centerOptional[tuple[float, float]] = None
ReturnsMatrix

for_cairo()

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

Returns the matrix components in Cairo order (xx, yx, xy, yy, x0, y0).

ParameterTypeDescription
Returnstuple[float, float, float, float, float, float]

from_list()

@classmethod from_list(data: Sequence[Sequence[float]]) -> Matrix

Create a Matrix from a list of lists.

ParameterTypeDescription
dataSequence[Sequence[float]]
ReturnsMatrix

get()

get(row: int, col: int) -> float

Get a single element from the 3x3 matrix (row-major indexing).

ParameterTypeDescription
rowint
colint
Returnsfloat

get_abs_scale()

get_abs_scale() -> tuple[float, float]

Extract the absolute scale components (|sx|, |sy|).

ParameterTypeDescription
Returnstuple[float, float]

get_determinant_2x2()

get_determinant_2x2() -> float

Calculate the determinant of the top-left 2x2 sub-matrix.

ParameterTypeDescription
Returnsfloat

get_rotation()

get_rotation() -> float

Extract the rotation angle in degrees.

ParameterTypeDescription
Returnsfloat

get_scale()

get_scale() -> tuple[float, float]

Extract the signed scale components (sx, sy).

ParameterTypeDescription
Returnstuple[float, float]

get_translation()

get_translation() -> tuple[float, float]

Extract the translation component (tx, ty).

ParameterTypeDescription
Returnstuple[float, float]

get_x_axis_angle()

get_x_axis_angle() -> float

Calculate the angle of the transformed X-axis in degrees.

ParameterTypeDescription
Returnsfloat

get_y_axis_angle()

get_y_axis_angle() -> float

Calculate the angle of the transformed Y-axis in degrees.

ParameterTypeDescription
Returnsfloat

has_zero_scale()

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

Check if the matrix has zero scale on any axis.

ParameterTypeDescription
tolerancefloat = 1e-06Threshold below which a scale is considered zero.
Returnsbool

identity()

@classmethod identity() -> Matrix

Create an identity matrix.

ParameterTypeDescription
ReturnsMatrix

invert()

invert() -> Matrix

Compute the inverse of the matrix.

Will raise an error if the matrix is singular.

ParameterTypeDescription
ReturnsMatrix

is_close()

is_close(other: Matrix, tol: float = 1e-06) -> bool

Check if two matrices are effectively equal within tolerance.

ParameterTypeDescription
otherMatrixThe matrix to compare against.
tolfloat = 1e-06The absolute tolerance parameter.
Returnsbool

is_flipped()

is_flipped() -> bool

Check if the matrix includes a reflection (flip).

ParameterTypeDescription
Returnsbool

is_identity()

is_identity() -> bool

Check if the matrix is an identity matrix.

ParameterTypeDescription
Returnsbool

post_rotate()

post_rotate(
angle_deg: float,
center: Optional[tuple[float, float]] = None,
) -> Matrix

Apply a rotation after this matrix's transformation.

ParameterTypeDescription
angle_degfloatRotation angle in degrees.
centerOptional[tuple[float, float]] = NoneOptional center point to rotate around.
ReturnsMatrix

post_scale()

post_scale(
sx: float,
sy: float,
center: Optional[tuple[float, float]] = None,
) -> Matrix

Apply a scale after this matrix's transformation.

ParameterTypeDescription
sxfloatScale factor for x-axis.
syfloatScale factor for y-axis.
centerOptional[tuple[float, float]] = NoneOptional center point to scale around.
ReturnsMatrix

post_shear()

post_shear(
shx: float,
shy: float,
center: Optional[tuple[float, float]] = None,
) -> Matrix

Apply a shear after this matrix's transformation.

ParameterTypeDescription
shxfloatShear factor for x-axis.
shyfloatShear factor for y-axis.
centerOptional[tuple[float, float]] = NoneOptional center point to shear around.
ReturnsMatrix

post_translate()

post_translate(tx: float, ty: float) -> Matrix

Apply a translation after this matrix's transformation.

ParameterTypeDescription
txfloat
tyfloat
ReturnsMatrix

pre_rotate()

pre_rotate(
angle_deg: float,
center: Optional[tuple[float, float]] = None,
) -> Matrix

Apply a rotation before this matrix's transformation.

ParameterTypeDescription
angle_degfloatRotation angle in degrees.
centerOptional[tuple[float, float]] = NoneOptional center point to rotate around.
ReturnsMatrix

pre_scale()

pre_scale(
sx: float,
sy: float,
center: Optional[tuple[float, float]] = None,
) -> Matrix

Apply a scale before this matrix's transformation.

ParameterTypeDescription
sxfloatScale factor for x-axis.
syfloatScale factor for y-axis.
centerOptional[tuple[float, float]] = NoneOptional center point to scale around.
ReturnsMatrix

pre_shear()

pre_shear(
shx: float,
shy: float,
center: Optional[tuple[float, float]] = None,
) -> Matrix

Apply a shear before this matrix's transformation.

ParameterTypeDescription
shxfloatShear factor for x-axis.
shyfloatShear factor for y-axis.
centerOptional[tuple[float, float]] = NoneOptional center point to shear around.
ReturnsMatrix

pre_translate()

pre_translate(tx: float, ty: float) -> Matrix

Apply a translation before this matrix's transformation.

ParameterTypeDescription
txfloat
tyfloat
ReturnsMatrix

rotation()

@classmethod
rotation(
angle_deg: float,
center: Optional[tuple[float, float]] = None,
) -> Matrix

Create a rotation matrix.

ParameterTypeDescription
angle_degfloatRotation angle in degrees.
centerOptional[tuple[float, float]] = NoneOptional (x, y) center point to rotate around.
ReturnsMatrix

scale()

@classmethod
scale(
sx: float,
sy: float,
center: Optional[tuple[float, float]] = None,
) -> Matrix

Create a scaling matrix.

ParameterTypeDescription
sxfloatScale factor for x-axis.
syfloatScale factor for y-axis.
centerOptional[tuple[float, float]] = NoneOptional (x, y) center point to scale around.
ReturnsMatrix

set_translation()

set_translation(tx: float, ty: float) -> Matrix

Returns a new matrix with the same rotation/scale/shear but new translation.

ParameterTypeDescription
txfloatNew translation x.
tyfloatNew translation y.
ReturnsMatrix

shear()

@classmethod
shear(
shx: float,
shy: float,
center: Optional[tuple[float, float]] = None,
) -> Matrix

Create a shearing matrix.

ParameterTypeDescription
shxfloatShear factor for x-axis.
shyfloatShear factor for y-axis.
centerOptional[tuple[float, float]] = NoneOptional (x, y) center point to shear around.
ReturnsMatrix

to_4x4_list()

to_4x4_list() -> list[list[float]]

Converts the matrix to a 4x4 list of lists (row-major). The 3x3 Matrix is placed in the top-left 2x2 of the 4x4, with translation in the last column, and Z preserved.

ParameterTypeDescription
Returnslist[list[float]]

to_4x4_numpy()

to_4x4_numpy() -> numpy.NDArray[numpy.float64]

Return the matrix as a 4x4 numpy array (affine, Z-preserving).

ParameterTypeDescription
Returnsnumpy.NDArray[numpy.float64]

to_graphene()

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

Returns (xx, yx, xy, yy, x0, y0) for GTK/Graphene.

ParameterTypeDescription
Returnstuple[float, float, float, float, float, float]

to_list()

to_list() -> list[list[float]]

Returns a copy of the matrix data as a list of lists.

ParameterTypeDescription
Returnslist[list[float]]

to_numpy()

to_numpy() -> numpy.NDArray[numpy.float64]

Return the matrix as a 3x3 numpy array.

ParameterTypeDescription
Returnsnumpy.NDArray[numpy.float64]

transform_point()

transform_point(*args: float | tuple[float, float]) -> tuple[float, float]

Apply the affine transformation to a 2D point.

ParameterTypeDescription
*argsfloat | tuple[float, float]
Returnstuple[float, float]

transform_rectangle()

transform_rectangle(
*args: float | tuple[float, float, float, float],
) -> tuple[float, float, float, float]

Transform a rectangle and return the new axis-aligned bounding box.

ParameterTypeDescription
*argsfloat | tuple[float, float, float, float]
Returnstuple[float, float, float, float]

transform_vector()

transform_vector(*args: float | tuple[float, float]) -> tuple[float, float]

Apply the transformation to a 2D vector, ignoring translation.

ParameterTypeDescription
*argsfloat | tuple[float, float]
Returnstuple[float, float]

translation()

@classmethod translation(tx: float, ty: float) -> Matrix

Create a translation matrix.

ParameterTypeDescription
txfloatTranslation in x.
tyfloatTranslation in y.
ReturnsMatrix

without_translation()

without_translation() -> Matrix

Returns a new matrix with translation set to zero.

ParameterTypeDescription
ReturnsMatrix

Move

A rapid-move command with an endpoint but no cutting.

end

end: tuple[float, float, float]

Endpoint of the move in 3D space.