PathData Class

The geometry of a ScenePath: a list of commands, as in SVG.

public sealed class PathData

Properties

NameDescription
CommandsGets the commands of the path.
IsEmptyGets a value that indicates whether the path has no commands.

Commands

PathData.cs

Gets the commands of the path.

public IReadOnlyList<PathCommand> Commands { get; }

Gets a value that indicates whether the path has no commands.

public bool IsEmpty { get; }

Property value

bool

Methods

NameDescription
GetLength()Gets the length of the path: the lengths of its subpaths, without the moves between them.
GetPointAtLength(double)Gets the point at a distance along the path, and the direction of the path there, as SVG getPointAtLength.
GetVertices()Gets the vertices of the path, where its markers are drawn (ScenePath.MarkerStart, ScenePath.MarkerMid, ScenePath.MarkerEnd), with the direction of the path there, as SVG computes them for orient="auto".
Reverse()Returns the path drawn backwards: its subpaths in the reverse order, each from its end to its start, as SVG 2 reverses the path of a textPath whose side is right.
ToCubicCurves()Returns the path with its quadratic curves and its arcs converted to cubic Bézier curves, for the formats that have no other curve, such as PDF and PostScript. The other commands are kept.
ToString()Returns the path as the value of the d attribute of an SVG path.
Translate(double, double)Returns the path moved by an offset. The radii and the rotations of the arcs do not change.

GetLength()

PathData.cs

Gets the length of the path: the lengths of its subpaths, without the moves between them.

public double GetLength()

Returns

double The length.

Remarks

The curves and the arcs are measured by their chords, within 1/100 of a pixel. A segment with a coordinate that is not finite has no length.

GetPointAtLength(double)

PathData.cs

Gets the point at a distance along the path, and the direction of the path there, as SVG getPointAtLength.

public PathPoint GetPointAtLength(double distance)

Parameters

distance double
The distance from the start of the path. It is clamped to the path; a value that is not a number is 0.

Returns

PathPoint The point. At the end of a segment, the direction is the one of the next segment; at the end of the path, the one of its last segment. A path without length gives its first point, with a direction of 0.

Exceptions

InvalidOperationException
The path is empty.

GetVertices()

PathData.cs

Gets the vertices of the path, where its markers are drawn (ScenePath.MarkerStart, ScenePath.MarkerMid, ScenePath.MarkerEnd), with the direction of the path there, as SVG computes them for orient="auto".

public IReadOnlyList<PathPoint> GetVertices()

Returns

IReadOnlyList<PathPoint> One vertex per command: the end point of each command, and the start of its subpath for a PathCommandKind.Close command. A path whose first command is not a move starts with a vertex at the origin. The start marker is on the first vertex, the end marker on the last one, the middle marker on the others.

Remarks

The direction at a vertex is halfway between the directions of the segment that ends there and of the one that starts there, or the direction of the only one; the tangents of the curves and the arcs. A closed subpath joins its last segment and its first one at its start. A segment without length keeps the direction of the previous one.

Reverse()

PathData.cs

Returns the path drawn backwards: its subpaths in the reverse order, each from its end to its start, as SVG 2 reverses the path of a textPath whose side is right.

public PathData Reverse()

Returns

PathData The reversed path, which covers the same points.

Remarks

Each subpath starts with a move to its last point, then follows its segments back: the control points of the curves are swapped, and the arcs turn the other way (their PathCommand.Sweep flag is inverted). A closed subpath starts at the end of its last segment and closes at the same point. A path that does not start with a move starts at the origin, and a segment that follows a PathCommandKind.Close command starts at the start of the closed subpath, as in SVG: the reversed path has explicit moves to these points. Reversing the reversed path gives the original geometry.

ToCubicCurves()

PathData.cs

Returns the path with its quadratic curves and its arcs converted to cubic Bézier curves, for the formats that have no other curve, such as PDF and PostScript. The other commands are kept.

public PathData ToCubicCurves()

Returns

PathData The path, made of PathCommandKind.MoveTo, PathCommandKind.LineTo, PathCommandKind.CubicTo and PathCommandKind.Close commands.

Remarks

A quadratic curve becomes the cubic curve of the same shape. An arc is resolved as SVG resolves it (SVG 1.1, appendix F.6): a radius of 0 gives a line, radii too small for the end points are scaled up, and an arc that ends where it starts is omitted. It is approximated by one cubic curve per quarter of a turn at most.

ToString()

PathData.cs

Returns the path as the value of the d attribute of an SVG path.

public override string ToString()

Returns

string The path data.

Translate(double, double)

PathData.cs

Returns the path moved by an offset. The radii and the rotations of the arcs do not change.

public PathData Translate(double offsetX, double offsetY)

Parameters

offsetX double
The offset along x.
offsetY double
The offset along y.

Returns

PathData The moved path.