Table of Contents

Class Contour

Namespace
SixLabors.PolygonClipper
Assembly
SixLabors.PolygonClipper.dll

Represents a single polygon ring (outer contour or hole).

public sealed class Contour : IReadOnlyCollection<Vertex>, IEnumerable<Vertex>, IEnumerable
Inheritance
Contour
Implements
Inherited Members

Remarks

A contour is treated as implicitly closed: an edge is always considered between the last vertex and the first vertex. A duplicated terminal closing vertex is optional on input but not required.

Constructors

Contour()

Initializes a new instance of the Contour class.

public Contour()

Contour(int)

Initializes a new instance of the Contour class with a vertex capacity.

public Contour(int capacity)

Parameters

capacity int

The initial vertex capacity.

Properties

Count

Gets the number of stored vertices.

public int Count { get; }

Property Value

int

Depth

Gets or sets the depth of the contour.

public int Depth { get; set; }

Property Value

int

HoleCount

Gets the number of holes.

public int HoleCount { get; }

Property Value

int

IsExternal

Gets a value indicating whether the contour is external (not a hole).

public bool IsExternal { get; }

Property Value

bool

this[int]

Gets the vertex at the specified index.

public Vertex this[int index] { get; }

Parameters

index int

The index of the vertex.

Property Value

Vertex

The Vertex at the specified index.

ParentIndex

Gets or sets the index of the parent contour in the polygon if this contour is a hole.

public int? ParentIndex { get; set; }

Property Value

int?

Methods

Add(in Vertex)

Adds a vertex to the end of the vertices collection.

public void Add(in Vertex vertex)

Parameters

vertex Vertex

The vertex to add.

AddHoleIndex(int)

Adds a hole index to the contour.

public void AddHoleIndex(int index)

Parameters

index int

The index of the hole to add.

Clear()

Clears all vertices and holes from the contour.

public void Clear()

ClearHoles()

Clears all holes from the contour.

public void ClearHoles()

DeepClone()

Creates a deep copy of this contour.

public Contour DeepClone()

Returns

Contour

A detached contour copy.

GetBoundingBox()

Gets the bounding box of the contour.

public Box2 GetBoundingBox()

Returns

Box2

The Box2.

GetEnumerator()

Returns an enumerator that iterates through the collection.

public IEnumerator<Vertex> GetEnumerator()

Returns

IEnumerator<Vertex>

An enumerator that can be used to iterate through the collection.

GetHoleIndex(int)

Gets the hole index at the specified position in the contour.

public int GetHoleIndex(int index)

Parameters

index int

The index of the hole.

Returns

int

The hole index.

GetLastVertex()

Gets the last vertex in the contour.

public Vertex GetLastVertex()

Returns

Vertex

The last Vertex in the contour.

IsClockwise()

Gets a value indicating whether the contour is clockwise oriented

public bool IsClockwise()

Returns

bool

true if the contour is clockwise oriented; otherwise false.

IsCounterClockwise()

Gets a value indicating whether the contour is counterclockwise oriented

public bool IsCounterClockwise()

Returns

bool

true if the contour is counterclockwise oriented; otherwise false.

RemoveVertexAt(int)

Removes the vertex at the specified index from the contour.

public void RemoveVertexAt(int index)

Parameters

index int

The index of the vertex to remove.

Reverse()

Reverses the orientation of the contour.

public void Reverse()

SetClockwise()

Sets the contour to clockwise orientation.

public void SetClockwise()

SetCounterClockwise()

Sets the contour to counterclockwise orientation.

public void SetCounterClockwise()

Translate(double, double)

Translates the contour by the specified x and y values.

public void Translate(double x, double y)

Parameters

x double

The x-coordinate offset.

y double

The y-coordinate offset.