svg_path/csg
Boolean operations on filled SVG paths.
The using fill rule is part of the operation: both input paths are first
interpreted as filled sets under that rule, the Boolean operation is
applied to those sets, and the returned path fills as the resulting set
under the same rule. For Nonzero, CSG preserves contour-depth level-set
boundaries inside the resulting set rather than collapsing the result to a
minimal filled outline.
Open subpaths are treated as implicitly closed for fill purposes. Empty paths and move-only subpaths contribute no filled area.
The implementation preserves original segment types where possible. It
splits original path segments at point intersections, classifies each
resulting directed piece by the output contour depth on its left and right
sides, and assembles closed subpaths from those retained pieces. A depth
jump larger than one emits repeated pieces so the returned path can express
the same Nonzero field. Result contour orientation is normalized after
assembly: fill-forced boundaries keep the direction required by the output
winding field, and retained internal Nonzero level contours use clockwise
orientation when their direction is not forced by the fill. Curved segments
remain curved between real encounters; only implicit closing edges are added
as lines. Coincident line edges are split at their overlap endpoints and
resolved by deterministic boundary ownership rules.
Types
Options for path CSG operations.
pub type Options {
Options(
intersection: intersections.IntersectionOptions,
containment: svg_path.ContainmentOptions,
tolerance: Float,
)
}
Constructors
-
Options( intersection: intersections.IntersectionOptions, containment: svg_path.ContainmentOptions, tolerance: Float, )
Values
pub fn difference(
left: svg_path.Path,
minus right: svg_path.Path,
using fill_rule: svg_path.FillRule,
) -> Result(svg_path.Path, svg_path.Error)
Return a path whose fill is left minus right under using.
pub fn difference_with(
left: svg_path.Path,
minus right: svg_path.Path,
using fill_rule: svg_path.FillRule,
options options: Options,
) -> Result(svg_path.Path, svg_path.Error)
Return a path whose fill is left minus right using explicit options.
pub fn intersection(
left: svg_path.Path,
right: svg_path.Path,
using fill_rule: svg_path.FillRule,
) -> Result(svg_path.Path, svg_path.Error)
Return a path whose fill is the intersection of two input paths under
using.
pub fn intersection_with(
left: svg_path.Path,
right: svg_path.Path,
using fill_rule: svg_path.FillRule,
options options: Options,
) -> Result(svg_path.Path, svg_path.Error)
Return a path whose fill is the intersection of two input paths using explicit options.
pub fn simplify_nonzero_output(
path: svg_path.Path,
) -> Result(svg_path.Path, svg_path.Error)
Remove internal contour-depth boundaries from a CSG result while preserving
its Nonzero filled set.
CSG operations intentionally preserve Nonzero contour-depth level sets.
This helper is a post-processing convenience for callers who want the
simpler filled-set boundary instead.
pub fn simplify_nonzero_output_with(
path: svg_path.Path,
options options: Options,
) -> Result(svg_path.Path, svg_path.Error)
Remove internal contour-depth boundaries from a CSG result using explicit options.
pub fn union(
left: svg_path.Path,
right: svg_path.Path,
using fill_rule: svg_path.FillRule,
) -> Result(svg_path.Path, svg_path.Error)
Return a path whose fill is the union of two input paths under using.
pub fn union_with(
left: svg_path.Path,
right: svg_path.Path,
using fill_rule: svg_path.FillRule,
options options: Options,
) -> Result(svg_path.Path, svg_path.Error)
Return a path whose fill is the union of two input paths using explicit options.