Table of Contents

Class PolygonStore

Namespace
LansMap.Core.Vector

Filled-polygon collection: rings triangulated at add time into mercator triangles for the GPU fill layer.

public sealed class PolygonStore
Inheritance
object
PolygonStore

Fields

InitialTriangleCapacity

Starting triangle-list capacity for a new store.

public const int InitialTriangleCapacity = 256

Field Value

int

Properties

Dirty

True when triangles changed since the last ClearDirty().

public bool Dirty { get; }

Property Value

bool

PolygonCount

Number of polygons currently stored (removed ones excluded).

public int PolygonCount { get; }

Property Value

int

TriangleCount

Number of triangle slots, including collapsed removed ones until compact.

public int TriangleCount { get; }

Property Value

int

Triangles

Live triangle list the GPU fill layer uploads, including collapsed removed slots until compact.

public IReadOnlyList<PolygonStore.Triangle> Triangles { get; }

Property Value

IReadOnlyList<PolygonStore.Triangle>

Methods

AddEmptyPolygon(int, uint)

Reserves a polygon with no ring yet; invisible until SetPolygonRing(int, IReadOnlyList<LatLon>) writes at least three points.

public int AddEmptyPolygon(int maxPoints, uint fillColorRgba)

Parameters

maxPoints int

Most ring vertices one SetPolygonRing(int, IReadOnlyList<LatLon>) call will ever carry; at least 3.

fillColorRgba uint

Fill color as packed RGBA.

Returns

int

Polygon id of the reserved polygon.

Exceptions

ArgumentException

maxPoints is less than 3.

AddPolygon(IReadOnlyList<LatLon>, uint)

Adds a filled ring, throwing if the ring is refused.

public int AddPolygon(IReadOnlyList<LatLon> ring, uint fillColorRgba)

Parameters

ring IReadOnlyList<LatLon>

Closed outline in degrees WGS84; at least three vertices.

fillColorRgba uint

Fill color as packed RGBA.

Returns

int

Polygon id of the stored ring.

Exceptions

ArgumentException

The ring was refused; see Describe(Rejection).

ClearDirty()

Clears Dirty after the GPU fill layer has uploaded.

public void ClearDirty()

Describe(Rejection)

Developer-facing text for a PolygonStore.Rejection. User-facing wording belongs to the UI.

public static string Describe(PolygonStore.Rejection refusal)

Parameters

refusal PolygonStore.Rejection

Why the ring was refused, or None.

Returns

string

One-line English for logs and the throwing overload.

RemovePolygon(int)

Collapses a polygon's triangles (color 0). Unknown ids are ignored. Compacts when more than half the slots are waste.

public void RemovePolygon(int id)

Parameters

id int

Polygon id from a successful add.

SetPolygonColor(int, uint)

Recolors every live triangle of a polygon and the color a future SetPolygonRing(int, IReadOnlyList<LatLon>) call will use. Unknown ids are ignored.

public void SetPolygonColor(int id, uint fillColorRgba)

Parameters

id int

Polygon id from a successful add.

fillColorRgba uint

New fill color as packed RGBA.

SetPolygonRing(int, IReadOnlyList<LatLon>)

Rewrites an existing polygon's ring in place.

public PolygonStore.Rejection SetPolygonRing(int id, IReadOnlyList<LatLon> ring)

Parameters

id int

Polygon id from AddPolygon(IReadOnlyList<LatLon>, uint), TryAddPolygon(IReadOnlyList<LatLon>, uint), or AddEmptyPolygon(int, uint).

ring IReadOnlyList<LatLon>

New closed outline in degrees WGS84. Null or fewer than three vertices hides the polygon (a state it carries, not an error) while keeping its reservation and fill color.

Returns

PolygonStore.Rejection

None when the ring was accepted or the polygon was hidden; TriangulationFailed when the ring was refused, in which case the previous fill is kept and this refusal is also readable back through TryGetPolygon(int, out PolygonInfo).

Remarks

When the new ring triangulates to no more triangles than the polygon's current reservation, every write lands in place. A ring that needs more triangles reallocates a new range at max(needed, 2x old capacity) and keeps the same id - the old range joins the waste count instead of leaking. A caller whose peak vertex count is known up front avoids the allocating path entirely by reserving with AddEmptyPolygon(int, uint) once.

Exceptions

ArgumentException

id is unknown.

TryAddPolygon(IReadOnlyList<LatLon>, uint)

Tries to add a filled ring without throwing.

public PolygonStore.AddResult TryAddPolygon(IReadOnlyList<LatLon> ring, uint fillColorRgba)

Parameters

ring IReadOnlyList<LatLon>

Closed outline in degrees WGS84. Null or fewer than three vertices is TooFewPoints.

fillColorRgba uint

Fill color as packed RGBA.

Returns

PolygonStore.AddResult

An id on success; TooFewPoints or TriangulationFailed (self-intersection, no area, or ear clipping stopped) otherwise.

TryGetPolygon(int, out PolygonInfo)

Reads a polygon's current settings and vertex count.

public bool TryGetPolygon(int id, out PolygonInfo info)

Parameters

id int

Polygon id from a successful add.

info PolygonInfo

The snapshot on success; default otherwise.

Returns

bool

False when id is unknown or removed.