Table of Contents

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:

  • Points stores the concatenated point data for every contour.
  • Contours maps each contour to its point run and derived segment range.
  • Info exposes geometry-wide metadata such as bounds and total segment count.

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

info LinearGeometryInfo

The geometry metadata.

contours IReadOnlyList<LinearContour>

The contour metadata.

points IReadOnlyList<PointF>

The point storage.

Properties

Contours

Gets the contour metadata describing how Points is partitioned.

public IReadOnlyList<LinearContour> Contours { get; }

Property Value

IReadOnlyList<LinearContour>

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

LinearGeometryInfo

Points

Gets the retained point storage for all contours in this geometry.

public IReadOnlyList<PointF> Points { get; }

Property Value

IReadOnlyList<PointF>

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

point PointF

The point to test.

intersectionRule IntersectionRule

The fill rule used for containment.

Returns

bool

true when the point is inside or on the geometry boundary.

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

points PointF[]

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

points PointF[]

The polyline points.

scale Vector2

The X/Y scale at which the polyline is baked.

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()

Gets an enumerator for the derived linear segments represented by Points and Contours.

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

distance float

The distance along the geometry.

pathPoint PathPoint

When this method returns, contains the path information at distance if the distance resolves to a point on the geometry; otherwise, the default value.

Returns

bool

true if distance resolves to a point on the geometry; otherwise, false.

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

distance float

The distance along the geometry.

pathPoint PathPoint

When this method returns, contains the path information at distance if the geometry is measurable; otherwise, the default value.

Returns

bool

true if the point could be resolved; otherwise, false.

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

startDistance float

The segment start distance.

stopDistance float

The segment stop distance.

startOnBeginFigure bool

Whether the returned segment starts a new figure at the first segment point.

path IPath

When this method returns, contains the segment path if one was created; otherwise, an empty path.

Returns

bool

true when a segment path was created.