Crate lyon_bezier [] [src]

Bézier curve related maths and tools.

This crate implements simple 2d quadratic and cubic bézier math and an efficient flattening algorithm on top of eulcid.

Flattening

Flattening is the action of approximating a curve with a succession of line segments.

The flattening algorithm implemented in this crate is based on the paper Fast, Precise Flattening of Cubic Bézier Segment Offset Curves. It tends to produce a better approximations than the usual recursive subdivision approach (or in other words, it generates less segments for a given tolerance threshold).

The tolerance threshold taken as input by the flattening algorithms corresponds to the maximum distance between the curve and its linear approximation. The smaller the tolerance is, the more precise the approximation and the more segments are generated. This value is typically chosen in function of the zoom level.

The figure above shows a close up on a curve (the dotted line) and its linear approximation (the black segments). The tolerance threshold is represented by the light green area and the orange arrow.

Structs

CubicBezierSegment

A 2d curve segment defined by four points: the beginning of the segment, two control points and the end of the segment.

CubicFlatteningIter

An iterator over a cubic bezier segment that yields line segments approximating the curve for a given approximation threshold.

QuadraticBezierSegment

A 2d curve segment defined by three points: the beginning of the segment, a control point and the end of the segment.

QuadraticFlatteningIter

An iterator over a quadratic bézier segment that yields line segments approximating the curve for a given approximation threshold.

Functions

cubic_to_quadratic

Approximate a cubic bezier segment with a sequence of quadratic bezier segments.

Type Definitions

Point

Alias for euclid::Point2D<f32>.

Vec2

Alias for euclid::Point2D<f32>.