Function tryIntersectGeodesicSegments

Find whether two finite geographic route segments cross or overlap.

bool tryIntersectGeodesicSegments(T)(
  const Geodesic!T solver,
  const GeographicCoordinate!T firstStart,
  const GeographicCoordinate!T firstEnd,
  const GeographicCoordinate!T secondStart,
  const GeographicCoordinate!T secondEnd,
  out GeodesicSegmentIntersectionResult!T result
) pure nothrow @nogc @safe
if (isGeodesyScalar!T);

Give the start and end of each segment. The result distinguishes no shared point (none), one crossing (point), and a shared stretch (overlap). Two valid segments that do not meet are still a successful calculation: the function returns true with result.kind == none.

Exact coincident endpoints are rejected as degenerate segments. Exact antipodes and detected equal-and-opposite-latitude multiple-shortest solutions are rejected because the shortest geodesic is not unique.

Parameters

NameDescription
solver Valid prepared geodesic solver.
firstStart First segment start.
firstEnd First segment end.
secondStart Second segment start.
secondEnd Second segment end.
result Receives none, point, or overlap.

Returns

true when the bounded intersection problem was evaluated successfully, including the geometrically disjoint case. Returns false for invalid/degenerate/ambiguous segment input or numerical non-convergence. On failure result is .init.

Example

Example finding one ordinary bounded-segment crossing.

const solver =
    Geodesic!double.fromEllipsoid(
        wgs84!double());

const firstStart =
    GeographicCoordinate!double.fromComponents(
        Latitude!double.fromDegrees(0.0),
        Longitude!double.fromDegrees(-10.0));

const firstEnd =
    GeographicCoordinate!double.fromComponents(
        Latitude!double.fromDegrees(0.0),
        Longitude!double.fromDegrees(10.0));

const secondStart =
    GeographicCoordinate!double.fromComponents(
        Latitude!double.fromDegrees(-10.0),
        Longitude!double.fromDegrees(0.0));

const secondEnd =
    GeographicCoordinate!double.fromComponents(
        Latitude!double.fromDegrees(10.0),
        Longitude!double.fromDegrees(0.0));

GeodesicSegmentIntersectionResult!double result;

assert(tryIntersectGeodesicSegments(
    solver,
    firstStart,
    firstEnd,
    secondStart,
    secondEnd,
    result));

assert(result.kind
    == GeodesicSegmentIntersectionKind.point);