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>
Constructors
Section titled “Constructors”PgPolygon(IEnumerable<PgPoint>)
Section titled “PgPolygon(IEnumerable<PgPoint>)”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.
Properties
Section titled “Properties”BoundingBox
Section titled “BoundingBox”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
this[int]
Section titled “this[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.
Points
Section titled “Points”Gets the vertices without exposing mutable storage.
public ReadOnlySpan<PgPoint> Points { get; }Value: ReadOnlySpan<PgPoint>
Methods
Section titled “Methods”GetEnumerator()
Section titled “GetEnumerator()”Enumerates vertices in order.
public IEnumerator<PgPoint> GetEnumerator()Returns: IEnumerator<PgPoint>
The vertex enumerator.
Parse(string)
Section titled “Parse(string)”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.
ToString()
Section titled “ToString()”Formats vertices without backend access.
public override string ToString()Returns: string
The polygon text.
ToString(string?, IFormatProvider?)
Section titled “ToString(string?, IFormatProvider?)”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:
- FormatException: A format is specified.
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:
- FormatException: A format is specified.
TryParse(string?, out PgPolygon?)
Section titled “TryParse(string?, out PgPolygon?)”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.