Skip to main content

Module path

Module path 

Source
Expand description

Path operations: boolean combinations, stroke-to-path, arc-length measurement and offset / inset.

Every operation here is build-time and IR-neutral: it takes a BezPath and returns a new BezPath, never touching the scene graph (crate::scene) or a backend. Feed the result to crate::builder::Ctx::path and the SVG and the raster backend render it identically — there is nothing per-backend to keep in sync.

use lievisual::{BoolOp, PathOps, Rect, Shape};

let a = Rect::new(0.0, 0.0, 10.0, 10.0).to_path(0.01);
let b = Rect::new(5.0, 5.0, 15.0, 15.0).to_path(0.01);
assert!((a.union(&b).area() - 175.0).abs() < 0.5);

// Subtract an inner rect → a ring with a real hole (two contours).
let ring = a.difference(&Rect::new(3.0, 3.0, 7.0, 7.0).to_path(0.01));
assert!((ring.area() - 84.0).abs() < 0.5);

§Boolean ops need a polygon engine

kurbo 0.13 no longer ships BooleanOps, so PathOps::boolean delegates to i_overlay (pure Rust, no unsafe, no threading by default). Curves are flattened into polygons first (see tolerance / DEFAULT_TOLERANCE) and the result is polygonal: a union of two circles comes back as a dense polyline, not as arcs. Raise the tolerance to emit fewer, coarser nodes; lower it for smoother output.

Filling uses the non-zero rule, which is also the default of both backends, so contours that come back as holes (opposite winding) render as holes everywhere.

§Offset / inset

PathOps::offset and PathOps::inset are the morphological dilation and erosion by a disk (Minkowski sum / difference), built from stroke-to-path plus a boolean op. They treat the path as a filled region (an open path is closed first) and they round convex corners, exactly as a disk-shaped structuring element does. That is the usual “grow / shrink a shape” semantic; for an exact constant-width band around a curve use PathOps::outline instead.

Structs§

PathSample
A position sampled along a path by PathOps::point_at_length.

Enums§

BoolOp
Which boolean combination PathOps::boolean should compute.

Constants§

DEFAULT_TOLERANCE
Default flattening / stroking tolerance in user units, used by the convenience PathOps::union and friends, and by the crate::builder path helpers.

Traits§

PathOps
Path algorithms on any BezPath: boolean combinations, stroke-to-path, measurement, and offset / inset.