Struct Polygon2View
Non-owning read-only view of an ordered sequence of polygon rings.
struct Polygon2View(T)
if (isGeoScalar!T);
Supported scalar types are int, long, float, double, and real.
Polygon2View is an empty polygon view.
Polygon2View does not allocate or copy ring descriptors or point data. The caller retains ownership of both the backing ring-descriptor storage and the point storage referenced by those descriptors. The ring-descriptor storage must remain valid for the lifetime of the Polygon2View. Point storage referenced by a stored ring descriptor must remain valid for as long as that descriptor can be accessed through the Polygon2View.
The view aliases this backing storage. Changes made through the owners of mutable ring-descriptor or point storage remain visible through an existing Polygon2View. Mutation is not exposed through Polygon2View itself.
For a non-empty polygon, ring zero is the exterior ring. Subsequent rings are interior rings. Ring roles are structural and do not depend on winding direction.
Polygon2View does not validate topology or normalize ring orientation. Empty and degenerate rings remain representable through LinearRing2View.
Constructors
| Name | Description |
|---|---|
this
(rings)
|
Constructs a view over contiguous ring-descriptor storage. |
Properties
| Name | Type | Description |
|---|---|---|
empty[get]
|
bool | True when the polygon contains no rings. |
exterior[get]
|
const(LinearRing2View!T) | Returns the exterior ring by value. |
holeCount[get]
|
size_t | Number of interior rings. |
length[get]
|
size_t | Number of rings, including the exterior ring when present. |
Methods
| Name | Description |
|---|---|
hole
(index)
|
Returns one interior ring by zero-based hole index. |
opIndex
(index)
|
Returns one ring descriptor by value. |
Example
Example using structural exterior and hole ring roles.
import geo;
alias P = Point2!double;
alias R = LinearRing2View!double;
alias G = Polygon2View!double;
P[4] exteriorPoints = [
P(0.0, 0.0),
P(10.0, 0.0),
P(10.0, 10.0),
P(0.0, 10.0)
];
P[4] holePoints = [
P(2.0, 2.0),
P(4.0, 2.0),
P(4.0, 4.0),
P(2.0, 4.0)
];
R[2] rings = [
R(exteriorPoints[]),
R(holePoints[])
];
auto polygon =
G(rings[]);
assert(!polygon .empty);
assert(polygon .length == 2);
assert(polygon .holeCount == 1);
assert(
polygon[0][0] ==
P(0.0, 0.0)
);
assert(
polygon .exterior[2] ==
P(10.0, 10.0)
);
assert(
polygon .hole(0)[1] ==
P(4.0, 2.0)
);