Expand description
Tessellation of 2D fill and stroke operations.
This crate is reexported in lyon.
§Overview
The most interesting types and traits of this crate are:
- FillTessellator - Tessellator for complex path fill operations.
- StrokeTessellator - Tessellator for complex path stroke operations.
GeometryBuilder- (See the documentation of the geometry_builder module) which the above two are built on. This trait provides an interface for types that help with building and assembling the vertices and triangles that form the tessellation, usually in the form of arbitrary vertex and index buffers.
§The tessellation pipeline
The figure above shows a simplified summary of each step of the fill tessellation pipeline.
§The input: iterators
The path tessellators are not tied to a particular data structure. Instead they consume iterators of flattened path events. A Path struct in the crate lyon_path is provided for convenience (but is optional).
§The output: geometry builders
The tessellators are parametrized over a type implementing the GeometryBuilder trait. This trait provides some simple methods to add vertices and triangles, without enforcing any particular representation for the resulting geometry. This is important because each application will usually want to work with its own vertex type tailored a certain rendering model.
Applications can implement the GeometryBuilder<Point> trait in order to
generate vertex buffers and index buffers with custom vertex types.
The structs VertexBuffers and
geometry_builder::BuffersBuilder are provided
for convenience. VertexBuffers<T> is contains a Vec<T> for the vertices and a Vec<u16>
for the indices.
BuffersBuilder is generic over a VertexConstructor<InputVertex, OutputVertex> trait which
creates the application’s output vertices from the tessellator input vertices (either FillVertex
or StrokeVertex).
§Rendering the tessellated geometry
The tessellators produce geometry in the form of vertex and index buffers which are expected
to be rendered using the equivalent of OpenGL’s glDrawElements with mode GL_TRIANGLES available
under various names in the different graphics APIs.
There is an example showing how
it can be done with wgpu.
§Flattening and tolerance
Most tessellators in this crate currently operate on flattened paths (paths or shapes represented
by sequences of line segments). when paths contain bézier curves or arcs, the latter need to be
approximated with sequences of line segments. This approximation depends on a tolerance parameter
which represents the maximum distance between a curve and its flattened approximation.
More explanation about flattening and tolerance in the lyon_geom crate.
§Examples
Re-exports§
Modules§
- geometry_
builder - Tools to help with generating vertex and index buffers.
- math
- f32 version of the lyon_geom types used everywhere. Most other lyon crates reexport them.
Structs§
- Buffers
Builder - A temporary view on a
VertexBuffersobject which facilitate the population of vertex and index data. - Event
Queue - A queue of sorted events for the fill tessellator’s sweep-line algorithm.
- Event
Queue Builder - Fill
Builder - Fill
Options - Parameters for the fill tessellator.
- Fill
Tessellator - A Context object that can tessellate fill operations for complex paths.
- Fill
Vertex - Extra vertex information from the
FillTessellator, accessible when building vertices. - Stroke
Builder - A builder object that tessellates a stroked path via the
PathBuilderinterface. - Stroke
Options - Parameters for the tessellator.
- Stroke
Tessellator - A Context object that can tessellate stroke operations for complex paths.
- Stroke
Vertex - Extra vertex information from the
StrokeTessellatoraccessible when building vertices. - Vertex
Buffers - Structure that holds the vertex and index data.
- Vertex
Id - A virtual vertex offset in a geometry.
- Vertex
Source Iterator - An iterator over the sources of a given vertex.
Enums§
- Fill
Rule - The fill rule defines how to determine what is inside and what is outside of the shape.
- Geometry
Builder Error - An error that can happen while generating geometry.
- Internal
Error - Describes an unexpected error happening during tessellation.
- LineCap
- Line cap as defined by the SVG specification.
- Line
Join - Line join as defined by the SVG specification.
- Orientation
- Vertical or Horizontal.
- Side
- The positive or negative side of a vector or segment.
- Tessellation
Error - The fill tessellator’s error enumeration.
- Unsupported
Paramater - Vertex
Source - Where a vertex produced by a tessellator comes from in the original path.
Traits§
- Fill
Geometry Builder - A Geometry builder to interface with the
FillTessellator. - Fill
Vertex Constructor - A trait specifying how to create vertex values.
- Geometry
Builder - An interface separating tessellators and other geometry generation algorithms from the actual vertex construction.
- Stroke
Geometry Builder - A Geometry builder to interface with the
StrokeTessellator. - Stroke
Vertex Constructor - A trait specifying how to create vertex values.
Type Aliases§
- Attribute
Index - An alias for
usize. - Attributes
- An alias for a slice of
f32values. - Tessellation
Result - The fill tessellator’s result type.