Function polygonUnion
Constructs the regularized two-dimensional union of two polygons.
PolygonUnionResult polygonUnion(T)(
scope Polygon2View!T first,
scope Polygon2View!T second
) @safe
if (isPolygonUnionScalar!T);
Both inputs are validated. Invalid geometry is reported through
PolygonUnionStatus or
PolygonUnionStatus; it is never repaired implicitly.
When both operands are invalid, the first operand is reported first.
Supported input scalar domains are int, long, float, and
double. Robust real support remains outside this contract.
Constructed coordinates follow the existing IntersectionScalar!T
construction policy and are currently double for every supported input
scalar.
Exact topology remains authoritative until the selected result boundary is
materialized. If binary64 materialization cannot preserve the required
exact result topology, the returned status is
PolygonUnionStatus and no partial geometry is
exposed.
The operation allocates variable-size workspace and immutable result
storage. It is deliberately not @nogc. Allocation/resource exhaustion
follows normal D runtime failure semantics and is not a polygon-union
geometry status. This includes a workspace cardinality that cannot be
represented by size_t; such an impossible allocation size follows the
same OutOfMemoryError resource-failure path rather than becoming a
checked geometry result.
The current implementation is the correctness-first exact-overlay baseline. Its worst-case time may reach O(n^4) in the total input boundary-edge count because output-topology verification is itself quadratic. This is a baseline implementation bound, not a promise that future implementations retain that complexity.
Parameters
| Name | Description |
|---|---|
| first | first polygon operand |
| second | second polygon operand |
Returns
A checked immutable owning result.
Example
Example constructing a polygon union through the public owning result API.
import geo;
alias P = Point2!int;
alias R = LinearRing2View!int;
alias G = Polygon2View!int;
P[4] outerPoints = [
P(0, 0),
P(8, 0),
P(8, 8),
P(0, 8),
];
P[4] innerPoints = [
P(2, 2),
P(4, 2),
P(4, 4),
P(2, 4),
];
R[1] outerRings = [
R(outerPoints[])
];
R[1] innerRings = [
R(innerPoints[])
];
const result =
polygonUnion(
first: G(outerRings[]),
second: G(innerRings[])
);
assert(result .succeeded);
assert(result .status == PolygonUnionStatus .success);
assert(result .length == 1);
const component =
result[0];
assert(component .holeCount == 0);
assert(
component .exterior[0] ==
Point2!double(0.0, 0.0)
);