brutal/brutal.numerics/Brutal.Numerics/Vector/float4/float4.math-metric.gen.cs
2026-10-15 14:12:02 +13:00

62 lines
1.8 KiB
C#

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