Skip to content

PgPolygon

Namespace: Ankus

Assembly: Ankus.Runtime.dll

Owns an immutable ordered sequence of polygon vertices and its PostgreSQL-compatible bounding box. Empty polygons have a zero bounding box and can be constructed without backend access.

public sealed class PgPolygon : IReadOnlyList<PgPoint>, IReadOnlyCollection<PgPoint>, IEnumerable<PgPoint>, IEnumerable, ISpanFormattable, IFormattable, IParsable<PgPolygon>

Inheritance: object

Implements: IReadOnlyList<PgPoint>, IReadOnlyCollection<PgPoint>, IEnumerable<PgPoint>, IEnumerable, ISpanFormattable, IFormattable, IParsable<PgPolygon>

Copies the vertices and computes coordinate extrema using PostgreSQL floating-point ordering.

public PgPolygon(IEnumerable<PgPoint> points)

Parameters:

points — IEnumerable<PgPoint>

The ordered polygon vertices.

Gets the minimum bounding rectangle, or the zero box for an empty polygon.

public PgBox BoundingBox { get; }

Value: PgBox

Gets the number of vertices.

public int Count { get; }

Value: int

Gets a vertex by its zero-based index.

public PgPoint this[int index] { get; }

Parameters:

index — int

The vertex index.

Value: PgPoint

The point.

Gets the vertices without exposing mutable storage.

public ReadOnlySpan<PgPoint> Points { get; }

Value: ReadOnlySpan<PgPoint>

Enumerates vertices in order.

public IEnumerator<PgPoint> GetEnumerator()

Returns: IEnumerator<PgPoint>

The vertex enumerator.

Parses a polygon using PostgreSQL on the active backend.

public static PgPolygon Parse(string text)

Parameters:

text — string

The polygon text.

Returns: PgPolygon

The owned polygon.

Formats vertices without backend access.

public override string ToString()

Returns: string

The polygon text.

Formats the value as PostgreSQL’s canonical text, the same text as ToString().

public string ToString(string? format, IFormatProvider? formatProvider)

Parameters:

format — string

Null or empty; PostgreSQL text has one canonical form.

formatProvider — IFormatProvider

Ignored: the text does not depend on culture.

Returns: string

The canonical text.

Exceptions:

TryFormat(Span<char>, out int, ReadOnlySpan<char>, IFormatProvider?)

Section titled “TryFormat(Span<char>, out int, ReadOnlySpan<char>, IFormatProvider?)”

Copies the value’s canonical PostgreSQL text into a span, as interpolated strings and other span-based formatters request it.

public bool TryFormat(Span<char> destination, out int charsWritten, ReadOnlySpan<char> format, IFormatProvider? provider)

Parameters:

destination — Span<char>

The span that receives the text.

charsWritten — int

The number of characters written.

format — ReadOnlySpan<char>

Empty; PostgreSQL text has one canonical form.

provider — IFormatProvider

Ignored: the text does not depend on culture.

Returns: bool

Whether the text fit in the destination.

Exceptions:

Tries PostgreSQL parsing without swallowing backend-access or operational errors.

public static bool TryParse(string? text, out PgPolygon? value)

Parameters:

text — string

The polygon text.

value — PgPolygon

The result, or null.

Returns: bool

Whether parsing succeeded.

Invalid input leaves no error pending: PostgreSQL 16 and later report it as a soft input error, and earlier majors roll back an internal subtransaction. Before PostgreSQL 16, transaction callbacks and parallel operations forbid that rollback; native errors there remain pending and throw PgException.