svg_path/curvature
Curvature helpers for offset construction and diagnostics.
This module is intentionally more experimental than the root svg_path
API. Offset code needs curvature values, cusp residuals, and near-cusp band
classifiers before we know which helpers deserve a stable public surface.
Types
A sampled interval where the signed radius of curvature is close to a target offset distance.
pub type CurvatureBand {
CurvatureBand(from: Float, to: Float)
}
Constructors
-
CurvatureBand(from: Float, to: Float)
First and second derivative data at a segment parameter.
pub type Derivatives {
Derivatives(first: svg_path.Point, second: svg_path.Point)
}
Constructors
-
Derivatives(first: svg_path.Point, second: svg_path.Point)
Options for sampled cusp/root/band discovery.
pub type Options {
Options(tolerance: Float, samples: Int, max_depth: Int)
}
Constructors
-
Options(tolerance: Float, samples: Int, max_depth: Int)Arguments
- tolerance
-
Numeric tolerance for roots and interval widths in parameter space.
- samples
-
Initial number of sample windows on
0.0..1.0. - max_depth
-
Maximum bisection/subdivision depth.
Values
pub fn segment_derivatives(
segment: svg_path.Segment,
at t: Float,
) -> Result(Derivatives, svg_path.Error)
Return first and second parameter derivatives for a segment at t.
Lines return zero second derivative. Arcs are converted to cubic Bezier pieces only as a fallback for now; callers that need exact ellipse curvature should use a later arc-specialized helper.
pub fn segment_inflection_parameters(
segment: svg_path.Segment,
options options: Options,
) -> Result(List(Float), Nil)
Sample and refine interior inflection parameters.
This solves cross(p'(t), p''(t)) = 0. Lines and identically flat pieces
return an empty list. Roots at the segment endpoints are filtered out.
pub fn segment_right_normal_curvature(
segment: svg_path.Segment,
at t: Float,
) -> Result(Float, Nil)
Return right-normal signed curvature at a segment parameter.
Positive values mean the curve bends toward the right normal used by
svg_path/offset; negative values mean it bends toward the left normal.
Lines return 0.0. Degenerate zero-speed parameters return an error.
pub fn segment_right_normal_cusp_parameters(
segment: svg_path.Segment,
distance distance: Float,
options options: Options,
) -> Result(List(Float), Nil)
Sample and refine parameters where right-normal signed radius equals
distance.
This is conservative root discovery over the cusp residual. It detects sign-changing roots and exact sampled roots. Repeated roots that do not change sign can be added later using polynomial candidates.
pub fn segment_right_normal_radius(
segment: svg_path.Segment,
at t: Float,
) -> Result(Float, Nil)
Return right-normal signed radius of curvature at a segment parameter.
Lines and inflection points return Error(Nil) because their radius is
infinite. Degenerate zero-speed parameters also return Error(Nil).
pub fn segment_right_normal_radius_close_bands(
segment: svg_path.Segment,
distance distance: Float,
margin margin: Float,
options options: Options,
) -> Result(List(CurvatureBand), Nil)
Sample intervals where right-normal signed radius is within margin of
distance.
This is a conservative sampled classifier. Adjacent close samples are merged into parameter bands. It is intended as a first staging helper for offset stalled-run detection, not as a final exact algebraic interval solver.
pub fn segment_right_normal_radius_close_to(
segment: svg_path.Segment,
distance distance: Float,
margin margin: Float,
at t: Float,
) -> Result(Bool, Nil)
Return abs(R_right(t) - distance) < margin without evaluating R_right(t)
directly.
Algebraically, for finite nonzero curvature this is equivalent to:
abs(|p'|^3 + distance * cross(p', p'')) < margin * abs(cross(p', p'')).