Pular para o conteúdo principal

raygeo.ops

Command sequence (Ops) manipulation for CNC motion control.

Ops is a container of ordered commands (move, line, arc, bezier, state changes like power/feed) that defines a complete machining job. It supports building sequences programmatically (move_to, line_to, arc_to, etc.), transforming them (translate, rotate, scale, transform with 4x4 matrices), clipping to rectangles or regions, linearizing curves, estimating processing time, and serializing to dict or numpy arrays for persistence.

The module also provides command-type enumerations (CommandType, CommandCategory, SectionType), machine State tracking (power, feed, coolant, air_assist, head_coolant, frequency), and an Axis bitflag for multi-axis machines.

CommandInfo

Detailed information about a single command in an Ops sequence.

Returned by Ops.inspect and provides the full set of parameters for any command type in a structured form.

air_assist

air_assist: Optional[state.AirAssistMode]

Air assist mode, if a SetAirAssist command.

center_offset

center_offset: Optional[tuple[float, float]]

Arc centre offset from start point, if an arc command.

clockwise

clockwise: Optional[bool]

Whether an arc is clockwise, if an arc command.

control

control: Optional[tuple[float, float, float]]

Quadratic-Bezier control point, if a quad. Bezier command.

control1

control1: Optional[tuple[float, float, float]]

First cubic-Bezier control point, if a Bezier command.

control2

control2: Optional[tuple[float, float, float]]

Second cubic-Bezier control point, if a Bezier command.

coolant

coolant: Optional[state.CoolantMode]

Coolant mode, if a SetCoolant command.

duration_ms

duration_ms: Optional[float]

Dwell duration in ms, if a dwell command.

end

end: Optional[tuple[float, float, float]]

Endpoint of the command in 3D space, if applicable.

extra_axes

extra_axes: Optional[dict]

Extra axis positions, if any.

feed_rate

feed_rate: Optional[int]

Feed rate setting, if a SetFeedRate command.

frequency

frequency: Optional[int]

Laser frequency (Hz), if a frequency-setting command.

head_coolant

head_coolant: Optional[state.HeadCoolantMode]

Head coolant mode, if a SetHeadCoolant command.

head_uid

head_uid: Optional[str]

Unique identifier of the active head, if a head-setting command.

layer_uid

layer_uid: Optional[str]

Unique identifier of the active layer, if a layer-start command.

power

power: Optional[float]

Power level (0–1), if a power-setting command.

power_values

power_values: Optional[bytes]

Per-step power byte values for scan-to commands.

pulse_width

pulse_width: Optional[float]

Laser pulse width (µs), if a pulse-width-setting command.

rapid_rate

rapid_rate: Optional[int]

Rapid rate setting, if a SetRapidRate command.

section_type

section_type: Optional[types.SectionType]

Section type, if a section marker.

spindle_rpm

spindle_rpm: Optional[int]

Spindle RPM, if a SetSpindleRpm command.

state

state: Optional[state.State]

State snapshot at this command, if present.

type_

type_: types.CommandType

The type of this command (e.g. Move, Line, Arc, Bezier, ScanTo, …).

workpiece_uid

workpiece_uid: Optional[str]

Unique identifier of the active workpiece, if a workpiece-start command.

Ops

A sequence of machining operations (commands).

Ops is a container of ordered commands that define a complete machining job. It supports building command sequences programmatically, transforming them, clipping, serializing, and more.

Use the builder methods (move_to, line_to, arc_to, etc.) to construct a sequence, or load from geometry/dict/numpy arrays.

last_move_to

last_move_to: tuple[float, float, float]

The last (x, y, z) endpoint from a MoveTo command.

scanline_count

scanline_count: int

Return the number of scanline commands in the sequence.

air_assist()

air_assist(idx: int) -> state.AirAssistMode

Get the air assist mode from a SetAirAssist command.

Raises: TypeError — If the command is not a SetAirAssist.

ParameterTypeDescription
idxintCommand index.
Returnsstate.AirAssistModeThe air assist mode.
ComplexityO(1) time, O(1) space

apply_bidir_scan_offset()

apply_bidir_scan_offset(offset_mm: float) -> None

Correct X misalignment between left-to-right and right-to-left raster passes.

For every raster pass (a MoveTo followed by a ScanLine), if the pass runs right-to-left, both the entry MoveTo and the ScanLine endpoint are shifted along X by offset_mm. Left-to-right passes are left untouched.

ParameterTypeDescription
offset_mmfloatOffset in millimeters to apply to RTL passes.
ReturnsNone
ComplexityO(n) time, O(n) space

Bidirectional scan offset correction

Bidirectional scan offset correction

apply_lead_in_out()

apply_lead_in_out(lead_in_mm: float, lead_out_mm: float) -> None

Apply lead-in and lead-out to vector contour paths.

For each contour within a VECTOR_OUTLINE section, extends the toolpath with zero-power lead-in and lead-out segments along the tangent direction at the path start and end.

ParameterTypeDescription
lead_in_mmfloatLead-in distance in millimeters.
lead_out_mmfloatLead-out distance in millimeters.
ReturnsNone
ComplexityO(n) time, O(n) space

Lead-in and lead-out paths

Lead-in and lead-out paths

apply_multipass()

apply_multipass(passes: int, z_step_down: float) -> None

Repeats the ops sequence multiple times, optionally stepping down the Z axis after each pass.

ParameterTypeDescription
passesintTotal number of passes (must be >= 1).
z_step_downfloatZ distance to move down after each pass.
ReturnsNone
ComplexityO(n * passes) time, O(n * passes) space

Multi-pass with Z stepping

Multi-pass with Z stepping

apply_overscan()

apply_overscan(distance_mm: float) -> None

Apply overscan to raster lines.

Extends raster line start/end points by distance_mm along the line direction, adding zero-power lead-in and lead-out segments for constant engraving velocity.

ParameterTypeDescription
distance_mmfloatOverscan distance in millimeters.
ReturnsNone
ComplexityO(n) time, O(n) space

Overscan applied to raster lines

Overscan applied to raster lines

apply_state()

apply_state(state: state.State) -> None

Emit the state commands needed to reach state.

Power is always emitted (default 0.0). All other fields are emitted only when set (non-None). Domain-neutral: does not decide what values to use, just emits them.

ParameterTypeDescription
statestate.StateThe target state to apply.
ReturnsNone
ComplexityO(k) time where k = number of set fields, O(k) space

apply_tab_gaps()

apply_tab_gaps(clips: Sequence[tuple[float, float, float]]) -> None

Apply holding tabs as gaps in the toolpath.

For each clip point, the closest subpath is found and a gap of the specified width is cut at the nearest point on the path. Only VECTOR_OUTLINE sections are modified.

ParameterTypeDescription
clipsSequence[tuple[float, float, float]]List of (x, y, width) tuples defining tab positions.
ReturnsNone
ComplexityO(n * k) time, O(1) space where k is the number of tab clips

Tab operations on a rectangle

Tab operations on a rectangle

apply_tab_power()

apply_tab_power(
clips: Sequence[tuple[float, float, float]],
tab_power: float,
original_power: float,
) -> None

Apply holding tabs by reducing power in tab regions.

Instead of cutting a gap, the power is lowered in the tab area so the material stays connected but weaker. Only VECTOR_OUTLINE sections are modified.

ParameterTypeDescription
clipsSequence[tuple[float, float, float]]List of (x, y, width) tuples defining tab positions.
tab_powerfloatPower level inside tab regions (0.0–1.0).
original_powerfloatNormal cutting power to restore after the tab.
ReturnsNone
ComplexityO(n * k) time, O(1) space where k is the number of tab clips

apply_transformers()

apply_transformers(
transformers: Sequence[Any],
progress_cb: Optional[Any] = None,
) -> None

Apply a batch of transformers in a single call.

The transformers list may contain any of the typed spec objects defined in raygeo.ops.transform (SmoothSpec, OptimizeSpec, MergeLinesSpec, OverscanSpec, LeadInOutSpec, MultiPassSpec, CropSpec, TabsSpec, BidirScanOffsetSpec). The transformers are sorted by execution phase (geometry refinement -> path interruption -> post-processing) and applied in order.

Raises: TypeError — If any element is not a known spec type.

Raises: RuntimeError — If the loop was cancelled.

ParameterTypeDescription
transformersSequence[Any]List of typed spec objects.
progress_cbOptional[Any] = NoneOptional callable (progress, message) that also exposes an is_cancelled() method; called before each transformer. If is_cancelled() returns True the loop aborts before the next transformer.
ReturnsNone

arc_params()

arc_params(idx: int) -> tuple[float, float, bool]

Get the arc parameters (center offset i, j, and clockwise flag).

Raises: TypeError — If the command is not an ArcTo.

ParameterTypeDescription
idxintCommand index.
Returnstuple[float, float, bool](i, j, clockwise) tuple.
ComplexityO(1) time, O(1) space

arc_to()

arc_to(
x: float,
y: float,
i: float,
j: float,
clockwise: bool = True,
z: float = 0.0,
extra: Optional[dict] = None,
) -> None

Add a circular arc to the given coordinates.

ParameterTypeDescription
xfloatEnd X coordinate.
yfloatEnd Y coordinate.
ifloatI offset from current point to arc center.
jfloatJ offset from current point to arc center.
clockwisebool = TrueWhether the arc is clockwise (default True).
zfloat = 0.0End Z coordinate (default 0.0).
extraOptional[dict] = NoneOptional dict of extra axis values.
ReturnsNone
ComplexityO(1) time, O(1) space

bezier_params()

bezier_params(
idx: int,
) -> tuple[tuple[float, float, float], tuple[float, float, float]]

Get the cubic bezier control points.

Raises: TypeError — If the command is not a BezierTo.

ParameterTypeDescription
idxintCommand index.
Returnstuple[tuple[float, float, float], tuple[float, float, float]]((c1x, c1y, c1z), (c2x, c2y, c2z)) control points.
ComplexityO(1) time, O(1) space

bezier_to()

bezier_to(
control1: tuple[float, float, float],
control2: tuple[float, float, float],
end: tuple[float, float, float],
extra: Optional[dict] = None,
) -> None

Add a cubic bezier curve to the given endpoint.

ParameterTypeDescription
control1tuple[float, float, float]First control point (x, y, z).
control2tuple[float, float, float]Second control point (x, y, z).
endtuple[float, float, float]End point (x, y, z).
extraOptional[dict] = NoneOptional dict of extra axis values.
ReturnsNone
ComplexityO(1) time, O(1) space

category()

category(idx: int) -> types.CommandCategory

Get the CommandCategory at the given index.

ParameterTypeDescription
idxintCommand index (negative = from end).
Returnstypes.CommandCategoryThe category (MOVING, STATE, or MARKER).
ComplexityO(1) time, O(1) space

clear()

clear() -> None

Remove all commands from this Ops sequence.

ParameterTypeDescription
ReturnsNone
ComplexityO(1) time, O(1) space

clip_at()

clip_at(x: float, y: float, width: float) -> bool

Clip at a single vertical swath, keeping commands that intersect the band.

ParameterTypeDescription
xfloatX coordinate of the left edge.
yfloatY coordinate (used to find the relevant segment).
widthfloatWidth of the band.
ReturnsboolTrue if any commands were kept.
ComplexityO(n) time, O(1) space

clip_ops_to_regions()

clip_ops_to_regions(
regions: Sequence[Sequence[tuple[float, float]]],
tolerance: float = 0.3,
) -> None

Clip paths using polygonal regions as boundaries; keeps what is inside.

ParameterTypeDescription
regionsSequence[Sequence[tuple[float, float]]]List of polygons, each being a list of (x, y) vertices.
tolerancefloat = 0.3Approximation tolerance (default 0.3).
ReturnsNone
ComplexityO(n * m) time, O(n) space where m is the number of polygon vertices

clip_rect()

clip_rect(rect: tuple[float, float, float, float]) -> Ops

Clip this sequence to a rectangle, keeping only commands inside.

ParameterTypeDescription
recttuple[float, float, float, float](x_min, y_min, x_max, y_max).
ReturnsOpsA new Ops sequence containing the clipped commands.
ComplexityO(n) time, O(n) space

Ops paths clipped to a rectangle

Ops paths clipped to a rectangle

clip_to_regions()

clip_to_regions(
regions: Sequence[Sequence[tuple[float, float]]],
tolerance: float = 0.3,
) -> None

Clip paths to the given polygonal regions, keeping only what is inside.

ParameterTypeDescription
regionsSequence[Sequence[tuple[float, float]]]List of polygons, each being a list of (x, y) vertices.
tolerancefloat = 0.3Approximation tolerance (default 0.3).
ReturnsNone
ComplexityO(n * m) time, O(n) space where m is the number of polygon vertices

close_path()

close_path() -> None

Close the current sub-path by adding a line back to the start.

ParameterTypeDescription
ReturnsNone
ComplexityO(1) time, O(1) space

command_type()

command_type(idx: int) -> types.CommandType

Get the CommandType at the given index.

ParameterTypeDescription
idxintCommand index (negative = from end).
Returnstypes.CommandTypeThe CommandType of the command.
ComplexityO(1) time, O(1) space

coolant()

coolant(idx: int) -> state.CoolantMode

Get the coolant mode from a SetCoolant command.

Raises: TypeError — If the command is not a SetCoolant.

ParameterTypeDescription
idxintCommand index.
Returnsstate.CoolantModeThe coolant mode.
ComplexityO(1) time, O(1) space

copy()

copy() -> Ops

Return a deep copy of this Ops sequence.

ParameterTypeDescription
ReturnsOpsA new Ops instance.
ComplexityO(n) time, O(n) space

copy_command_from()

copy_command_from(source: Ops, idx: int) -> None

Copy a single command from another Ops sequence into this one.

ParameterTypeDescription
sourceOpsThe source Ops sequence.
idxintIndex of the command to copy.
ReturnsNone
ComplexityO(1) time, O(1) space

count_cutting()

count_cutting() -> int

Return the number of cutting commands in this sequence.

Counts all LineTo, ArcTo, BezierTo, QuadraticBezierTo, and ScanLine commands.

ParameterTypeDescription
ReturnsintNumber of cutting commands.
ComplexityO(n) time, O(1) space

count_travel()

count_travel() -> int

Return the number of travel (MoveTo) commands in this sequence.

ParameterTypeDescription
ReturnsintNumber of travel commands.
ComplexityO(n) time, O(1) space

cut_distance()

cut_distance() -> float

Compute the total cutting distance (excluding travel moves).

ParameterTypeDescription
ReturnsfloatTotal cut distance in mm.
ComplexityO(n) time, O(1) space

distance()

distance() -> float

Compute the total distance of all commands.

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

distance_at()

distance_at(
idx: int,
last_point: Optional[tuple[float, float, float]] = None,
) -> float

Compute the distance traveled up to command idx.

ParameterTypeDescription
idxintCommand index.
last_pointOptional[tuple[float, float, float]] = NoneOptional starting point override.
ReturnsfloatCumulative distance.
ComplexityO(1) time, O(1) space

dump()

dump() -> None

Print a human-readable dump of all commands.

ParameterTypeDescription
ReturnsNone
ComplexityO(n) time, O(n) space

dwell()

dwell(duration_ms: float) -> None

Pause execution for a given duration.

ParameterTypeDescription
duration_msfloatDwell duration in milliseconds.
ReturnsNone
ComplexityO(1) time, O(1) space

dwell_duration()

dwell_duration(idx: int) -> float

Get the duration (milliseconds) of a Dwell command.

Raises: TypeError — If the command is not a Dwell.

ParameterTypeDescription
idxintCommand index.
ReturnsfloatDuration in milliseconds.
ComplexityO(1) time, O(1) space

endpoint()

endpoint(idx: int) -> tuple[float, float, float]

Get the endpoint coordinates of a moving command.

ParameterTypeDescription
idxintCommand index (negative = from end).
Returnstuple[float, float, float](x, y, z) tuple.
ComplexityO(1) time, O(1) space

estimate_command_times()

estimate_command_times(
default_feed_rate: float = 1000.0,
default_rapid_rate: float = 3000.0,
acceleration: float = 1000.0,
) -> list[float]

Estimate the time of each individual command in the sequence.

Returns a list with one entry per command. Moving commands (MoveTo, LineTo, ArcTo, etc.) yield their estimated execution time in seconds. Non-moving commands (state changes, markers) yield 0.0.

ParameterTypeDescription
default_feed_ratefloat = 1000.0Default feed rate (default 1000.0).
default_rapid_ratefloat = 3000.0Default rapid rate (default 3000.0).
accelerationfloat = 1000.0Acceleration value (default 1000.0).
Returnslist[float]List of estimated times in seconds, one per command.
ComplexityO(n) time, O(n) space

estimate_time()

estimate_time(
default_feed_rate: float = 1000.0,
default_rapid_rate: float = 3000.0,
acceleration: float = 1000.0,
) -> float

Estimate the total processing time for this sequence.

ParameterTypeDescription
default_feed_ratefloat = 1000.0Default feed rate (default 1000.0).
default_rapid_ratefloat = 3000.0Default rapid rate (default 3000.0).
accelerationfloat = 1000.0Acceleration value (default 1000.0).
ReturnsfloatEstimated time in seconds.
ComplexityO(n) time, O(1) space

extend()

extend(other: Optional[Ops]) -> None

Extend this Ops sequence with commands from another.

ParameterTypeDescription
otherOptional[Ops]The other Ops sequence (or None for no-op).
ReturnsNone
ComplexityO(n) time, O(n) space

extra_axes()

extra_axes(idx: int) -> Optional[dict]

Get the extra axes data for a moving command.

ParameterTypeDescription
idxintCommand index.
ReturnsOptional[dict]Dict mapping axis names to values, or None.
ComplexityO(1) time, O(1) space

flip_ops()

flip_ops() -> Ops

Reverse the order of subpaths.

ParameterTypeDescription
ReturnsOpsA new Ops with subpath order reversed.
ComplexityO(n) time, O(n) space

frequency()

frequency(idx: int) -> int

Get the frequency of a SetFrequency command.

Raises: TypeError — If the command is not a SetFrequency.

ParameterTypeDescription
idxintCommand index.
ReturnsintFrequency in Hz.
ComplexityO(1) time, O(1) space

from_dict()

@classmethod from_dict(data: dict) -> Ops

Create an Ops sequence from a dictionary.

ParameterTypeDescription
datadictDictionary as produced by to_dict.
ReturnsOpsA new Ops instance.
ComplexityO(n) time, O(n) space

from_geometry()

@classmethod from_geometry(geometry: geo.Geometry) -> Ops

Create an Ops sequence from a Geometry.

ParameterTypeDescription
geometrygeo.GeometryThe geometry to convert.
ReturnsOpsA new Ops instance.
ComplexityO(n) time, O(n) space

from_mask_lines()

from_mask_lines(
mask: Any,
pixels_per_mm: tuple[float, float],
offset_x_mm: float,
offset_y_mm: float,
line_interval_mm: float,
z: float = 0.0,
angle: float = 0.0,
scan_mode: scan.ScanMode = scan.ScanMode.SEGMENTED,
) -> Ops

Rasterise a binary mask into line-to commands (no power).

Similar to from_mask_scan but emits move-to/line-to commands with a Z offset instead of scan-to with power values. Useful for simple contour or hatch patterns.

ParameterTypeDescription
maskAny2-D binary mask array.
pixels_per_mmtuple[float, float](x, y) pixel density in px/mm.
offset_x_mmfloatGlobal X offset in mm.
offset_y_mmfloatGlobal Y offset in mm.
line_interval_mmfloatSpacing between scan lines in mm.
zfloat = 0.0Z offset for the lines in mm.
anglefloat = 0.0Scan angle in degrees.
scan_modescan.ScanMode = scan.ScanMode.SEGMENTEDScanMode.SEGMENTED or ScanMode.FULL_SWEEP.
ReturnsOpsA new Ops container.
ComplexityO(h * w + n * p) where h, w = image dimensions, n = scan lines, p = pixels per line

from_mask_scan()

from_mask_scan(
mask: Any,
pixels_per_mm: tuple[float, float],
offset_x_mm: float,
offset_y_mm: float,
line_interval_mm: float,
step_power: float = 1.0,
angle: float = 0.0,
scan_mode: scan.ScanMode = scan.ScanMode.SEGMENTED,
) -> Ops

Rasterise a binary mask into scan-to commands.

Generates scan lines covering the mask's bounding box, samples the mask along each line, and emits move-to/scan-to commands for each non-zero segment (or the full sweep).

ParameterTypeDescription
maskAny2-D binary mask array.
pixels_per_mmtuple[float, float](x, y) pixel density in px/mm.
offset_x_mmfloatGlobal X offset in mm.
offset_y_mmfloatGlobal Y offset in mm.
line_interval_mmfloatSpacing between scan lines in mm.
step_powerfloat = 1.0Power value (0-1) for exposed pixels.
anglefloat = 0.0Scan angle in degrees.
scan_modescan.ScanMode = scan.ScanMode.SEGMENTEDScanMode.SEGMENTED or ScanMode.FULL_SWEEP.
ReturnsOpsA new Ops container.
ComplexityO(h * w + n * p) where h, w = image dimensions, n = scan lines, p = pixels per line

from_multi_pass_image()

from_multi_pass_image(
gray_image: Any,
pixels_per_mm: tuple[float, float],
offset_x_mm: float,
offset_y_mm: float,
line_interval_mm: float,
num_depth_levels: int,
z_step_down: float,
angle: float = 0.0,
angle_increment: float = 0.0,
scan_mode: scan.ScanMode = scan.ScanMode.SEGMENTED,
) -> Ops

Rasterise a grayscale image as multiple Z-depth passes.

Decomposes the grayscale image into num_depth_levels layers by depth-slicing, then rasterises each layer with a progressive Z offset and optional per-pass angle increment.

ParameterTypeDescription
gray_imageAny2-D grayscale image (0 = black, 255 = white).
pixels_per_mmtuple[float, float](x, y) pixel density in px/mm.
offset_x_mmfloatGlobal X offset in mm.
offset_y_mmfloatGlobal Y offset in mm.
line_interval_mmfloatSpacing between scan lines in mm.
num_depth_levelsintNumber of depth layers to produce.
z_step_downfloatZ decrement per depth layer in mm.
anglefloat = 0.0Initial scan angle in degrees.
angle_incrementfloat = 0.0Angle added per depth layer in degrees.
scan_modescan.ScanMode = scan.ScanMode.SEGMENTEDScanMode.SEGMENTED or ScanMode.FULL_SWEEP.
ReturnsOpsA new Ops container.
ComplexityO(d * (h * w + n * p)) where d = depth levels, h, w = image dims, n = scan lines, p = pixels per line

from_numpy_arrays()

@classmethod from_numpy_arrays(arrays: dict) -> Ops

Create an Ops sequence from numpy arrays.

ParameterTypeDescription
arraysdictDictionary as produced by to_numpy_arrays.
ReturnsOpsA new Ops instance.
ComplexityO(n) time, O(n) space

from_polyline()

from_polyline(
points: Sequence[tuple[float, float, float]],
move_first: bool = True,
state: Optional[state.State] = None,
) -> Ops

Build an Ops sequence from a 3-D polyline.

When move_first is True the first point is emitted as a MoveTo and subsequent points as LineTo. When move_first is False every point is emitted as a LineTo (useful for appending a polyline to an in-progress cut).

When state is provided, its commands (power, feed rate, etc.) are applied before the polyline points.

ParameterTypeDescription
pointsSequence[tuple[float, float, float]]List of (x, y, z) tuples.
move_firstbool = TrueWhether to emit the first point as a MoveTo.
stateOptional[state.State] = NoneOptional machine state to apply before the path.
ReturnsOpsA new Ops instance.
ComplexityO(n) where n = number of points

Ops.from_polyline with move_first=True vs move_first=False

Ops.from_polyline with move_first=True vs move_first=False

from_power_modulated_image()

from_power_modulated_image(
gray_image: Any,
alpha: Any,
pixels_per_mm: tuple[float, float],
offset_x_mm: float,
offset_y_mm: float,
line_interval_mm: float,
sample_interval_mm: float,
min_power: float = 0.0,
max_power: float = 1.0,
step_power: float = 1.0,
num_power_levels: int = 256,
angle: float = 0.0,
scan_mode: scan.ScanMode = scan.ScanMode.SEGMENTED,
) -> Ops

Rasterise a grayscale image with power-modulated scans.

Samples the image along scan lines and computes per-pixel power values from the grayscale intensity and alpha channel, then emits move-to/scan-to commands with the modulated power.

ParameterTypeDescription
gray_imageAny2-D grayscale image (0 = black, 255 = white).
alphaAny2-D alpha mask (0 = transparent/no emission).
pixels_per_mmtuple[float, float](x, y) pixel density in px/mm.
offset_x_mmfloatGlobal X offset in mm.
offset_y_mmfloatGlobal Y offset in mm.
line_interval_mmfloatSpacing between scan lines in mm.
sample_interval_mmfloatOutput sample spacing in mm.
min_powerfloat = 0.0Minimum power fraction (for white pixels).
max_powerfloat = 1.0Maximum power fraction (for black pixels).
step_powerfloat = 1.0Global power multiplier.
num_power_levelsint = 256Number of quantised power levels.
anglefloat = 0.0Scan angle in degrees.
scan_modescan.ScanMode = scan.ScanMode.SEGMENTEDScanMode.SEGMENTED or ScanMode.FULL_SWEEP.
ReturnsOpsA new Ops container.
ComplexityO(h * w + n * p) where h, w = image dimensions, n = scan lines, p = pixels per line

get_frame()

get_frame(
power: Optional[float] = None,
feed_rate: Optional[float] = None,
) -> Ops

Extract a frame (first and last endpoints) from the sequence.

ParameterTypeDescription
powerOptional[float] = NoneLaser power value (0.0 to 1.0).
feed_rateOptional[float] = NoneOptional feed rate to set on the frame commands.
ReturnsOpsA new Ops containing only the frame endpoints.
ComplexityO(n) time, O(n) space

group_by_auxiliary_state()

group_by_auxiliary_state() -> list[Ops]

Group contiguous commands with the same auxiliary state into separate Ops sequences.

Groups by continuity of auxiliary state (coolant, air_assist, head_coolant) only. For full parameter-regime grouping, use OpsSection.state_blocks with StateBlockStart/StateBlockEnd markers.

ParameterTypeDescription
Returnslist[Ops]A list of Ops sequences grouped by auxiliary state continuity.
ComplexityO(n) time, O(n) space

head_coolant()

head_coolant(idx: int) -> state.HeadCoolantMode

Get the head coolant mode from a SetHeadCoolant command.

Raises: TypeError — If the command is not a SetHeadCoolant.

ParameterTypeDescription
idxintCommand index.
Returnsstate.HeadCoolantModeThe head coolant mode.
ComplexityO(1) time, O(1) space

head_uid()

head_uid(idx: int) -> str

Get the head UID from a SetHead command.

Raises: TypeError — If the command is not a SetHead.

ParameterTypeDescription
idxintCommand index.
ReturnsstrThe head identifier.
ComplexityO(1) time, O(1) space

indices_of()

indices_of(ct: types.CommandType) -> list[int]

Return all indices where the command type matches ct.

ParameterTypeDescription
cttypes.CommandTypeThe CommandType to search for.
Returnslist[int]List of matching command indices.
ComplexityO(n) time, O(n) space

inspect()

inspect(idx: int) -> CommandInfo

Return detailed information about a single command.

ParameterTypeDescription
idxintThe command index.
ReturnsCommandInfoA CommandInfo object with type, endpoint, state, axes, etc.
ComplexityO(1) time, O(1) space

is_cutting()

is_cutting(idx: int) -> bool

Check whether the command at idx is a cutting move.

ParameterTypeDescription
idxintCommand index.
ReturnsboolTrue if the command is a cutting move.
ComplexityO(1) time, O(1) space

is_empty()

is_empty() -> bool

Check if the ops sequence is empty.

ParameterTypeDescription
ReturnsboolTrue if the container is empty.
ComplexityO(1) time, O(1) space

is_marker()

is_marker(idx: int) -> bool

Check whether the command at idx is a marker command.

ParameterTypeDescription
idxintCommand index.
ReturnsboolTrue if the command is a structural marker (JobStart, LayerStart, etc.).
ComplexityO(1) time, O(1) space

is_scanline()

is_scanline(idx: int) -> bool

Check whether the command at idx is a scanline command.

ParameterTypeDescription
idxintCommand index.
ReturnsboolTrue if the command is a ScanLine power command.
ComplexityO(1) time, O(1) space

is_state()

is_state(idx: int) -> bool

Check whether the command at idx is a state command.

ParameterTypeDescription
idxintCommand index.
ReturnsboolTrue if the command modifies machine state.
ComplexityO(1) time, O(1) space

is_travel()

is_travel(idx: int) -> bool

Check whether the command at idx is a travel (non-cutting) move.

ParameterTypeDescription
idxintCommand index.
ReturnsboolTrue if the command is a travel move.
ComplexityO(1) time, O(1) space

job_end()

job_end() -> None

Mark the end of a job.

ParameterTypeDescription
ReturnsNone
ComplexityO(1) time, O(1) space

job_start()

job_start() -> None

Mark the start of a job.

ParameterTypeDescription
ReturnsNone
ComplexityO(1) time, O(1) space

layer_end()

layer_end(layer_uid: str) -> None

Mark the end of a layer.

ParameterTypeDescription
layer_uidstrThe layer identifier.
ReturnsNone
ComplexityO(1) time, O(1) space

layer_start()

layer_start(layer_uid: str) -> None

Mark the start of a layer.

ParameterTypeDescription
layer_uidstrThe layer identifier.
ReturnsNone
ComplexityO(1) time, O(1) space

layer_uid()

layer_uid(idx: int) -> str

Get the layer UID from a LayerStart or LayerEnd command.

Raises: TypeError — If the command is not a Layer command.

ParameterTypeDescription
idxintCommand index.
ReturnsstrThe layer identifier.
ComplexityO(1) time, O(1) space

len()

len() -> int

Return the number of commands.

ParameterTypeDescription
ReturnsintNumber of commands in the container.
ComplexityO(1) time, O(1) space

line_to()

line_to(
x: float,
y: float,
z: float = 0.0,
extra: Optional[dict] = None,
) -> None

Add a cutting line to the given coordinates.

ParameterTypeDescription
xfloatX coordinate.
yfloatY coordinate.
zfloat = 0.0Z coordinate (default 0.0).
extraOptional[dict] = NoneOptional dict of extra axis values.
ReturnsNone
ComplexityO(1) time, O(1) space

linearize()

linearize(idx: int, start_point: tuple[float, float, float]) -> Ops

Decompose a curved command into linear segments.

Raises: TypeError — If the command at idx is not a curve or line type.

ParameterTypeDescription
idxintIndex of the command to linearize.
start_pointtuple[float, float, float]The (x, y, z) start point of the curve.
ReturnsOpsA new Ops containing the linearized sub-commands.
ComplexityO(n) time, O(n) space

linearize_all()

linearize_all() -> None

Replace all curved commands with linear approximations in-place.

ParameterTypeDescription
ReturnsNone
ComplexityO(n) time, O(n) space

linearize_arcs()

linearize_arcs() -> None

Replace only arc commands with linear approximations.

ParameterTypeDescription
ReturnsNone
ComplexityO(n) time, O(n) space

linearize_curves()

linearize_curves() -> None

Replace only bezier and quadratic bezier curves with linear approximations.

ParameterTypeDescription
ReturnsNone
ComplexityO(n) time, O(n) space

merge_overlapping_lines()

merge_overlapping_lines(tolerance: float) -> None

Merge overlapping line segments across all paths.

Detects line segments that are collinear and overlapping and replaces the covered sub-segments with travel moves to avoid cutting the same line twice.

ParameterTypeDescription
tolerancefloatMaximum distance for considering lines collinear.
ReturnsNone
ComplexityO(n log n) average time, O(n) space

Line merging before and after

Line merging before and after

move_to()

move_to(
x: float,
y: float,
z: float = 0.0,
extra: Optional[dict] = None,
) -> None

Add a rapid (non-cutting) move to the given coordinates.

ParameterTypeDescription
xfloatX coordinate.
yfloatY coordinate.
zfloat = 0.0Z coordinate (default 0.0).
extraOptional[dict] = NoneOptional dict of extra axis values.
ReturnsNone
ComplexityO(1) time, O(1) space

ops_section_end()

ops_section_end(
section_type: types.SectionType,
*,
raster_mode: Optional[types.RasterMode] = None,
) -> None

Mark the end of an ops section.

Raises: ValueError — If section_type is RasterFill without a raster_mode,

or VectorOutline with a raster_mode.
ParameterTypeDescription
section_typetypes.SectionTypeThe type of section.
raster_modeOptional[types.RasterMode]Optional raster mode.
ReturnsNone
ComplexityO(1) time, O(1) space

ops_section_start()

ops_section_start(
section_type: types.SectionType,
workpiece_uid: str,
*,
raster_mode: Optional[types.RasterMode] = None,
) -> None

Mark the start of an ops section.

Raises: ValueError — If section_type is RasterFill without a raster_mode,

or VectorOutline with a raster_mode.
ParameterTypeDescription
section_typetypes.SectionTypeThe type of section.
workpiece_uidstrThe workpiece identifier.
raster_modeOptional[types.RasterMode]Optional raster mode.
ReturnsNone
ComplexityO(1) time, O(1) space

optimize_travel()

optimize_travel(
allow_flip: bool = True,
preserve_first: bool = False,
preserve_order: Sequence[str] = [],
progress_cb: Optional[Any] = None,
) -> None

Optimize travel distance by reordering segments.

Performs two-level optimization: workpiece-level reordering (when workpiece markers are present) and segment-level nearest-neighbor + 2-opt refinement.

ParameterTypeDescription
allow_flipbool = TrueWhether to allow flipping subpaths.
preserve_firstbool = FalseKeep the first workpiece in place.
preserve_orderSequence[str] = []Workpiece UIDs whose order to preserve.
progress_cbOptional[Any] = NoneOptional callable(progress, message).
ReturnsNone
ComplexityO(n²) average time, O(n) space

Travel path before and after optimization

Travel path before and after optimization

power()

power(idx: int) -> float

Get the power level of a SetPower command.

Raises: TypeError — If the command is not a SetPower.

ParameterTypeDescription
idxintCommand index.
ReturnsfloatPower level (0.0–1.0 typically).
ComplexityO(1) time, O(1) space

preload_state()

preload_state() -> None

Pre-compute and store the accumulated state at each moving command.

ParameterTypeDescription
ReturnsNone
ComplexityO(n) time, O(n) space

pulse_width()

pulse_width(idx: int) -> float

Get the pulse width of a SetPulseWidth command.

Raises: TypeError — If the command is not a SetPulseWidth.

ParameterTypeDescription
idxintCommand index.
ReturnsfloatPulse width in microseconds.
ComplexityO(1) time, O(1) space

quadratic_bezier_params()

quadratic_bezier_params(idx: int) -> tuple[float, float, float]

Get the quadratic bezier control point.

Raises: TypeError — If the command is not a QuadraticBezierTo.

ParameterTypeDescription
idxintCommand index.
Returnstuple[float, float, float](cx, cy, cz) control point.
ComplexityO(1) time, O(1) space

quadratic_bezier_to()

quadratic_bezier_to(
control: tuple[float, float, float],
end: tuple[float, float, float],
extra: Optional[dict] = None,
) -> None

Add a quadratic bezier curve to the given endpoint.

ParameterTypeDescription
controltuple[float, float, float]Control point (x, y, z).
endtuple[float, float, float]End point (x, y, z).
extraOptional[dict] = NoneOptional dict of extra axis values.
ReturnsNone
ComplexityO(1) time, O(1) space

rate()

rate(idx: int) -> int

Get the feed/rapid rate from a SetFeedRate or SetRapidRate command.

Raises: TypeError — If the command is not a rate command.

ParameterTypeDescription
idxintCommand index.
ReturnsintRate in mm/s.
ComplexityO(1) time, O(1) space

rect()

rect(include_travel: bool = False) -> tuple[float, float, float, float]

Compute the bounding rectangle of all commands.

ParameterTypeDescription
include_travelbool = FalseWhether to include travel moves (default False).
Returnstuple[float, float, float, float](x_min, y_min, x_max, y_max).
ComplexityO(n) time, O(1) space

replace_all()

replace_all(source: Ops) -> None

Replace all commands in this sequence with those from another.

ParameterTypeDescription
sourceOpsThe source Ops sequence.
ReturnsNone
ComplexityO(n) time, O(n) space

replace_with()

replace_with(source: Ops) -> None

Replace the internal buffer of this sequence with a copy from another.

ParameterTypeDescription
sourceOpsThe source Ops sequence.
ReturnsNone
ComplexityO(n) time, O(n) space

rotate()

rotate(angle_deg: float, cx: float, cy: float) -> None

Rotate all coordinates around a pivot point.

ParameterTypeDescription
angle_degfloatRotation angle in degrees.
cxfloatPivot X coordinate.
cyfloatPivot Y coordinate.
ReturnsNone
ComplexityO(n) time, O(1) space

scale()

scale(sx: float, sy: float, sz: float = 1.0) -> None

Scale all coordinates by the given factors.

ParameterTypeDescription
sxfloatX scale factor.
syfloatY scale factor.
szfloat = 1.0Z scale factor (default 1.0).
ReturnsNone
ComplexityO(n) time, O(1) space

scan_to()

scan_to(
x: float,
y: float,
z: float = 0.0,
power_values: Optional[Sequence[int]] = None,
extra: Optional[dict] = None,
) -> None

Add a scan-line move with per-pixel power values.

ParameterTypeDescription
xfloatEnd X coordinate.
yfloatEnd Y coordinate.
zfloat = 0.0End Z coordinate (default 0.0).
power_valuesOptional[Sequence[int]] = NoneOptional per-pixel 8-bit power values.
extraOptional[dict] = NoneOptional dict of extra axis values.
ReturnsNone
ComplexityO(1) time, O(1) space

scanline_data()

scanline_data(idx: int) -> bytes

Get the raw scanline power data for a scanline command.

ParameterTypeDescription
idxintCommand index.
ReturnsbytesRaw bytes of scanline power data.
ComplexityO(1) time, O(1) space

section_content()

section_content(section: OpsSection) -> Ops

Extract the commands belonging to a section.

ParameterTypeDescription
sectionOpsSectionThe OpsSection to extract.
ReturnsOpsA new Ops containing only the content of that section.
ComplexityO(n) time, O(n) space

section_params()

section_params(
idx: int,
) -> tuple[types.SectionType, Optional[str], Optional[types.RasterMode]]

Get the section type, optional workpiece UID, and optional raster mode from an OpsSection command.

Raises: TypeError — If the command is not an OpsSectionStart or OpsSectionEnd.

ParameterTypeDescription
idxintCommand index.
Returnstuple[types.SectionType, Optional[str], Optional[types.RasterMode]](SectionType, Optional[str], Optional[RasterMode]).
ComplexityO(1) time, O(1) space

section_ranges()

section_ranges() -> list[OpsSectionRange]

Return the section ranges of the ops as index ranges.

Similar to sections but returns contiguous index ranges instead of individual index lists.

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

sections()

sections() -> list[OpsSection]

Return the logical sections of the ops.

Sections are delimited by OpsSectionStart/OpsSectionEnd markers and group commands into vector-outline and raster-fill portions.

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

sections_by_mode()

sections_by_mode(raster_mode: types.RasterMode) -> list[OpsSection]

Return sections matching a given raster mode.

ParameterTypeDescription
raster_modetypes.RasterModeThe RasterMode to filter by.
Returnslist[OpsSection]List of matching OpsSection objects.
ComplexityO(n) time, O(n) space

sections_by_type()

sections_by_type(section_type: types.SectionType) -> list[OpsSection]

Return sections matching a given section type.

ParameterTypeDescription
section_typetypes.SectionTypeThe SectionType to filter by.
Returnslist[OpsSection]List of matching OpsSection objects.
ComplexityO(n) time, O(n) space

segment_indices()

segment_indices() -> list[list[int]]

Return index ranges for each contiguous cutting segment.

ParameterTypeDescription
Returnslist[list[int]]A list of index lists, one per segment.
ComplexityO(n) time, O(n) space

set_air_assist()

set_air_assist(mode: state.AirAssistMode) -> None

Set the air assist mode for subsequent commands.

ParameterTypeDescription
modestate.AirAssistModeAir assist mode.
ReturnsNone
ComplexityO(1) time, O(1) space

set_coolant()

set_coolant(mode: state.CoolantMode) -> None

Set the coolant mode for subsequent commands.

ParameterTypeDescription
modestate.CoolantModeCoolant mode.
ReturnsNone
ComplexityO(1) time, O(1) space

set_feed_rate()

set_feed_rate(feed_rate: float) -> None

Set the feed rate for subsequent commands.

ParameterTypeDescription
feed_ratefloatFeed rate in units per second.
ReturnsNone
ComplexityO(1) time, O(1) space

set_frequency()

set_frequency(frequency: int) -> None

Set the laser pulse frequency.

ParameterTypeDescription
frequencyintFrequency in Hz.
ReturnsNone
ComplexityO(1) time, O(1) space

set_head()

set_head(head_uid: str) -> None

Switch to a specific head by UID.

ParameterTypeDescription
head_uidstrThe head identifier.
ReturnsNone
ComplexityO(1) time, O(1) space

set_head_coolant()

set_head_coolant(mode: state.HeadCoolantMode) -> None

Set the head coolant mode for subsequent commands.

ParameterTypeDescription
modestate.HeadCoolantModeHead coolant mode.
ReturnsNone
ComplexityO(1) time, O(1) space

set_power()

set_power(power: float) -> None

Set the cutting power for subsequent commands.

ParameterTypeDescription
powerfloatPower level (0.0–1.0).
ReturnsNone
ComplexityO(1) time, O(1) space

set_pulse_width()

set_pulse_width(pulse_width: float) -> None

Set the laser pulse width.

ParameterTypeDescription
pulse_widthfloatPulse width in microseconds.
ReturnsNone
ComplexityO(1) time, O(1) space

set_rapid_rate()

set_rapid_rate(rapid_rate: float) -> None

Set the rapid (traverse) rate for subsequent commands.

ParameterTypeDescription
rapid_ratefloatRapid rate in units per second.
ReturnsNone
ComplexityO(1) time, O(1) space

set_spindle_rpm()

set_spindle_rpm(rpm: int) -> None

Set the spindle RPM for subsequent commands.

ParameterTypeDescription
rpmintSpindle RPM.
ReturnsNone
ComplexityO(1) time, O(1) space

set_state_at()

set_state_at(idx: int, state: state.State) -> None

Overwrite the state at a specific command index.

ParameterTypeDescription
idxintThe command index.
statestate.StateThe new state.
ReturnsNone
ComplexityO(1) time, O(1) space

set_state_on_moving()

set_state_on_moving(state: state.State) -> None

Apply a state to all moving commands without an explicit state.

ParameterTypeDescription
statestate.StateThe state to apply.
ReturnsNone
ComplexityO(n) time, O(1) space

smooth()

smooth(amount: int, corner_angle_threshold: float) -> None

Smooth all line-only segments using a Gaussian filter.

Arcs are linearized first. Segments containing curves are transferred unchanged. The smoothing operates in place.

ParameterTypeDescription
amountintSmoothing strength (0-100). 0 is a no-op.
corner_angle_thresholdfloatCorners with an internal angle (in degrees) smaller than this are preserved.
ReturnsNone
ComplexityO(n * k) time, O(n) space where k is the kernel size

Gaussian smoothing applied to a square path

Gaussian smoothing applied to a square path

spindle_rpm()

spindle_rpm(idx: int) -> int

Get the spindle RPM from a SetSpindleRpm command.

Raises: TypeError — If the command is not a SetSpindleRpm.

ParameterTypeDescription
idxintCommand index.
ReturnsintSpindle RPM.
ComplexityO(1) time, O(1) space

split_at()

split_at(command_type: Any) -> list[Ops]

Split the sequence at paired markers of the given type.

Returns a list of Ops sequences. Each matched start/end marker pair yields one Ops containing the markers and their content. Commands that fall outside any pair are returned as additional Ops segments, so concatenating all returned sequences reproduces the original.

Raises: ValueError — If command_type is not a supported start marker.

ParameterTypeDescription
command_typeAnyCommandType.LAYER_START, WORKPIECE_START, OPS_SECTION_START, or JOB_START.
Returnslist[Ops]A list of Ops sequences.
ComplexityO(n) time, O(n) space

split_into_subpaths()

split_into_subpaths() -> list[Ops]

Split this Ops sequence into separate subpaths.

ParameterTypeDescription
Returnslist[Ops]A list of Ops sequences, one per subpath.
ComplexityO(n) time, O(n) space

state()

state(idx: int) -> Optional[state.State]

Get the machine state stored on a command (if available).

ParameterTypeDescription
idxintCommand index.
ReturnsOptional[state.State]The State at that index, or None.
ComplexityO(1) time, O(1) space

state_at()

state_at(idx: int) -> state.State

Return the accumulated state at a given command index.

Raises: IndexError — If the index is out of range.

ParameterTypeDescription
idxintThe command index.
Returnsstate.StateThe state at that point.
ComplexityO(1) time, O(1) space

state_block_end()

state_block_end() -> None

Mark the end of a state block.

ParameterTypeDescription
ReturnsNone
ComplexityO(1) time, O(1) space

state_block_start()

state_block_start(name: Optional[str]) -> None

Mark the start of a state block.

ParameterTypeDescription
nameOptional[str]Optional block name.
ReturnsNone
ComplexityO(1) time, O(1) space

state_blocks()

state_blocks() -> list[types.StateBlock]

Return all state blocks across all sections.

Raises: RuntimeError — If state block nesting is invalid.

ParameterTypeDescription
Returnslist[types.StateBlock]List of StateBlock objects.
ComplexityO(n) time, O(n) space

sub_ops()

sub_ops(indices: Sequence[int]) -> Ops

Extract a subset of commands by index.

ParameterTypeDescription
indicesSequence[int]List of command indices to extract.
ReturnsOpsA new Ops sequence containing only the specified commands.
ComplexityO(n) time, O(n) space

subpath_indices()

subpath_indices() -> list[list[int]]

Return index ranges for each subpath.

ParameterTypeDescription
Returnslist[list[int]]A list of index lists, one per subpath.
ComplexityO(n) time, O(n) space

subtract_regions()

subtract_regions(regions: Sequence[Sequence[tuple[float, float]]]) -> None

Subtract polygonal regions from the cutting paths.

ParameterTypeDescription
regionsSequence[Sequence[tuple[float, float]]]List of polygons, each being a list of (x, y) vertices.
ReturnsNone
ComplexityO(n * m) time, O(n) space where m is the number of polygon vertices

to_dict()

to_dict() -> dict

Serialize this Ops sequence to a dict suitable for JSON export.

ParameterTypeDescription
ReturnsdictA Python dict representation.
ComplexityO(n) time, O(n) space

to_gcode()

to_gcode(dialect: convert.GcodeDialectSpec, context_dict: dict) -> dict

Encode this Ops sequence into G-code text.

Takes a typed dialect specification and an encoding context as a plain dict (JSON-serialisable). Returns a dict with the G-code text and bidirectional op-to-line index maps.

Raises: ValueError — If deserialization fails.

ParameterTypeDescription
dialectconvert.GcodeDialectSpecA raygeo.ops.convert.GcodeDialectSpec instance.
context_dictdictJSON-serialisable dict matching the Rust EncodeContext schema.
Returnsdict{"text": str, "op_to_machine_code": {int: [int]}, "machine_code_to_op": {int: int}}

to_geometry()

to_geometry() -> geo.Geometry

Convert this Ops sequence back into a Geometry.

ParameterTypeDescription
Returnsgeo.GeometryA Geometry representing the same paths.
ComplexityO(n) time, O(n) space

to_numpy_arrays()

to_numpy_arrays() -> dict

Serialize this Ops sequence to numpy arrays.

ParameterTypeDescription
ReturnsdictA Python dict of numpy arrays.
ComplexityO(n) time, O(n) space

to_vertex_arrays()

to_vertex_arrays() -> Any

Encode all commands into GPU-friendly vertex arrays.

Returns four flat numpy arrays: (powered_vertices, powered_colors, travel_vertices, zero_power_vertices).

Powered vertices and colors are paired (2 vertices + 2 colors per segment). Travel and zero-power vertices are also paired (2 vertices per segment). All vertex data is 3-component (x, y, z); colors are 4-component (r, g, b, a).

ParameterTypeDescription
ReturnsAnyTuple of (powered_vertices[N,3], powered_colors[N,4], travel_vertices[M,3], zero_power_vertices[K,3]) as float32 arrays.
ComplexityO(n) time, O(n) space

transfer_command_from()

transfer_command_from(source: Ops, idx: int) -> None

Transfer (move) a single command from another Ops sequence into this one.

ParameterTypeDescription
sourceOpsThe source Ops sequence.
idxintIndex of the command to transfer.
ReturnsNone
ComplexityO(1) time, O(1) space

transform()

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

Apply a 4x4 affine transformation matrix to all geometry.

See geo.types.TransformMatrix for the matrix layout.

ParameterTypeDescription
matrixgeo.types.TransformMatrixA 4x4 affine transformation matrix.
ReturnsNone
ComplexityO(n) time, O(n) space

transform_layers()

transform_layers(callback: Any) -> None

Transform each layer by calling a Python callback with the layer UID and ops.

The callback receives (layer_uid: str, layer_ops: Ops) and should mutate the layer_ops in place.

ParameterTypeDescription
callbackAnyA callable accepting (layer_uid, layer_ops).
ReturnsNone
ComplexityO(n) time, O(n) space

transform_moving()

transform_moving(on_endpoint: Any, on_aux_point: Optional[Any] = None) -> None

Transform moving commands by calling Python callbacks on each endpoint and aux point.

The on_endpoint callback receives (endpoint, extra_axes) and should mutate the endpoint list in-place. The optional on_aux_point callback receives control points for curve commands.

ParameterTypeDescription
on_endpointAnyCallable (endpoint, extra_axes) -> None.
on_aux_pointOptional[Any] = NoneOptional callable (point,) -> None for curve control points.
ReturnsNone
ComplexityO(n) time, O(1) space

translate()

translate(dx: float, dy: float, dz: float = 0.0) -> None

Translate all moving commands by the given offset.

ParameterTypeDescription
dxfloatX offset.
dyfloatY offset.
dzfloat = 0.0Z offset (default 0.0).
ReturnsNone
ComplexityO(n) time, O(1) space

translate_layers()

translate_layers(
default_offset: tuple[float, float, float],
layer_offsets: Optional[dict] = None,
) -> None

Translate each layer by its own offset, with a default fallback.

ParameterTypeDescription
default_offsettuple[float, float, float]The (x, y, z) offset for layers not listed in layer_offsets.
layer_offsetsOptional[dict] = NoneOptional dict mapping layer UIDs to (x, y, z) offsets.
ReturnsNone
ComplexityO(n) time, O(1) space

without_state()

without_state() -> Ops

Return a copy with all state commands removed.

ParameterTypeDescription
ReturnsOpsA new Ops containing only moving commands.
ComplexityO(n) time, O(n) space

workpiece_end()

workpiece_end(workpiece_uid: str) -> None

Mark the end of a workpiece.

ParameterTypeDescription
workpiece_uidstrThe workpiece identifier.
ReturnsNone
ComplexityO(1) time, O(1) space

workpiece_start()

workpiece_start(workpiece_uid: str) -> None

Mark the start of a workpiece.

ParameterTypeDescription
workpiece_uidstrThe workpiece identifier.
ReturnsNone
ComplexityO(1) time, O(1) space

workpiece_uid()

workpiece_uid(idx: int) -> str

Get the workpiece UID from a WorkpieceStart or WorkpieceEnd command.

Raises: TypeError — If the command is not a Workpiece command.

ParameterTypeDescription
idxintCommand index.
ReturnsstrThe workpiece identifier.
ComplexityO(1) time, O(1) space

OpsSection

A section of operations parsed into marker and content index groups.

Produced by Ops.sections when splitting an Ops sequence into logical sections based on OpsSectionStart/OpsSectionEnd markers.

content_indices

content_indices: list[int]

Indices of the content commands belonging to this section.

marker_indices

marker_indices: list[int]

Indices of the section-marker commands (start/end) for this section.

raster_mode

raster_mode: Optional[types.RasterMode]

The raster mode of this section, if any.

section_type

section_type: Optional[types.SectionType]

The type of this section (VectorOutline or RasterFill), if any.

content()

content(ops: Ops) -> Ops

Extract the content commands of this section from an Ops sequence.

ParameterTypeDescription
opsOpsThe Ops sequence containing this section.
ReturnsOpsA new Ops containing only the content of this section.
ComplexityO(n) time, O(n) space

state_block_content()

state_block_content(ops: Ops, block: types.StateBlock) -> Ops

Extract a specific state block's content as Ops.

ParameterTypeDescription
opsOpsThe parent Ops sequence.
blocktypes.StateBlockThe StateBlock to extract.
ReturnsOpsA new Ops containing only the block's content.
ComplexityO(n) time, O(n) space

state_blocks()

state_blocks(ops: Ops) -> list[types.StateBlock]

Return the state blocks within this section.

Raises: RuntimeError — If state block nesting is invalid.

ParameterTypeDescription
opsOpsThe parent Ops sequence.
Returnslist[types.StateBlock]List of StateBlock objects.
ComplexityO(n) time, O(n) space

state_blocks_by_name()

state_blocks_by_name(ops: Ops, pattern: str) -> list[types.StateBlock]

Find state blocks by name pattern (* prefix match or exact).

Raises: RuntimeError — If state block nesting is invalid.

ParameterTypeDescription
opsOpsThe parent Ops sequence.
patternstrName pattern ("cell-*" for prefix, "labels" for exact).
Returnslist[types.StateBlock]List of matching StateBlock objects.
ComplexityO(n) time, O(n) space

OpsSectionRange

A contiguous range of indices that belong to a section.

Similar to OpsSection but stores start/end index ranges instead of individual index lists. Produced by Ops.section_ranges.

content_indices

content_indices: list[int]

Starting index of the content within this section range.

marker_indices

marker_indices: list[int]

Indices of the section-marker commands that bracket this range.

raster_mode

raster_mode: Optional[types.RasterMode]

The raster mode of this section range, if any.

section_type

section_type: Optional[types.SectionType]

The type of this section range (VectorOutline or RasterFill), if any.

content()

content(ops: Ops) -> Ops

Extract the content commands of this section range from an Ops sequence.

Extract the content commands of this section range from an Ops sequence.

ParameterTypeDescription
opsOpsThe Ops sequence containing this section.
ReturnsOpsA new Ops containing only the content of this section range.
ComplexityO(n) time, O(n) space