Function classifySegmentPolygonRelationship

Classifies a closed segment relative to a prevalidated polygon.

SegmentPolygonRelationship classifySegmentPolygonRelationship(T)(
  Segment2!T segment,
  scope Polygon2View!T polygon
) pure nothrow @nogc @safe
if (is(T == int) || is(T == long) || is(T == float) || is(T == double));

Supported scalar types are int, long, float, and double. real is deliberately outside the robust topology domain.

Preconditions

- polygon is valid according to validatePolygon(polygon).valid; - for floating scalar domains, both segment endpoints are finite.

Polygon validation is deliberately outside this query. This permits one validated polygon to be reused for many segment queries without repeating validation work.

An empty polygon is valid. Every finite segment against an empty polygon has hasExterior == true and all other facts false.

A degenerate segment represents one point. Exactly one of hasExterior, hasBoundary, or hasInterior is then true, and hasBoundaryOverlap is false.

Topological decisions are exact. No epsilon, rounded proper-intersection coordinate, event sorting, or polygon-pair arrangement is used.

No allocation is performed.

Reversing segment endpoints does not change the result. Reversing any ring of a valid polygon does not change the result.

Complexity

O(n) time and O(1) auxiliary space for n represented polygon boundary edges.

Returns

The four reduced existential relationship facts.

Example

Example classifying a road-like segment that crosses a polygonal area.

import geo;

alias P = Point2!double;
alias R = LinearRing2View!double;
alias G = Polygon2View!double;
alias S = Segment2!double;

P[4] points = [
    P(0.0, 0.0),
    P(10.0, 0.0),
    P(10.0, 10.0),
    P(0.0, 10.0)
];

R[1] rings = [
    R(points[])
];

const G polygon =
    G(rings[]);

const S segment =
    S(
        P(-5.0, 5.0),
        P(15.0, 5.0)
    );

const relationship =
    segment.classifySegmentPolygonRelationship(
        polygon
    );

assert(relationship.hasExterior);
assert(relationship.hasBoundary);
assert(relationship.hasInterior);
assert(!relationship.hasBoundaryOverlap);