Function polylineLength
Euclidean length of a polyline.
MetricScalar!T polylineLength(T)(
Polyline2View!T polyline
) pure nothrow @nogc @safe
if (isGeoScalar!T);
The result is the sum of the lengths of all consecutive segments in stored point order.
Empty and singleton polylines have length zero.
Uses the same MetricScalar policy as segmentLength().
Segment lengths are accumulated in stored order in MetricScalar!T using Kahan-style compensated summation to reduce floating-point accumulation error.
Compensation improves mixed-scale sums but does not make the result exact, correctly rounded, or independent of segment order. Each segment length remains an ordinary floating-point metric computation.
Non-finite segment lengths and accumulated overflow propagate according to normal floating-point arithmetic. The accumulated result may therefore be NaN or infinity.
No allocation or point copying is performed.
Complexity
O(n) time and O(1) auxiliary space for n stored points.
Example
Example summing the lengths of consecutive polyline segments.
import geo;
alias P = Point2!double;
P[3] points = [
P(0.0, 0.0),
P(3.0, 4.0),
P(6.0, 8.0)
];
const polyline =
Polyline2View!double(points[]);
assert(polylineLength(polyline) == 10.0);