Module rsvg::path_builder

source ·
Expand description

Representation of Bézier paths.

Path data can consume a significant amount of memory in complex SVG documents. This module deals with this as follows:

  • The path parser pushes commands into a PathBuilder. This is a mutable, temporary storage for path data.

  • Then, the PathBuilder gets turned into a long-term, immutable Path that has a more compact representation.

The code tries to reduce work in the allocator, by using a [TinyVec] with space for at least 32 commands on the stack for PathBuilder; most paths in SVGs in the wild have fewer than 32 commands, and larger ones will spill to the heap.

See these blog posts for details and profiles:


  • “c” command for paths; describes a cubic Bézier segment.
  • “a” command for paths; describes an elliptical arc in terms of its endpoints.
  • Whether an arc’s sweep should be >= 180 degrees, or smaller.
  • An immutable path with a compact representation.
  • Constructs a path out of commands.
  • A slice of commands and coordinates with a single MoveTo at the beginning.
  • An iterator over the commands/coordinates of a subpath.
  • An iterator over the subpaths of a Path.


  • Conversion from endpoint parameterization to center parameterization.
  • Packed version of a PathCommand, used in Path.
  • Long-form version of a single path command.
  • Angular direction in which an arc is drawn.