Function squaredNorm

Computes the squared Euclidean norm of a vector.

MetricScalar!T squaredNorm(T)(
  Vector2!T vector
) pure nothrow @nogc @safe
if (isGeoScalar!T);

Returns

The squared norm in MetricScalar!T.

The numerical construction is the same as dot(vector, vector). Integral input is therefore metric floating-point arithmetic rather than exact integral accumulation.

Very large finite input may produce infinity. NaN and infinity otherwise follow ordinary floating-point arithmetic.

This is a numerical vector operation, not a robust exact predicate.

No allocation is performed.

Complexity

O(1) time and O(1) auxiliary space.

Example

Example computing a squared vector norm through the public package API.

import geo;

auto vector = Vector2!int(3, 4);

static assert(
    is(typeof(squaredNorm(vector)) == double)
);

assert(squaredNorm(vector) == 25.0);