pub fn fit_polyline(
points: &[Vec3],
tolerance: f64,
maximum_points: usize,
local_interpolation: bool,
) -> Result<PolylineFit, String>Expand description
Interpolate a curve through a polyline and REFINE it until the curve itself
is within tolerance of that polyline.
tolerance is the deviation the RESULT must reach; maximum_points is
where the station ladder STARTS, not where it ends. Rung zero is exactly
the fit this routine returned before the ladder existed — same
simplification, same conditioning, same decimation, same parameters — so a
section that already met its tolerance returns the identical curve, to the
bit. Only a MEASURED miss spends anything: the budget doubles, each rung is
measured, and the best is kept, up to MAX_FIT_STATIONS or the input’s
own station count.
Where it cannot get there it says so, in PolylineFit::report, rather
than returning silently — the interpolant becomes a trim boundary and every
mass property downstream is read off it, so “within a step of the marched
points” is not good enough. This is the same contract
offset::fold_locus::fit_locus_pcurve already keeps for a traced locus
and crate::PcurveFitReport for a pcurve.
THE LANE IS ALSO MEASURED. local_interpolation is the lane the ladder
STARTS in, not the lane that is returned: where the caller’s own ladder ends
unmet, the other lane’s ladder is run on the same input and the better
MEASURED result is returned. Neither lane wins in general and the two fail
differently — measured on the exact-circle bench and the kink bench below:
- on a SMOOTH section the global cubic converges at h⁴ and the local lane at
h², so at the 96 stations
offset_shellasks for the local lane delivers 286 control points 2.179e-3 from the input and the global one delivers 96 at 3.700e-6 — 589x better with a third of the controls, and the local lane cannot reach 1e-7 there at any station count; - at a KINK — a rim through a corner — the local lane’s monotonicity limiter holds the corner where the global cubic rings across it: 8.377e-2 against 4.095e-1 at the same 32 stations, 4.9x.
So the flag is a caller’s PREFERENCE — which ladder is paid for first — and
never a decision about which curve is delivered. offset_shell asks for the
global lane since 2026-09-13 because its sections are mostly smooth and the
global rungs are three times cheaper per station; its corner sections reach
the local lane through this fallback instead. This is the
same shape as degenerate_apex_frustum’s branch selection in
geometry/analytic_surface/intersect.rs: a deterministic choice between two
constructions on their measured error, never a tolerance, and it can only
return the more accurate of the two.
Escape hatch: BREP_POLYLINE_FIT_REFINE=0 fits rung zero alone, for
bisecting a moved number against the pre-ladder tree.
The locus fitter is in crate::offset::fold_locus.