Skip to content
Taco de Wolff edited this page Nov 3, 2024 · 6 revisions

A path defines a vector path in 2D using a series of commands (MoveTo, LineTo, QuadTo, CubeTo, ArcTo and Close). Each command consists of a number of float64 values (depending on the command) that fully define the action. The first value is the command itself (as a float64). The last two values is the end point position of the pen after the action (x,y). QuadTo defined one control point (x,y) in between, CubeTo defines two control points, and ArcTo defines (rx,ry,phi,large+sweep) i.e. the radius in x and y, its rotation (in radians) and the large and sweep booleans in one float64.

Only valid commands are appended, so that LineTo has a non-zero length, QuadTo's and CubeTo's control point(s) don't (both) overlap with the start and end point, and ArcTo has non-zero radii and has non-zero length. For ArcTo we also make sure the angle is in the range [0, 2*PI) and we scale the radii up if they appear too small to fit the arc.

Path operators

For path construction, the following commands are available:

MoveTo(x, y float64)
LineTo(x, y float64)
QuadTo(cpx, cpy, x, y float64)
CubeTo(cpx1, cpy1, cpx2, cpy2, x, y float64)
ArcTo(rx, ry, rot float64, large, sweep bool, x, y float64)
Arc(rx, ry, rot, theta0, theta1 float64)

Path operators

Stroke caps and joins

We can stroke a path using Stroke(w float64, cr Capper, jr Joiner) *Path, with the fpllowing supported cappers and joiners:

Stroke caps and joins

Functionality

Additionally, the following path manipulations are supported:

// Join two paths together
Join(q *Path) *Path

// Append the path's commands
Append(q *Path) *Path

// Flatten the path to linear commands only
Flatten() *Path

// Expand or contract the (closed) path
Offset(w float64, fillRule FillRule) *Path

// Convert the path in dashes
Dash(offset float64, d ...float64) *Path

// Put markers on the path
Markers(first, mid, last *Path, align bool) []*Path

// Split the path at the given distances
SplitAt(ts ...float64) []*Path

// Reverse the direction of the path
Reverse() *Path

Implementation

Command Flatten Stroke Length SplitAt
LineTo yes yes yes yes
QuadTo yes (CubeTo) yes (CubeTo) yes yes (GL5 + Chebyshev10)
CubeTo yes yes yes (GL5) yes (GL5 + Chebyshev10)
ArcTo yes yes yes (GL5) yes (GL5 + Chebyshev10)
  • Ellipse => Cubic Bézier: used by rasterizer and PDF targets (see Maisonobe paper)

NB: GL5 means a Gauss-Legendre n=5, which is an numerical approximation as there is no analytical solution. Chebyshev is a converging way to approximate a function by an n=10 degree polynomial. It uses the bisection method as well to determine the polynomial points.

Clone this wiki locally