Function squaredDistance
Squared Euclidean distance between two points.
MetricScalar!T squaredDistance(T)(
Point2!T a,
Point2!T b
) pure nothrow @nogc @safe
if (isGeoScalar!T);
Returns
The squared distance in MetricScalar!T.
Integer coordinate geometry is converted to floating-point metric arithmetic after each component difference has been obtained without signed overflow.
This operation does not promise exact integral arithmetic. In particular, long-coordinate results may lose precision after conversion to double.
Floating-point NaN and infinity are not rejected. Results follow normal floating-point arithmetic. Very large finite results may overflow to infinity.
This function is a metric computation, not a robust exact distance comparison predicate.
No allocation is performed.
Complexity
O(1) time and O(1) auxiliary space.
Example
Example computing squared distance without taking a square root.
import geo;
const a = Point2!int(0, 0);
const b = Point2!int(3, 4);
static assert(
is(typeof(squaredDistance(a, b)) == double)
);
assert(
squaredDistance(a, b) == 25.0
);