Class LinearGeometry
- Namespace
- SixLabors.ImageSharp.Drawing
- Assembly
- SixLabors.ImageSharp.Drawing.dll
Represents retained linearized geometry that can be consumed directly by drawing backends.
public sealed class LinearGeometry
- Inheritance
-
LinearGeometry
- Inherited Members
Remarks
A LinearGeometry instance stores contour-local point data plus the metadata required to interpret those points as a sequence of final linear segments.
Closed contours do not duplicate their first point at the end of the stored point run. Closure is represented by IsClosed, and the closing segment is derived by GetSegments().
The retained storage model is:
Constructors
LinearGeometry(LinearGeometryInfo, IReadOnlyList<LinearContour>, IReadOnlyList<PointF>)
Initializes a new instance of the LinearGeometry class.
public LinearGeometry(LinearGeometryInfo info, IReadOnlyList<LinearContour> contours, IReadOnlyList<PointF> points)
Parameters
infoLinearGeometryInfoThe geometry metadata.
contoursIReadOnlyList<LinearContour>The contour metadata.
pointsIReadOnlyList<PointF>The point storage.
Properties
Contours
Gets the contour metadata describing how Points is partitioned.
public IReadOnlyList<LinearContour> Contours { get; }
Property Value
Remarks
Each entry defines one contour's point run and the corresponding segment range in the derived segment stream.
Info
Gets geometry-wide metadata for this retained result.
public LinearGeometryInfo Info { get; }
Property Value
Points
Gets the retained point storage for all contours in this geometry.
public IReadOnlyList<PointF> Points { get; }
Property Value
Remarks
Points are stored per contour in contour order. A closed contour does not repeat its first point at the end of its stored point run.
Methods
ComputeArea()
Calculates the total absolute area of all contour point runs.
public float ComputeArea()
Returns
- float
The total contour area.
Remarks
Each contour with at least three points contributes the absolute value of its shoelace area, regardless of whether it is marked closed. The result is memoized.
ComputeLength()
Calculates the total length of all derived linear segments.
public float ComputeLength()
Returns
- float
The total segment length.
Remarks
The result is memoized. Concurrent first calls may compute it more than once, which is benign because the computation is deterministic.
Contains(PointF, IntersectionRule)
Returns whether the supplied point is inside the geometry.
public bool Contains(PointF point, IntersectionRule intersectionRule)
Parameters
pointPointFThe point to test.
intersectionRuleIntersectionRuleThe fill rule used for containment.
Returns
Remarks
Only closed contours participate in the test; open contours never contain points. A point lying exactly on a closed contour edge is treated as contained under both fill rules.
CreateOpenPolyline(PointF[])
Creates retained geometry for one open polyline.
public static LinearGeometry CreateOpenPolyline(PointF[] points)
Parameters
pointsPointF[]The polyline points.
Returns
- LinearGeometry
The retained open polyline geometry.
CreateOpenPolyline(PointF[], Vector2)
Creates retained geometry for one open polyline, baked under the supplied device-space scale.
public static LinearGeometry CreateOpenPolyline(PointF[] points, Vector2 scale)
Parameters
Returns
- LinearGeometry
The retained open polyline geometry.
Remarks
When scale is One the input array is retained directly without
copying, so the caller must not mutate it afterwards.
GetSegments()
public SegmentEnumerator GetSegments()
Returns
- SegmentEnumerator
A zero-allocation enumerator that yields the final linear segments in contour order.
TryGetPathPointAtDistance(float, out PathPoint)
Gets path information at the specified distance along the geometry.
public bool TryGetPathPointAtDistance(float distance, out PathPoint pathPoint)
Parameters
distancefloatThe distance along the geometry.
pathPointPathPointWhen this method returns, contains the path information at
distanceif the distance resolves to a point on the geometry; otherwise, the default value.
Returns
Remarks
The distance must resolve to a point on the geometry itself: negative or non-finite distances fail, and when any contour is open a distance beyond the total length fails. When every contour is closed the distance wraps modulo the total length instead.
At a distance that lands exactly on a shared vertex the outgoing segment wins, so the reported tangent and angle are those of the segment leaving the vertex.
TryGetPathPointAtDistanceUnbounded(float, out PathPoint)
Gets path information at the specified distance along the geometry, extrapolating along the boundary tangents when the distance falls before the start or beyond the end of an open geometry.
public bool TryGetPathPointAtDistanceUnbounded(float distance, out PathPoint pathPoint)
Parameters
distancefloatThe distance along the geometry.
pathPointPathPointWhen this method returns, contains the path information at
distanceif the geometry is measurable; otherwise, the default value.
Returns
Remarks
Unlike TryGetPathPointAtDistance(float, out PathPoint), out-of-range distances resolve to a point on the virtual straight-line continuation of the geometry's first or last segment. The method returns false only when the distance is not a finite number or the geometry has no measurable length.
TryGetSegment(float, float, bool, out IPath)
Creates a path segment between two distances along the geometry.
public bool TryGetSegment(float startDistance, float stopDistance, bool startOnBeginFigure, out IPath path)
Parameters
startDistancefloatThe segment start distance.
stopDistancefloatThe segment stop distance.
startOnBeginFigureboolWhether the returned segment starts a new figure at the first segment point.
pathIPathWhen this method returns, contains the segment path if one was created; otherwise, an empty path.