Module kurbo::simplify

source ·
Expand description

Simplification of a Bézier path.

This module is currently experimental.

The methods in this module create a SimplifyBezPath object, which can then be fed to fit_to_bezpath or fit_to_bezpath_opt depending on the degree of optimization desired.

The implementation uses a number of techniques to achieve high performance and accuracy. The parameter (generally written t) evenly divides the curve segments in the original, so sampling can be done in constant time. The derivatives are computed analytically, as that is straightforward with Béziers.

The areas and moments are computed analytically (using Green’s theorem), and the prefix sum is stored. Thus, it is possible to analytically compute the area and moment of any subdivision of the curve, also in constant time, by taking the difference of two stored prefix sum values, then fixing up the subsegments.

A current limitation (hoped to be addressed in the future) is that non-regular cubic segments may have tangents computed incorrectly. This can easily happen, for example when setting a control point equal to an endpoint.

In addition, this method does not report corners (adjoining segments where the tangents are not continuous). It is not clear whether it’s best to handle such cases here, or in client code.

Structs