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.

Modules

utils

Structs

Arc
ArcFlags

Flag parameters for arcs as described by the SVG specification.

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.

Line
LineSegment
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.

SvgArc
Triangle

Functions

cubic_to_quadratic

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

Type Definitions

Point

Alias for euclid::Point2D<f32>.

Radians
Rect

Alias for euclid::Rect<f32>

Size

Alias for euclid::Size2D<f32>.

Transform2D

Alias for euclid::Transform2D<f32>

UpToTwo
Vec2

Alias for euclid::Point2D<f32>.