-
Notifications
You must be signed in to change notification settings - Fork 144
Stroke tessellation
The code for the path stroke tessellator is in tessellation/src/path_stroke.rs.
Some specific tessellation routines for simpler shapes are implemented in tessellation/src/basic_shapes.rs.
The stroke tessellator task as input an iterator of flattened path events (it does not handle bezier curves or arcs). Flattened path events give information like "start a new sub-path at this position", "draw a line from the current position to this position", "end the current sub-path drawing a line to the start of the sub path", etc.
The stroke tessellator does not apply the line width. Instead it generates vertices which contain a position along the path and a normal (applying the line width is done by adding the normal times the width divided by two to the vertex position).
In order to compute the normal for a given vertex, the algorithm needs the positions of the previous and next vertices. This means that as it consumes the path events, the tessellator keeps track of the first, second, current and previous positions. This way, at each LineTo
event the tessellator can look at the current position the previous position, and the new position pointed by the event to compute the normal for the current vertex and generate the triangles between the previous and current vertices. In other words, the tessellator is always emitting triangles for the previous segment when it receives a new LineTo event.
Stroke specification: https://svgwg.org/specs/strokes/
While implementing the entire SVG specification is out of scope, it is best to stay close to SVG for implemented features.