Libart: Bézier Paths

typedef enum {
} ArtPathcode;

typedef struct _ArtVpath ArtVpath;

typedef struct _ArtBpath ArtBpath;

struct _ArtBpath {
  ArtPathcode code;
  double x1;
  double y1;
  double x2;
  double y2;
  double x3;
  double y3;

ArtBpath is the libart data structure for representing Bézier paths. Related data structures include Vector paths.

A Bézier path is represented in memory as an array of ArtBpath elements. The last such element has a path code of ART_END.

A Bézier path is made of a number of segments, each of which is a connected sequence of lines and curves. The ordering of segments within a vector path is not significant. Each segment begins with an ART_MOVETO or ART_MOVETO_OPEN path code. Each successive line or curve in the segment has an ART_LINETO or ART_CURVETO path code, respectively.

For the ART_MOVETO, ART_MOVETO_OPEN, and ART_LINETO path codes, only the x3 and y3 fields are used.

Curves are standard Bézier cubic splines. Thus, if x0 and y0 represent the x3 and y3 coordinates of the previous element, then the curve traces through (x, y) defined by the following formulae as t goes from 0 to 1:

x = x0(1 - t)3 + x1(1 - t)2t + x2(1 - t)t2 + x3t3

y = y0(1 - t)3 + y1(1 - t)2t + y2(1 - t)t2 + y3t3

Segments can be either open or closed, depending on the choice of initial path code. The last point of a closed segment should coincide with the first point. The converse is not necessarily true; an open path in which the last point coincides with the first is entirely legal.