Class ContourMeasure
One measured contour of a PathMeasure. Distances run from 0 at the contour's start to Length at its end; distances outside are clamped to them, as in Skia.
public sealed class ContourMeasure
- Inheritance
-
ContourMeasure
- 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);
Properties
IsClosed
Gets a value indicating whether the contour is closed, so its end meets its start.
public bool IsClosed { get; }
Property Value
Length
Gets the contour's length.
public float Length { get; }
Property Value
Methods
AddSegment(PathBuilder, float, float, bool)
Adds the piece between two distances to a builder, as GetSegment(float, float) describes.
public void AddSegment(PathBuilder builder, float start, float end, bool startWithMove = true)
Parameters
builderPathBuilderThe builder.
startfloatWhere the piece starts; clamped to the contour.
endfloatWhere the piece ends; clamped to the contour.
startWithMoveboolWhether the piece starts a new contour; otherwise a line joins it to the builder's current point, to chain pieces into one contour.
GetMatrix(float)
Returns the transform that puts a shape on the contour at a distance: its x axis along the direction of travel and its origin at the point, so a shape drawn along +x follows the path.
public Matrix3x2 GetMatrix(float distance)
Parameters
distancefloatThe distance from the start, clamped to the contour.
Returns
- Matrix3x2
A rotation and translation.
GetPosition(float)
Returns the point at a distance along the contour.
public Vector2 GetPosition(float distance)
Parameters
distancefloatThe distance from the start, clamped to the contour.
Returns
- Vector2
The point.
GetSegment(float, float)
Returns the piece of the contour between two distances, as a path of one open contour that keeps the contour's lines, quadratics and cubics: curves cut at the ends are split exactly, so the piece exports as cleanly as the whole. The whole of a closed contour comes back closed.
public Path GetSegment(float start, float end)
Parameters
startfloatWhere the piece starts; clamped to the contour.
endfloatWhere the piece ends; clamped to the contour.
Returns
- Path
The piece, or an empty path when
endis not afterstart.
GetTangent(float)
Returns the direction of travel at a distance along the contour, as a unit vector.
public Vector2 GetTangent(float distance)
Parameters
distancefloatThe distance from the start, clamped to the contour.
Returns
- Vector2
The direction; where a curve's direction is undefined (a cusp), the limit from inside the curve.