svg_path/degeneracy
Degenerate and nearly-degenerate geometry cleanup.
Types
Errors returned by degeneracy cleanup helpers.
pub type Error {
InvalidTolerance(tolerance: Float)
PathError(error: svg_path.Error)
ConvexHullError(error: convex_hull.Error)
}
Constructors
-
InvalidTolerance(tolerance: Float)The linearization tolerance must be finite and non-negative.
-
PathError(error: svg_path.Error)An underlying path operation failed.
-
ConvexHullError(error: convex_hull.Error)Convex-hull construction failed while normalizing degenerate segments.
Values
pub fn normalize_degenerate_segments(
subpath: svg_path.Subpath,
tolerance tolerance: Float,
) -> Result(svg_path.Subpath, Error)
Replace maximal contiguous line-degenerate windows in a subpath.
Each selected window preserves its start and end and the two longitudinal
support extrema, ordered by their occurrence in the source. Intermediate
local reversals need not be retained. Windows are considered from left to
right. Their exact curve-preserving convex hull is
grown one segment at a time, and the largest prefix certified to fit in a
strip of the requested width is selected first. A 0.0 tolerance collapses
a window only when its strip width is exactly zero.
pub fn segment_linearize_if_degenerate(
segment: svg_path.Segment,
tolerance tolerance: Float,
) -> Result(option.Option(List(svg_path.Segment)), Error)
Detect a curve that is contained in an absolute-width strip and replace it with ordered line segments when possible.
tolerance is the maximum distance from the replacement line or lines to
the curve, in path coordinate units. Ok(None) means that the segment is
not line-degenerate. Ok(Some(lines)) preserves collinear backtracking;
Some([]) represents a curve with no movement. Lines themselves return
Ok(None). The tolerance must be finite and non-negative; a tolerance of
0.0 collapses the segment only when it lies exactly on a line strip of
width zero.
pub fn subpath_linearize_if_degenerate(
subpath: svg_path.Subpath,
tolerance tolerance: Float,
) -> Result(option.Option(List(svg_path.Segment)), Error)
Detect whether an entire subpath fits inside one absolute-width line strip.
Ok(Some(lines)) returns an ordered line replacement, preserving the
subpath’s flattened traversal and backtracking. Ok(None) means that the
subpath is not line-degenerate. Empty subpaths return Ok(Some([])).