Struct GeodesicPolygonAccumulator

Build a geographic polygon one vertex at a time and measure it.

struct GeodesicPolygonAccumulator(T)
  
if (isGeodesyScalar!T);

Use this accumulator when polygon vertices arrive as a stream or when you do not want to store all vertices. Add vertices in boundary order. compute (or checked tryCompute) returns perimeter and signed area, including the closing edge back to the first vertex. Computing does not modify the accumulator.

Only the first and most recent vertices are retained; no dynamic vertex storage is used.

.init is invalid. Prepare from a valid Geodesic!T.

Properties

NameTypeDescription
isValid[get] boolTrue when this accumulator has a valid prepared geodesic solver.
pointCount[get] size_tNumber of vertices currently accumulated.

Methods

NameDescription
addPoint (point) Add the next polygon corner in boundary order.
compute () Return the closed polygon's perimeter and signed area.
fromGeodesic (solver) Prepare an empty polygon accumulator.
tryAddPoint (point) Add the next polygon corner without throwing.
tryCompute (result) Measure the polygon's complete perimeter and signed area without throwing.
tryFromGeodesic (solver, result) Prepare an empty polygon accumulator without throwing.

Example

Example validating winding symmetry for a closed geodesic polygon.

import std.math : fabs;

const solver =
    Geodesic!double.fromEllipsoid(
        Ellipsoid!double.sphere(
            6_371_000.0));

auto ccw =
    GeodesicPolygonAccumulator!double.fromGeodesic(
        solver);

auto cw =
    GeodesicPolygonAccumulator!double.fromGeodesic(
        solver);

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

const p1 =
    GeographicCoordinate!double.fromComponents(
        Latitude!double.fromDegrees(0.0),
        Longitude!double.fromDegrees(1.0));

const p2 =
    GeographicCoordinate!double.fromComponents(
        Latitude!double.fromDegrees(1.0),
        Longitude!double.fromDegrees(0.0));

ccw.addPoint(p0);
ccw.addPoint(p1);
ccw.addPoint(p2);

cw.addPoint(p0);
cw.addPoint(p2);
cw.addPoint(p1);

double closingDistance;
double closingArea;
int closingCrossing;

assert(
    ccw.edge(
        p2,
        p0,
        closingDistance,
        closingArea,
        closingCrossing));

assert(isFiniteGeodesyScalar(closingDistance));
assert(isFiniteGeodesyScalar(closingArea));

GeodesicPolygonResult!double ccwResult;
GeodesicPolygonResult!double cwResult;

assert(ccw.tryCompute(ccwResult));
assert(cw.tryCompute(cwResult));

assert(ccwResult.perimeter > 0.0);
assert(
    fabs(
        ccwResult.perimeter
            - cwResult.perimeter)
    < 1.0e-8);

assert(ccwResult.signedArea > 0.0);
assert(cwResult.signedArea < 0.0);

assert(
    fabs(
        ccwResult.signedArea
            + cwResult.signedArea)
    < 1.0e-3);