### 74 releases (14 stable)

1.0.13 | Dec 17, 2023 |
---|---|

1.0.11 | Nov 6, 2023 |

1.0.10 | Feb 5, 2023 |

1.0.7 | Dec 7, 2022 |

0.1.1 | Jul 14, 2016 |

#**679** in Graphics APIs

**59,846** downloads per month

Used in **207** crates
(19 directly)

**MIT/Apache**

1MB

**35K**
SLoC

# lyon::tessellation

Tessellation of filled and stroked 2D paths.

can be used as a standalone crate or as part of lyon via the `lyon_tessellation`

module.`lyon ::`tessellation

###
`lib.rs`

:

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.

- (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.`GeometryBuilder`

## The tessellation pipeline

FillTessellator GeometryBuilder output VertexConstructor Iterator<PathEvent> builder.add_vertex(FillVertex) -> VertexId;builder.add_triangle(VertexId, VertexId, VertexId); FillVertex -> CustomVertex MoveTo(Point)LineTo(Point)CloseThe 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

trait in order to
generate vertex buffers and index buffers with custom vertex types.`GeometryBuilder <Point>`

The structs VertexBuffers and
geometry_builder::BuffersBuilder are provided
for convenience.

is contains a `VertexBuffers <T>`

`Vec``<`T`>`

for the vertices and a `Vec``<``u16``>`

for the indices.

is generic over a `BuffersBuilder`

trait which
creates the application's output vertices from the tessellator input vertices (either `VertexConstructor <InputVertex, OutputVertex>`

`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

with mode `glDrawElements`

available
under various names in the different graphics APIs.
There is an example showing how
it can be done with wgpu.`GL_TRIANGLES`

### 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

parameter
which represents the maximum distance between a curve and its flattened approximation.`tolerance`

More explanation about flattening and tolerance in the lyon_geom crate.

## Examples

#### Dependencies

~1.5MB

~35K SLoC