Inkscape Wiki

draw freely
Download Now!
Open Source Scalable Vector Graphics Editor
 


As the 37th attempt at solving this problem, we've created the 2Geom project to provide a high level path data structure for Inkscape.

[edit] Old discussion archive

Proposed data structure for all paths in inkscape

typedef enum{
  [[MoveTo]],
  [[LineTo]],
  [[ArcTo]],
  [[CubicTo]],
  End
} [[PathOperator]];

class Path {
  vector<NR::Point> data;
  vector<PathOperator> operators;
};
Aren't you missing QuadTo? -- MenTaLguY
End is the same as ClosePath, isn't it? -- Piers

MoveTo matches one point, the position to move to.

LineTo matches one point, the position to draw a line to.

ArcTo matches 4 points, a scale pair, a rotation vector, a pair of bools for orientation and the position to draw the arc to.

[16:02]<njh> well the xform is really just a pair of vectors, which we could call rx and ry
[16:03]<njh> the length of which would represent the rx and ry SVG values, and the angle of rx would be the rotation of the ellipse
[16:03]<njh> we then require that the arc is drawn in a positive winding direction from start, travelling from rx to ry, thus putting an orientation on the arc
[16:04]<njh> I haven't convinced myself that you can represent both flags this way, but it seems reasonable.

CubicTo matches three points, the two control points and the final position to draw a curve to.

End doesn't match any points

Compare with vector<union{MoveToObject, LineToObject}> path; which has both issues with union, and memory cost of largest possible object

Livarot has additional weights with each control point, but it is not clear what these mean, perhaps some kind of NURB?

Batik has a similar approach (parallel vectors); note however, that the parameters are just doubles, rather than Points:

class Path {
  vector<double> data;
  vector<PathOperator> operators;
};

SVG has 10 commands, maybe to get the best possible compliance and possibillities we should use all of them, or will that slow things down too much? I think they should be used when possible in the SVG, but it could also be kept somewhere else as it is now, like with the sodipodi:nodetypes -- Piers

For Your Consideration:

cmdNameSize
MMoveTo1 point
ZClosePath/Endnone
LLineTo1 point
HHorizLineTo1 (.5) point
VVertLineTo1 (.5) point
CCubicTo3 points
SSmoothCubicTo2 points (first control point is mirrored)
QQuadTo2 points
TSmoothQuadTo1 point (first control point is mirrored)
AArcTo2 points (endpoint & radii) + 2 bools (large & sweep) + 1 rotation vector