Module lyon::geom[]

Simple 2D geometric primitives on top of euclid.

Overview.

This crate implements some of the maths to work with:

  • lines and line segments,
  • quadratic and cubic bézier curves,
  • elliptic arcs,
  • triangles.

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

arc

Elliptic arc related maths and tools.

arrayvec

arrayvec provides the types ArrayVec and ArrayString: array-backed vector and string types, which store their contents inline.

cubic_bezier
cubic_to_quadratic
euclid

A collection of strongly typed math tools for computer graphics with an inclination towards 2d graphics and layout.

math

Basic types that are used everywhere. Most other lyon crates reexport them.

quadratic_bezier
traits
utils

Structs

Line

An infinite line defined by a point and a vector.

LineEquation

A line defined by the equation a * x + b * y + c = 0; a * a + b * b = 1.

LineSegment

A linear segment.

Monotonic

A x and y monotonic curve segment, for example Monotonic<QuadraticBezierSegment>.

Triangle

A 2D triangle defined by three points a, b and c.