fitCubicBeziers
Fits a polyline of points with one or more tangent-continuous cubic Beziers, splitting wherever a single piece can't stay within errorTolerance. Compared to the plain least-squares version:
Tangent directions are estimated once, globally, and pieces meeting at a shared point always use the same direction there - no visible kinks at split boundaries.
The split location is chosen near the worst-fitting point, but biased toward the flattest (lowest local turn angle) point within curvatureSearchRadius of it - splitting where the data is already nearly straight makes any residual join even less noticeable.
Parameters
the points to fit, in order along the curve
max allowed distance between any input point and the fitted curve
recursion limit; caps output at 2^maxDepth pieces
don't split a piece with fewer points than this
how many neighbors on each side to use when estimating a point's tangent
if true, nudges the split point toward lower local curvature
how far (in points) to search for a flatter split point