Table of Contents

Class PathMeasure

Namespace
Egami.Drawing
Assembly
Egami.Drawing.dll

Measures a path: the length of each contour, and the point, direction and pieces at any distance along it. Lengths are exact to about 1e-4 units, curves included: each curve's length is integrated by adaptive Gauss–Legendre quadrature, and a distance is turned back into a point on the curve by Newton steps, so long curves do not gather the errors of a flattened outline. Contours of zero length are left out, as Skia's SkContourMeasureIter leaves them. Measuring is done once, here; the queries are cheap and safe from many threads.

public sealed class PathMeasure
Inheritance
PathMeasure
Inherited Members

Examples

// Measure a path: its length, and a point and direction at any distance, curves included.
Path route = new PathBuilder().MoveTo(10, 90).CubicTo(60, 0, 140, 160, 190, 60).ToPath();
PathMeasure measure = new(route);
ContourMeasure contour = measure.Contours[0];
Vector2 halfway = contour.GetPosition(contour.Length / 2);
Vector2 heading = contour.GetTangent(contour.Length / 2);

// An arrowhead placed at the end, turned along the path, and the middle third as a path of its own (still a cubic).
Path arrow = Path.Polygon([new(-6, -4), new(0, 0), new(-6, 4)]).Transform(contour.GetMatrix(contour.Length));
Path middle = contour.GetSegment(contour.Length / 3, 2 * contour.Length / 3);

Constructors

PathMeasure(Path, bool)

Initializes a new instance of the PathMeasure class.

public PathMeasure(Path path, bool forceClosed = false)

Parameters

path Path

The path.

forceClosed bool

Whether to measure open contours as if closed, with the line back to their start.

Properties

Contours

Gets the contours that have a length, in the path's order.

public IReadOnlyList<ContourMeasure> Contours { get; }

Property Value

IReadOnlyList<ContourMeasure>

TotalLength

Gets the length of all the contours together.

public float TotalLength { get; }

Property Value

float