Skip to main content

Module biarc

Module biarc 

Source
Expand description

Biarc fitting: a sampled outline in, a G1-continuous chain of circular arcs out (ADR-0098).

This is the half of ADR-0098 that makes the cheap primitive enough. A sampled polyline shows its joints because it is only C0 — the tangent jumps at every vertex, and the eye reads a tangent discontinuity as a corner however fine the sampling. A chain built here is G1: consecutive pieces share both an endpoint and a tangent direction there, by construction, so the same handful of pieces that read as a faceted polygon read as a drawn curve. The approximation error shows up as a curve slightly in the wrong place rather than as a visible vertex.

A corner in the source outline stays a corner. The fit breaks its chain wherever consecutive chords turn by more than CORNER_TURN, because a trefoil’s three cusps and a diamond’s four vertices are the figure, not sampling artefacts, and a run that is all corners comes back as the polyline it was given.

That is not enough to leave a Maurer chord web alone, and the measurement says so. A d = 29 walk is about 90 % corners — but the other 10 % are runs of two and three chords that the fit happily replaces with arcs, which would redraw a figure whose chords are the figure. So the decision of whether a walk is a curve at all is the caller’s, taken from corner_fraction before the fit is ever called; see curves::maurer_rose_pieces.

Pure: no clock, no randomness, no global state, so the same outline always yields the same chain (the determinism rule). Allocation-free into a caller-preallocated out, because parametric_curve resamples every frame.