Function classifyPolygonRelationship
Classifies the reduced exact topological relationship of two polygons.
PolygonRelationshipResult classifyPolygonRelationship(T)(
scope Polygon2View!T first,
scope Polygon2View!T second
) @safe
if (isPolygonRelationshipScalar!T);
Both inputs are validated. Invalid geometry is reported through
PolygonRelationshipStatus or
PolygonRelationshipStatus; it is never repaired
implicitly. When both operands are invalid, the first operand is reported
first.
Supported scalar domains are int, long, float, and double.
Empty polygons are valid. Empty versus empty succeeds with all five
relationship facts false. Empty versus a non-empty polygon reports only
hasSecondOnlyInterior; the reversed operand order reports only
hasFirstOnlyInterior.
Classification reuses the exact noding, arrangement, operand provenance, half-edge embedding, and A/B side-label machinery shared with polygon union. It reduces that exact topology directly and does not construct union boundaries, components, or rounded/materialized result coordinates.
The operation may allocate variable-size temporary topology workspace and
is deliberately not @nogc. Allocation/resource exhaustion follows normal
D runtime failure semantics and is not a geometric relationship status.
The current correctness-first implementation has a conservative documented worst-case upper bound of O(n^4) time or better in the total input boundary-edge count. This is an implementation bound, not a promise that future implementations retain that complexity.
Swapping first and second exchanges only
hasFirstOnlyInterior and hasSecondOnlyInterior. The shared-interior,
boundary-contact, and boundary-overlap facts are symmetric.
Parameters
| Name | Description |
|---|---|
| first | first polygon operand |
| second | second polygon operand |
Returns
A checked relationship-classification result.
Example
Example classifying two adjacent polygons through the public root API.
import geo;
alias P = Point2!int;
alias R = LinearRing2View!int;
alias G = Polygon2View!int;
P[4] firstPoints = [
P(0, 0),
P(2, 0),
P(2, 2),
P(0, 2),
];
P[4] secondPoints = [
P(2, 0),
P(4, 0),
P(4, 2),
P(2, 2),
];
R[1] firstRings = [
R(firstPoints[])
];
R[1] secondRings = [
R(secondPoints[])
];
const first =
G(firstRings[]);
const second =
G(secondRings[]);
const result =
classifyPolygonRelationship(
first: first,
second: second
);
assert(result .succeeded);
const relationship =
result .relationship;
assert(relationship .hasFirstOnlyInterior);
assert(relationship .hasSecondOnlyInterior);
assert(!relationship .hasSharedInterior);
assert(relationship .hasBoundaryContact);
assert(relationship .hasBoundaryOverlap);
/*
* The same public operation supports UFCS with the first polygon as the
* receiver.
*/
const ufcsResult =
first .classifyPolygonRelationship(
second
);
assert(
ufcsResult .relationship ==
relationship
);