// - edit Vector.math-metric.tt to modify
#nullable enable
namespace Brutal.Numerics;
public partial struct double3
{
///
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public readonly double Length()
{
return double.Sqrt(LengthSquared());
}
///
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public readonly double LengthSquared()
{
return Dot(this, this);
}
///
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static double Distance(double3 a, double3 b)
{
return double.Sqrt(DistanceSquared(a, b));
}
///
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static double DistanceSquared(double3 a, double3 b)
{
var difference = a - b;
return Dot(difference, difference);
}
///
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static double Dot(double3 a, double3 b)
{
return a.X * b.X + a.Y * b.Y + a.Z * b.Z;
}
///
/// Thrown when the input vector is a zero vector.
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static double3 Normalize(double3 value)
{
var lengthSquared = Dot(value, value);
if (lengthSquared == 0)
throw new DivideByZeroException();
return value / double.Sqrt(lengthSquared);
}
///
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static double3 NormalizeOrZero(double3 value)
{
var length = double.Sqrt(Dot(value, value));
return length == 0 ? Zero : value / length;
}
}