mirror of
https://github.com/ahwootech/BRUTAL.git
synced 2026-11-25 20:48:24 +01:00
62 lines
1.8 KiB
C#
62 lines
1.8 KiB
C#
// <auto-generated /> - edit Vector.math-metric.tt to modify
|
|
#nullable enable
|
|
|
|
namespace Brutal.Numerics;
|
|
|
|
public partial struct float2
|
|
{
|
|
/// <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="Vector2.Distance" />
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public static float Distance(float2 a, float2 b)
|
|
{
|
|
return float.Sqrt(DistanceSquared(a, b));
|
|
}
|
|
|
|
/// <inheritdoc cref="Vector2.DistanceSquared" />
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public static float DistanceSquared(float2 a, float2 b)
|
|
{
|
|
var difference = a - b;
|
|
return Dot(difference, difference);
|
|
}
|
|
|
|
/// <inheritdoc cref="Vector2.Dot" />
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public static float Dot(float2 a, float2 b)
|
|
{
|
|
return a.X * b.X + a.Y * b.Y;
|
|
}
|
|
|
|
/// <inheritdoc cref="Vector2.Normalize" />
|
|
/// <exception cref="DivideByZeroException">Thrown when the input vector is a zero vector.</exception>
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public static float2 Normalize(float2 value)
|
|
{
|
|
var lengthSquared = Dot(value, value);
|
|
if (lengthSquared == 0)
|
|
throw new DivideByZeroException();
|
|
return value / float.Sqrt(lengthSquared);
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public static float2 NormalizeOrZero(float2 value)
|
|
{
|
|
var length = float.Sqrt(Dot(value, value));
|
|
return length == 0 ? Zero : value / length;
|
|
}
|
|
}
|