Class PolygonStore
Filled-polygon collection: rings triangulated at add time into mercator triangles for the GPU fill layer.
public sealed class PolygonStore
- Inheritance
-
objectPolygonStore
Fields
InitialTriangleCapacity
Starting triangle-list capacity for a new store.
public const int InitialTriangleCapacity = 256
Field Value
Properties
Dirty
True when triangles changed since the last ClearDirty().
public bool Dirty { get; }
Property Value
PolygonCount
Number of polygons currently stored (removed ones excluded).
public int PolygonCount { get; }
Property Value
TriangleCount
Number of triangle slots, including collapsed removed ones until compact.
public int TriangleCount { get; }
Property Value
Triangles
Live triangle list the GPU fill layer uploads, including collapsed removed slots until compact.
public IReadOnlyList<PolygonStore.Triangle> Triangles { get; }
Property Value
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
maxPointsintMost ring vertices one SetPolygonRing(int, IReadOnlyList<LatLon>) call will ever carry; at least 3.
fillColorRgbauintFill color as packed RGBA.
Returns
- int
Polygon id of the reserved polygon.
Exceptions
- ArgumentException
maxPointsis 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
ringIReadOnlyList<LatLon>Closed outline in degrees WGS84; at least three vertices.
fillColorRgbauintFill 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
refusalPolygonStore.RejectionWhy 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
idintPolygon 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
SetPolygonRing(int, IReadOnlyList<LatLon>)
Rewrites an existing polygon's ring in place.
public PolygonStore.Rejection SetPolygonRing(int id, IReadOnlyList<LatLon> ring)
Parameters
idintPolygon id from AddPolygon(IReadOnlyList<LatLon>, uint), TryAddPolygon(IReadOnlyList<LatLon>, uint), or AddEmptyPolygon(int, uint).
ringIReadOnlyList<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
idis unknown.
TryAddPolygon(IReadOnlyList<LatLon>, uint)
Tries to add a filled ring without throwing.
public PolygonStore.AddResult TryAddPolygon(IReadOnlyList<LatLon> ring, uint fillColorRgba)
Parameters
ringIReadOnlyList<LatLon>Closed outline in degrees WGS84. Null or fewer than three vertices is TooFewPoints.
fillColorRgbauintFill 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
idintPolygon id from a successful add.
infoPolygonInfoThe snapshot on success; default otherwise.
Returns
- bool
False when
idis unknown or removed.