VectorPathMeasure Class
The chords of a path, computed once, to answer many questions about its length, its points and its directions: the position of a marker that moves along the path, or the point a pointer snaps to as it moves.
public sealed class VectorPathMeasureRemarks
The answers are those of VectorPath.GetLength, VectorPath.TryGetPointAtDistance and VectorPath.TryGetClosestPoint, bit for bit: the path is measured by the chords it is drawn with, within 1/16 of a pixel of its curves, a closed contour includes its closing segment, and the contours follow each other without the gap between them. Those methods walk the whole path at each call; a measure walks it once, when it is created, then finds a point at a distance by a binary search, and the closest point by skipping the groups of chords that are farther than the nearest one found.
A path cannot change once it is built: a measure keeps answering for the path it was created from (VectorPathMeasure.Path), and is thread-safe. It holds 48 bytes per chord.
Constructors
| Name | Description |
|---|---|
| VectorPathMeasure(VectorPath) | Initializes a new instance of the VectorPathMeasure class: measures a path. |
VectorPathMeasure(VectorPath)
VectorPathMeasure.csInitializes a new instance of the VectorPathMeasure class: measures a path.
public VectorPathMeasure(VectorPath path)Properties
| Name | Description |
|---|---|
| Length | Gets the length of the path: what VectorPath.GetLength gives. |
| Path | Gets the path that is measured. |
Length
VectorPathMeasure.csGets the length of the path: what VectorPath.GetLength gives.
public double Length { get; }Property value
Methods
| Name | Description |
|---|---|
| TryGetClosestPoint(PointD, PointD, double) | Finds the point of the path that is the nearest to a position, and its distance along the path. |
| TryGetPointAtDistance(double, PointD, PointD) | Finds the point at a distance from the start of the path, and the direction of the path there. |
TryGetClosestPoint(PointD, PointD, double)
VectorPathMeasure.csFinds the point of the path that is the nearest to a position, and its distance along the path.
Parameters
pointPointD- The position.
closestPointD- The nearest point of the path.
distanceAlongPathdouble- The distance from the start of the path to that point, along the path, in pixels.
Returns
bool false when the path has no length: there is no point to find.
Exceptions
ArgumentException- A coordinate of
pointis not a finite number.
Remarks
The answer is the one of VectorPath.TryGetClosestPoint: when several points are as near, the first one along the path is given. The groups of chords whose box is farther than the nearest point found are skipped: the time grows with the number of chords near the position, and with the number of groups.
TryGetPointAtDistance(double, PointD, PointD)
VectorPathMeasure.csFinds the point at a distance from the start of the path, and the direction of the path there.
Parameters
distancedouble- The distance from the start of the path, in pixels.
pointPointD- The point of the path at that distance.
tangentPointD- The direction of the path at that point, as a vector of length 1.
Returns
bool false when the path has no length: there is no point to find, and no direction.
Exceptions
ArgumentExceptiondistanceis not a number.
Remarks
The answer is the one of VectorPath.TryGetPointAtDistance: a distance before the start gives the first point, a distance beyond the end the last one, and at a corner the direction is the one of the segment that starts there. The time grows with the logarithm of the number of chords.