Function segmentIntersectionKind

Classifies the exact topological intersection of two closed segments.

SegmentIntersectionKind segmentIntersectionKind(T)(
  Segment2!T first,
  Segment2!T second
) pure nothrow @nogc @safe
if (isIntersectionScalar!T);

Supported scalar types:

int long float double

For floating-point coordinates all endpoint coordinates must be finite.

The operation returns only topology. It deliberately does not construct an intersection coordinate.

Degenerate segments are valid and represent a point.

No allocation is performed.

Complexity

time O(1) space O(1)

Example

Example classifying closed-segment intersections without construction.

import geo;

alias P = Point2!int;
alias S = Segment2!int;
alias K = SegmentIntersectionKind;

assert(
    segmentIntersectionKind(
        S(P(0, 0), P(4, 0)),
        S(P(0, 2), P(4, 2))
    ) ==
    K.none
);

assert(
    segmentIntersectionKind(
        S(P(0, 0), P(4, 4)),
        S(P(0, 4), P(4, 0))
    ) ==
    K.point
);

assert(
    segmentIntersectionKind(
        S(P(0, 0), P(6, 0)),
        S(P(2, 0), P(8, 0))
    ) ==
    K.overlap
);