This commit is contained in:
Rian Drake 2026-10-15 14:09:11 +13:00
commit b578433e37
11 changed files with 784842 additions and 0 deletions

View file

@ -0,0 +1,28 @@
// <auto-generated /> - edit Vector.copy.tt to modify
#nullable enable
namespace Brutal.Numerics;
public partial struct float2
{
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public readonly void CopyTo(Span<float> destination)
{
if (destination.Length < ComponentCount)
throw new ArgumentException("Length must be at least 2.", nameof(destination));
Unsafe.WriteUnaligned(ref Unsafe.As<float, byte>(ref MemoryMarshal.GetReference(destination)), this);
}
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public readonly bool TryCopyTo(Span<float> destination)
{
if (destination.Length < ComponentCount)
return false;
Unsafe.WriteUnaligned(ref Unsafe.As<float, byte>(ref MemoryMarshal.GetReference(destination)), this);
return true;
}
}

View file

@ -0,0 +1,41 @@
// <auto-generated /> - edit Vector.equality.tt to modify
#nullable enable
namespace Brutal.Numerics;
public partial struct float2
{
/// <inheritdoc />
public readonly override int GetHashCode()
{
return HashCode.Combine(X, Y);
}
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public readonly bool Equals(float2 other)
{
return X.Equals(other.X) && Y.Equals(other.Y);
}
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public readonly override bool Equals([NotNullWhen(true)] object? obj)
{
return obj is float2 other && Equals(other);
}
/// <summary>IEEE lane-wise equality over every component: any NaN component makes this false (contrast <see cref="Equals(float2)" />, which is NaN-reflexive), and -0 equals +0.</summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool operator ==(float2 a, float2 b)
{
return a.X == b.X && a.Y == b.Y;
}
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool operator !=(float2 a, float2 b)
{
return !(a == b);
}
}

View file

@ -0,0 +1,92 @@
// <auto-generated /> - edit Vector.format.tt to modify
#nullable enable
namespace Brutal.Numerics;
public partial struct float2 : ISpanFormattable, IUtf8SpanFormattable, ISpanParsable<float2>
{
/// <inheritdoc />
public readonly override string ToString()
{
return ToString("G", CultureInfo.CurrentCulture);
}
/// <inheritdoc cref="Vector2.ToString(string?)" />
public readonly string ToString(string? format)
{
return ToString(format, CultureInfo.CurrentCulture);
}
/// <inheritdoc />
public readonly string ToString(string? format, IFormatProvider? formatProvider)
{
var separator = NumberFormatInfo.GetInstance(formatProvider).NumberGroupSeparator;
return $"<{X.ToString(format, formatProvider)}{separator} {Y.ToString(format, formatProvider)}>";
}
/// <inheritdoc />
public readonly bool TryFormat(Span<char> destination, out int charsWritten, ReadOnlySpan<char> format, IFormatProvider? provider)
{
return StringHelpers.TryFormat<float2, float>(this, destination, out charsWritten, format, provider);
}
/// <inheritdoc />
public readonly bool TryFormat(Span<byte> destination, out int bytesWritten, ReadOnlySpan<char> format, IFormatProvider? provider)
{
return StringHelpers.TryFormat<float2, float>(this, destination, out bytesWritten, format, provider);
}
/// <inheritdoc cref="Parse(ReadOnlySpan{char}, NumberStyles, IFormatProvider?)" />
public static float2 Parse(string s, IFormatProvider? provider)
{
ArgumentNullException.ThrowIfNull(s);
return Parse(s.AsSpan(), NumberStyles.Float, provider);
}
/// <inheritdoc cref="Parse(ReadOnlySpan{char}, NumberStyles, IFormatProvider?)" />
public static float2 Parse(ReadOnlySpan<char> s, IFormatProvider? provider = null)
{
return Parse(s, NumberStyles.Float, provider);
}
/// <inheritdoc cref="Parse(ReadOnlySpan{char}, NumberStyles, IFormatProvider?)" />
public static float2 Parse(string s, NumberStyles style, IFormatProvider? provider)
{
ArgumentNullException.ThrowIfNull(s);
return Parse(s.AsSpan(), style, provider);
}
/// <summary>Parses from the <see cref="ToString()" /> format, <c>&lt;1, 2, 3&gt;</c>.</summary>
/// <exception cref="FormatException">The input is not in a valid format, or a component fails to parse.</exception>
public static float2 Parse(ReadOnlySpan<char> s, NumberStyles style, IFormatProvider? provider)
{
if (!TryParse(s, style, provider, out var result))
throw new FormatException($"'{s}' is not in a valid float2 format.");
return result;
}
/// <inheritdoc cref="TryParse(ReadOnlySpan{char}, NumberStyles, IFormatProvider?, out float2)" />
public static bool TryParse([NotNullWhen(true)] string? s, IFormatProvider? provider, out float2 result)
{
return TryParse(s.AsSpan(), NumberStyles.Float, provider, out result);
}
/// <inheritdoc cref="TryParse(ReadOnlySpan{char}, NumberStyles, IFormatProvider?, out float2)" />
public static bool TryParse(ReadOnlySpan<char> s, IFormatProvider? provider, out float2 result)
{
return TryParse(s, NumberStyles.Float, provider, out result);
}
/// <inheritdoc cref="TryParse(ReadOnlySpan{char}, NumberStyles, IFormatProvider?, out float2)" />
public static bool TryParse([NotNullWhen(true)] string? s, NumberStyles style, IFormatProvider? provider, out float2 result)
{
return TryParse(s.AsSpan(), style, provider, out result);
}
/// <summary>Parses from the <see cref="ToString()" /> format, <c>&lt;1, 2, 3&gt;</c>.</summary>
/// <returns>true if the input parsed as a float2.</returns>
public static bool TryParse(ReadOnlySpan<char> s, NumberStyles style, IFormatProvider? provider, out float2 result)
{
return StringHelpers.TryParse<float2, float>(s, style, provider, out result);
}
}

View file

@ -0,0 +1,107 @@
// <auto-generated /> - edit Vector.tt to modify
#nullable enable
namespace Brutal.Numerics;
/// <summary>
/// Implements a 2D vector with float components.
/// </summary>
[DebuggerTypeProxy(typeof(VectorDebugView2<float2, float, float>))]
public partial struct float2 : IVector2<float2, float>
, IFloatingVector<float2, float>
, IFloatingVector2<float2, float, floatQuat, float3x2, float4x4>
{
/// <inheritdoc />
public static int ComponentSize => sizeof(float);
/// <summary>Gets the number of components.</summary>
public static int ComponentCount => 2;
/// <inheritdoc cref="Vector2.X" />
[XmlAttribute]
public float X;
/// <inheritdoc cref="Vector2.Y" />
[XmlAttribute]
public float Y;
float IVector2<float2, float>.X { readonly get => X; set => X = value; }
float IVector2<float2, float>.Y { readonly get => Y; set => Y = value; }
/// <inheritdoc cref="Vector2(float, float)" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public float2(float x, float y)
{
X = x;
Y = y;
}
/// <inheritdoc cref="Vector2(float)" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public float2(float xy)
: this(xy, xy) { }
/// <summary>Creates a vector from the leading 2 elements of a span.</summary>
/// <param name="span">The elements to read; must contain at least 2, and any beyond that are ignored.</param>
/// <exception cref="ArgumentOutOfRangeException"><paramref name="span" /> holds fewer than 2 elements.</exception>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public float2(ReadOnlySpan<float> span)
{
if (span.Length < 2)
throw new ArgumentOutOfRangeException(nameof(span), "Length must be at least 2.");
this = Unsafe.ReadUnaligned<float2>(ref Unsafe.As<float, byte>(ref MemoryMarshal.GetReference(span)));
}
/// <inheritdoc cref="float2(ReadOnlySpan{float})" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static float2 IComponentTuple<float2, float>.Create(ReadOnlySpan<float> span) => new(span);
/// <inheritdoc />
public static float2 UnitX => new(1, 0);
/// <inheritdoc />
public static float2 UnitY => new(0, 1);
/// <inheritdoc />
public float this[int index]
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
readonly get
{
if ((uint)index >= ComponentCount)
throw new ArgumentOutOfRangeException(nameof(index));
return Unsafe.Add(ref Unsafe.AsRef(in X), index);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
set
{
if ((uint)index >= ComponentCount)
throw new ArgumentOutOfRangeException(nameof(index));
Unsafe.Add(ref X, index) = value;
}
}
public readonly void Deconstruct(out float x, out float y)
{
x = X;
y = Y;
}
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public Span<float> AsSpan()
{
return MemoryMarshal.CreateSpan(ref Unsafe.As<float2, float>(ref this), 2);
}
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public readonly ReadOnlySpan<float> AsReadOnlySpan()
{
return MemoryMarshal.CreateReadOnlySpan(in Unsafe.As<float2, float>(ref Unsafe.AsRef(in this)), 2);
}
}

View file

@ -0,0 +1,62 @@
// <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;
}
}

View file

@ -0,0 +1,60 @@
// <auto-generated /> - edit Vector.math.tt to modify
#nullable enable
namespace Brutal.Numerics;
public partial struct float2
{
/// <inheritdoc cref="Vector2.Reflect" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float2 Reflect(float2 vector, float2 normal)
{
return vector - 2 * Dot(vector, normal) * normal;
}
/// <inheritdoc cref="Vector2.Transform(Vector2, Matrix3x2)" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float2 Transform(float2 position, float3x2 matrix)
{
var result = matrix.X * position.X;
result += matrix.Y * position.Y;
result += matrix.Z;
return result;
}
/// <inheritdoc cref="Vector2.Transform(Vector2, Matrix4x4)" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float2 Transform(float2 position, float4x4 matrix)
{
return float4.Transform(position, matrix).XY;
}
/// <inheritdoc cref="Vector2.Transform(Vector2, Quaternion)" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float2 Transform(float2 value, floatQuat rotation)
{
return float4.Transform(value, rotation).XY;
}
/// <inheritdoc cref="Vector2.TransformNormal(Vector2, Matrix3x2)" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float2 TransformNormal(float2 normal, float3x2 matrix)
{
var result = matrix.X * normal.X;
result += matrix.Y * normal.Y;
return result;
}
/// <inheritdoc cref="Vector2.TransformNormal(Vector2, Matrix4x4)" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float2 TransformNormal(float2 normal, float4x4 matrix)
{
var result = matrix.X * normal.X;
result += matrix.Y * normal.Y;
return result.XY;
}
}

View file

@ -0,0 +1,54 @@
// <auto-generated /> - edit Vector.numerics-binary.tt to modify
#nullable enable
namespace Brutal.Numerics;
// IBinaryNumber
public partial struct float2 : IBinaryNumber<float2>
{
/// <summary>Determines if every component of a value is a power of two.</summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static bool IBinaryNumber<float2>.IsPow2(float2 value)
{
return float.IsPow2(value.X) && float.IsPow2(value.Y);
}
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static float2 IBitwiseOperators<float2, float2, float2>.operator &(float2 a, float2 b)
{
return Unsafe.BitCast<int2, float2>(Unsafe.BitCast<float2, int2>(a) & Unsafe.BitCast<float2, int2>(b));
}
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static float2 IBitwiseOperators<float2, float2, float2>.operator |(float2 a, float2 b)
{
return Unsafe.BitCast<int2, float2>(Unsafe.BitCast<float2, int2>(a) | Unsafe.BitCast<float2, int2>(b));
}
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static float2 IBitwiseOperators<float2, float2, float2>.operator ^(float2 a, float2 b)
{
return Unsafe.BitCast<int2, float2>(Unsafe.BitCast<float2, int2>(a) ^ Unsafe.BitCast<float2, int2>(b));
}
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static float2 IBitwiseOperators<float2, float2, float2>.operator ~(float2 value)
{
return Unsafe.BitCast<int2, float2>(~Unsafe.BitCast<float2, int2>(value));
}
}
// the componentwise predicate mask (no interface to mirror) - the per-lane truth IsPow2 collapses
public partial struct float2
{
/// <summary>Determines which components of a value are powers of two.</summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool2 IsPow2(float2 value)
{
return new bool2(float.IsPow2(value.X), float.IsPow2(value.Y));
}
}

View file

@ -0,0 +1,445 @@
// <auto-generated /> - edit Vector.numerics-floating.tt to modify
#nullable enable
namespace Brutal.Numerics;
// IFloatingPointConstants
public partial struct float2 : IFloatingPointConstants<float2>
{
/// <inheritdoc />
public static float2 E => new(float.E);
/// <inheritdoc />
public static float2 Pi => new(float.Pi);
/// <inheritdoc />
public static float2 Tau => new(float.Tau);
}
// IExponentialFunctions
public partial struct float2 : IExponentialFunctions<float2>
{
/// <inheritdoc />
/// <remarks>NOTE: the vectorized float kernel is not exact at zero.
/// It returns 1 ulp above <c>One</c>, so <c>Exp(Zero)</c> does not give back <c>One</c>.
/// Legal under the vectorized-math accuracy contract, and the double kernel is exact.
/// Upstream: https://github.com/dotnet/runtime/issues/118841.</remarks>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float2 Exp(float2 value)
{
return new(float.Exp(value.X), float.Exp(value.Y));
}
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float2 Exp2(float2 value)
{
return new float2(float.Exp2(value.X), float.Exp2(value.Y));
}
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float2 Exp10(float2 value)
{
return new float2(float.Exp10(value.X), float.Exp10(value.Y));
}
}
// ILogarithmicFunctions
public partial struct float2 : ILogarithmicFunctions<float2>
{
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float2 Log(float2 value)
{
return new(float.Log(value.X), float.Log(value.Y));
}
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float2 Log(float2 value, float2 newBase)
{
return new float2(float.Log(value.X, newBase.X), float.Log(value.Y, newBase.Y));
}
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float2 Log2(float2 value)
{
return new(float.Log2(value.X), float.Log2(value.Y));
}
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float2 Log10(float2 value)
{
return new float2(float.Log10(value.X), float.Log10(value.Y));
}
}
// IPowerFunctions
public partial struct float2 : IPowerFunctions<float2>
{
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float2 Pow(float2 value, float2 power)
{
return new float2(float.Pow(value.X, power.X), float.Pow(value.Y, power.Y));
}
}
// IRootFunctions
public partial struct float2 : IRootFunctions<float2>
{
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float2 Cbrt(float2 value)
{
return new float2(float.Cbrt(value.X), float.Cbrt(value.Y));
}
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float2 Hypot(float2 a, float2 b)
{
return new(float.Hypot(a.X, b.X), float.Hypot(a.Y, b.Y));
}
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float2 RootN(float2 value, int n)
{
return new float2(float.RootN(value.X, n), float.RootN(value.Y, n));
}
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float2 Sqrt(float2 value)
{
return new(float.Sqrt(value.X), float.Sqrt(value.Y));
}
}
// ITrigonometricFunctions
public partial struct float2 : ITrigonometricFunctions<float2>
{
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float2 Sin(float2 value)
{
return new(float.Sin(value.X), float.Sin(value.Y));
}
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float2 Cos(float2 value)
{
return new(float.Cos(value.X), float.Cos(value.Y));
}
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static (float2 Sin, float2 Cos) SinCos(float2 value)
{
var (sinX, cosX) = float.SinCos(value.X);
var (sinY, cosY) = float.SinCos(value.Y);
return (new(sinX, sinY), new(cosX, cosY));
}
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float2 Tan(float2 value)
{
return new float2(float.Tan(value.X), float.Tan(value.Y));
}
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float2 Asin(float2 value)
{
return new float2(float.Asin(value.X), float.Asin(value.Y));
}
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float2 Acos(float2 value)
{
return new float2(float.Acos(value.X), float.Acos(value.Y));
}
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float2 Atan(float2 value)
{
return new float2(float.Atan(value.X), float.Atan(value.Y));
}
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float2 SinPi(float2 value)
{
return new float2(float.SinPi(value.X), float.SinPi(value.Y));
}
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float2 CosPi(float2 value)
{
return new float2(float.CosPi(value.X), float.CosPi(value.Y));
}
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float2 TanPi(float2 value)
{
return new float2(float.TanPi(value.X), float.TanPi(value.Y));
}
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float2 AsinPi(float2 value)
{
return new float2(float.AsinPi(value.X), float.AsinPi(value.Y));
}
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float2 AcosPi(float2 value)
{
return new float2(float.AcosPi(value.X), float.AcosPi(value.Y));
}
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float2 AtanPi(float2 value)
{
return new float2(float.AtanPi(value.X), float.AtanPi(value.Y));
}
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static (float2 SinPi, float2 CosPi) SinCosPi(float2 value)
{
return (SinPi(value), CosPi(value));
}
/// <inheritdoc cref="float.DegreesToRadians" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float2 DegreesToRadians(float2 degrees)
{
return new(float.DegreesToRadians(degrees.X), float.DegreesToRadians(degrees.Y));
}
/// <inheritdoc cref="float.RadiansToDegrees" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float2 RadiansToDegrees(float2 radians)
{
return new(float.RadiansToDegrees(radians.X), float.RadiansToDegrees(radians.Y));
}
}
// IHyperbolicFunctions
public partial struct float2 : IHyperbolicFunctions<float2>
{
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float2 Sinh(float2 value)
{
return new float2(float.Sinh(value.X), float.Sinh(value.Y));
}
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float2 Cosh(float2 value)
{
return new float2(float.Cosh(value.X), float.Cosh(value.Y));
}
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float2 Tanh(float2 value)
{
return new float2(float.Tanh(value.X), float.Tanh(value.Y));
}
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float2 Asinh(float2 value)
{
return new float2(float.Asinh(value.X), float.Asinh(value.Y));
}
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float2 Acosh(float2 value)
{
return new float2(float.Acosh(value.X), float.Acosh(value.Y));
}
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float2 Atanh(float2 value)
{
return new float2(float.Atanh(value.X), float.Atanh(value.Y));
}
}
// IFloatingPoint
public partial struct float2 : IFloatingPoint<float2>
{
/// <inheritdoc cref="float.Floor(float)" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float2 Floor(float2 value)
{
return new(float.Floor(value.X), float.Floor(value.Y));
}
/// <inheritdoc cref="float.Ceiling(float)" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float2 Ceiling(float2 value)
{
return new(float.Ceiling(value.X), float.Ceiling(value.Y));
}
/// <inheritdoc cref="float.Round(float)" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float2 Round(float2 value)
{
return new(float.Round(value.X), float.Round(value.Y));
}
/// <inheritdoc cref="float.Truncate(float)" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float2 Truncate(float2 value)
{
return new(float.Truncate(value.X), float.Truncate(value.Y));
}
/// <inheritdoc cref="float.Round(float, int, MidpointRounding)" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float2 Round(float2 value, int digits, MidpointRounding mode)
{
return new float2(float.Round(value.X, digits, mode), float.Round(value.Y, digits, mode));
}
// One exponent and significand PER LANE, so there is no single honest answer: explicit and throwing.
int IFloatingPoint<float2>.GetExponentByteCount() =>
throw new NotSupportedException($"{nameof(float2)} has one exponent per component.");
int IFloatingPoint<float2>.GetExponentShortestBitLength() =>
throw new NotSupportedException($"{nameof(float2)} has one exponent per component.");
int IFloatingPoint<float2>.GetSignificandBitLength() =>
throw new NotSupportedException($"{nameof(float2)} has one significand per component.");
int IFloatingPoint<float2>.GetSignificandByteCount() =>
throw new NotSupportedException($"{nameof(float2)} has one significand per component.");
bool IFloatingPoint<float2>.TryWriteExponentBigEndian(Span<byte> destination, out int bytesWritten) =>
throw new NotSupportedException($"{nameof(float2)} has one exponent per component.");
bool IFloatingPoint<float2>.TryWriteExponentLittleEndian(Span<byte> destination, out int bytesWritten) =>
throw new NotSupportedException($"{nameof(float2)} has one exponent per component.");
bool IFloatingPoint<float2>.TryWriteSignificandBigEndian(Span<byte> destination, out int bytesWritten) =>
throw new NotSupportedException($"{nameof(float2)} has one significand per component.");
bool IFloatingPoint<float2>.TryWriteSignificandLittleEndian(Span<byte> destination, out int bytesWritten) =>
throw new NotSupportedException($"{nameof(float2)} has one significand per component.");
}
// IFloatingPointIeee754
public partial struct float2 : IFloatingPointIeee754<float2>
{
/// <summary>Gets a vector whose components are NaN.</summary>
public static float2 NaN => new(float.NaN);
/// <inheritdoc cref="float.Epsilon" />
public static float2 Epsilon => new(float.Epsilon);
/// <inheritdoc cref="float.NegativeZero" />
public static float2 NegativeZero => new(float.NegativeZero);
/// <inheritdoc cref="float.PositiveInfinity" />
public static float2 PositiveInfinity => new(float.PositiveInfinity);
/// <inheritdoc cref="float.NegativeInfinity" />
public static float2 NegativeInfinity => new(float.NegativeInfinity);
/// <inheritdoc cref="float.Atan2" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float2 Atan2(float2 y, float2 x)
{
return new float2(float.Atan2(y.X, x.X), float.Atan2(y.Y, x.Y));
}
/// <inheritdoc cref="float.Atan2Pi" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float2 Atan2Pi(float2 y, float2 x)
{
return new float2(float.Atan2Pi(y.X, x.X), float.Atan2Pi(y.Y, x.Y));
}
/// <inheritdoc cref="float.BitDecrement" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float2 BitDecrement(float2 value)
{
return new float2(float.BitDecrement(value.X), float.BitDecrement(value.Y));
}
/// <inheritdoc cref="float.BitIncrement" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float2 BitIncrement(float2 value)
{
return new float2(float.BitIncrement(value.X), float.BitIncrement(value.Y));
}
/// <inheritdoc cref="float.FusedMultiplyAdd" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float2 FusedMultiplyAdd(float2 a, float2 b, float2 addend)
{
return new(float.FusedMultiplyAdd(a.X, b.X, addend.X), float.FusedMultiplyAdd(a.Y, b.Y, addend.Y));
}
/// <inheritdoc cref="float.MultiplyAddEstimate" />
/// <remarks>Permitted but not required to fuse; use <see cref="FusedMultiplyAdd" /> where the single rounding is required.</remarks>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float2 MultiplyAddEstimate(float2 a, float2 b, float2 addend)
{
return new(float.MultiplyAddEstimate(a.X, b.X, addend.X), float.MultiplyAddEstimate(a.Y, b.Y, addend.Y));
}
/// <inheritdoc cref="float.Ieee754Remainder" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float2 Ieee754Remainder(float2 a, float2 b)
{
return new float2(float.Ieee754Remainder(a.X, b.X), float.Ieee754Remainder(a.Y, b.Y));
}
/// <inheritdoc cref="float.ScaleB" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float2 ScaleB(float2 value, int n)
{
return new float2(float.ScaleB(value.X, n), float.ScaleB(value.Y, n));
}
// ILogB's int return cannot hold one exponent per lane - same shape as Sign
static int IFloatingPointIeee754<float2>.ILogB(float2 value) =>
throw new NotSupportedException($"{nameof(float2)} has one exponent per component.");
/// <inheritdoc cref="Vector2.Lerp(Vector2, Vector2, float)" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float2 Lerp(float2 a, float2 b, float amount)
{
return new(float.Lerp(a.X, b.X, amount), float.Lerp(a.Y, b.Y, amount));
}
/// <inheritdoc cref="Sqrt" />
[Obsolete("Renamed to Sqrt (the generic-math name; SquareRoot was the System.Numerics vector spelling).")]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float2 SquareRoot(float2 value)
{
return Sqrt(value);
}
}

View file

@ -0,0 +1,545 @@
// <auto-generated /> - edit Vector.numerics.tt to modify
#nullable enable
namespace Brutal.Numerics;
// INumberBase
public partial struct float2 : INumberBase<float2>
{
/// <inheritdoc />
public static float2 Zero => new(0);
/// <inheritdoc />
public static float2 One => new(1);
static float2 IAdditiveIdentity<float2, float2>.AdditiveIdentity => Zero;
static float2 IMultiplicativeIdentity<float2, float2>.MultiplicativeIdentity => One;
static int INumberBase<float2>.Radix => 2; // every component type is binary
/// <inheritdoc cref="Vector2.Abs" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float2 Abs(float2 value)
{
return new(float.Abs(value.X), float.Abs(value.Y));
}
static bool INumberBase<float2>.IsCanonical(float2 value) => true;
static bool INumberBase<float2>.IsComplexNumber(float2 value) => false;
static bool INumberBase<float2>.IsImaginaryNumber(float2 value) => false;
/// <summary>Determines if every component of a value is zero.</summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static bool INumberBase<float2>.IsZero(float2 value)
{
return value == Zero;
}
/// <summary>Determines if every component of a value is an even integral value.</summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static bool INumberBase<float2>.IsEvenInteger(float2 value)
{
return float.IsEvenInteger(value.X) && float.IsEvenInteger(value.Y);
}
/// <summary>Determines if every component of a value is an odd integral value.</summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static bool INumberBase<float2>.IsOddInteger(float2 value)
{
return float.IsOddInteger(value.X) && float.IsOddInteger(value.Y);
}
/// <summary>Determines if every component of a value is negative.</summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static bool INumberBase<float2>.IsNegative(float2 value)
{
return float.IsNegative(value.X) && float.IsNegative(value.Y);
}
/// <summary>Determines if every component of a value is positive.</summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static bool INumberBase<float2>.IsPositive(float2 value)
{
return float.IsPositive(value.X) && float.IsPositive(value.Y);
}
/// <summary>Determines if every component of a value is finite.</summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static bool INumberBase<float2>.IsFinite(float2 value)
{
return float.IsFinite(value.X) && float.IsFinite(value.Y);
}
/// <summary>Determines if every component of a value is infinite.</summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static bool INumberBase<float2>.IsInfinity(float2 value)
{
return float.IsInfinity(value.X) && float.IsInfinity(value.Y);
}
/// <summary>Determines if every component of a value is negative infinity.</summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static bool INumberBase<float2>.IsNegativeInfinity(float2 value)
{
return float.IsNegativeInfinity(value.X) && float.IsNegativeInfinity(value.Y);
}
/// <summary>Determines if every component of a value is positive infinity.</summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static bool INumberBase<float2>.IsPositiveInfinity(float2 value)
{
return float.IsPositiveInfinity(value.X) && float.IsPositiveInfinity(value.Y);
}
/// <summary>Determines if every component of a value is an integral value.</summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static bool INumberBase<float2>.IsInteger(float2 value)
{
return float.IsInteger(value.X) && float.IsInteger(value.Y);
}
/// <summary>Determines if every component of a value is a real value.</summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static bool INumberBase<float2>.IsRealNumber(float2 value)
{
return float.IsRealNumber(value.X) && float.IsRealNumber(value.Y);
}
/// <summary>Determines if any component of a value is NaN.</summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static bool INumberBase<float2>.IsNaN(float2 value)
{
return float.IsNaN(value.X) || float.IsNaN(value.Y);
}
/// <summary>Determines if every component of a value is normal.</summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static bool INumberBase<float2>.IsNormal(float2 value)
{
return float.IsNormal(value.X) && float.IsNormal(value.Y);
}
/// <summary>Determines if every component of a value is subnormal.</summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static bool INumberBase<float2>.IsSubnormal(float2 value)
{
return float.IsSubnormal(value.X) && float.IsSubnormal(value.Y);
}
/// <summary>Computes, componentwise, the value whose magnitude is greater.</summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float2 MaxMagnitude(float2 a, float2 b)
{
return new(float.MaxMagnitude(a.X, b.X), float.MaxMagnitude(a.Y, b.Y));
}
/// <summary>Computes, componentwise, the value whose magnitude is greater, preferring numbers over NaN.</summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float2 MaxMagnitudeNumber(float2 a, float2 b)
{
return new(float.MaxMagnitudeNumber(a.X, b.X), float.MaxMagnitudeNumber(a.Y, b.Y));
}
/// <summary>Computes, componentwise, the value whose magnitude is smaller.</summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float2 MinMagnitude(float2 a, float2 b)
{
return new(float.MinMagnitude(a.X, b.X), float.MinMagnitude(a.Y, b.Y));
}
/// <summary>Computes, componentwise, the value whose magnitude is smaller, preferring numbers over NaN.</summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float2 MinMagnitudeNumber(float2 a, float2 b)
{
return new(float.MinMagnitudeNumber(a.X, b.X), float.MinMagnitudeNumber(a.Y, b.Y));
}
/// <inheritdoc cref="Vector2.Add" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float2 Add(float2 a, float2 b)
{
return a + b;
}
/// <inheritdoc cref="Vector2.Divide(Vector2, Vector2)" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float2 Divide(float2 a, float2 b)
{
return a / b;
}
/// <inheritdoc cref="Vector2.Multiply(Vector2, Vector2)" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float2 Multiply(float2 a, float2 b)
{
return a * b;
}
/// <inheritdoc cref="Vector2.Negate" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float2 Negate(float2 value)
{
return -value;
}
/// <inheritdoc cref="Vector2.Subtract" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float2 Subtract(float2 a, float2 b)
{
return a - b;
}
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float2 operator +(float2 a, float2 b)
{
return new(a.X + b.X, a.Y + b.Y);
}
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float2 operator -(float2 a, float2 b)
{
return new(a.X - b.X, a.Y - b.Y);
}
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float2 operator *(float2 a, float2 b)
{
return new(a.X * b.X, a.Y * b.Y);
}
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float2 operator /(float2 a, float2 b)
{
return new(a.X / b.X, a.Y / b.Y);
}
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float2 operator -(float2 a)
{
return new(-a.X, -a.Y);
}
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float2 operator +(float2 a)
{
return a;
}
// ++/-- are well-defined (+/- One) but a footgun on a concrete vector: generic-plane only.
static float2 IIncrementOperators<float2>.operator ++(float2 value) => value + One;
static float2 IDecrementOperators<float2>.operator --(float2 value) => value - One;
static bool INumberBase<float2>.TryConvertFromChecked<TOther>(TOther value, out float2 result)
{
return NumberConversion.TryConvertFrom<float2, float, TOther, NumberConversion.Checked>(value, out result);
}
static bool INumberBase<float2>.TryConvertToChecked<TOther>(float2 value, [MaybeNullWhen(false)] out TOther result)
{
result = default;
return false;
}
static bool INumberBase<float2>.TryConvertFromSaturating<TOther>(TOther value, out float2 result)
{
return NumberConversion.TryConvertFrom<float2, float, TOther, NumberConversion.Saturating>(value, out result);
}
static bool INumberBase<float2>.TryConvertToSaturating<TOther>(float2 value, [MaybeNullWhen(false)] out TOther result)
{
result = default;
return false;
}
static bool INumberBase<float2>.TryConvertFromTruncating<TOther>(TOther value, out float2 result)
{
return NumberConversion.TryConvertFrom<float2, float, TOther, NumberConversion.Truncating>(value, out result);
}
static bool INumberBase<float2>.TryConvertToTruncating<TOther>(float2 value, [MaybeNullWhen(false)] out TOther result)
{
result = default;
return false;
}
}
// IMultiplyOperators<TSelf, TComponent, TSelf>, IDivisionOperators<TSelf, TComponent, TSelf>
public partial struct float2
: IMultiplyOperators<float2, float, float2>
, IDivisionOperators<float2, float, float2>
{
/// <inheritdoc cref="Vector2.Divide(Vector2, float)" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float2 Divide(float2 a, float b)
{
return a / b;
}
/// <inheritdoc cref="Vector2.Multiply(Vector2, float)" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float2 Multiply(float2 a, float b)
{
return a * b;
}
/// <inheritdoc cref="Vector2.Multiply(float, Vector2)" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float2 Multiply(float a, float2 b)
{
return a * b;
}
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float2 operator *(float2 a, float b)
{
return new(a.X * b, a.Y * b);
}
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float2 operator /(float2 a, float b)
{
return new(a.X / b, a.Y / b);
}
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float2 operator *(float a, float2 b)
{
return new(a * b.X, a * b.Y);
}
}
// INumber
public partial struct float2 : INumber<float2>
{
/// <inheritdoc cref="Vector2.Clamp" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float2 Clamp(float2 value, float2 min, float2 max)
{
// HLSL contract when min > max: max wins (clamp is Max-then-Min); pinned in
// Clamp_InvertedBounds_MatchesBcl. NOT scalar T.Clamp, which throws on inversion.
return Min(Max(value, min), max);
}
/// <inheritdoc cref="Vector2.Max" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float2 Max(float2 a, float2 b)
{
return new(float.Max(a.X, b.X), float.Max(a.Y, b.Y));
}
/// <inheritdoc cref="Vector2.Min" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float2 Min(float2 a, float2 b)
{
return new(float.Min(a.X, b.X), float.Min(a.Y, b.Y));
}
/// <summary>Selects, componentwise, the larger value, preferring numbers over NaN.</summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float2 MaxNumber(float2 a, float2 b)
{
return new(float.MaxNumber(a.X, b.X), float.MaxNumber(a.Y, b.Y));
}
/// <summary>Selects, componentwise, the smaller value, preferring numbers over NaN.</summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float2 MinNumber(float2 a, float2 b)
{
return new(float.MinNumber(a.X, b.X), float.MinNumber(a.Y, b.Y));
}
/// <summary>Copies, componentwise, the sign of <paramref name="sign" /> onto the magnitude of <paramref name="value" />.</summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float2 CopySign(float2 value, float2 sign)
{
return new(float.CopySign(value.X, sign.X), float.CopySign(value.Y, sign.Y));
}
// the Native variants permit either NaN/signed-zero behavior - forwarding is always legal
static float2 INumber<float2>.ClampNative(float2 value, float2 min, float2 max) => Clamp(value, min, max);
static float2 INumber<float2>.MaxNative(float2 a, float2 b) => Max(a, b);
static float2 INumber<float2>.MinNative(float2 a, float2 b) => Min(a, b);
// Sign's int return cannot hold a per-lane answer, and a collapsed one would lie for mixed signs
static int INumber<float2>.Sign(float2 value) =>
throw new NotSupportedException($"{nameof(float2)} has no scalar sign.");
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float2 operator %(float2 a, float2 b)
{
return new float2(a.X % b.X, a.Y % b.Y);
}
int IComparable.CompareTo(object? obj) =>
throw new NotSupportedException($"{nameof(float2)} has no total order.");
int IComparable<float2>.CompareTo(float2 other) =>
throw new NotSupportedException($"{nameof(float2)} has no total order.");
static bool IComparisonOperators<float2, float2, bool>.operator <(float2 a, float2 b) =>
throw new NotSupportedException($"{nameof(float2)} has no total order.");
static bool IComparisonOperators<float2, float2, bool>.operator <=(float2 a, float2 b) =>
throw new NotSupportedException($"{nameof(float2)} has no total order.");
static bool IComparisonOperators<float2, float2, bool>.operator >(float2 a, float2 b) =>
throw new NotSupportedException($"{nameof(float2)} has no total order.");
static bool IComparisonOperators<float2, float2, bool>.operator >=(float2 a, float2 b) =>
throw new NotSupportedException($"{nameof(float2)} has no total order.");
}
// IComponentwiseComparison + the componentwise predicate masks (no interface to mirror)
public partial struct float2 : IComponentwiseComparison<float2, bool2>
{
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool2 operator <(float2 a, float2 b)
{
return new bool2(a.X < b.X, a.Y < b.Y);
}
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool2 operator <=(float2 a, float2 b)
{
return new bool2(a.X <= b.X, a.Y <= b.Y);
}
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool2 operator >(float2 a, float2 b)
{
return new bool2(a.X > b.X, a.Y > b.Y);
}
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool2 operator >=(float2 a, float2 b)
{
return new bool2(a.X >= b.X, a.Y >= b.Y);
}
/// <summary>Determines which components of a value are zero.</summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool2 IsZero(float2 value)
{
return new bool2(value.X == 0, value.Y == 0);
}
/// <summary>Determines which components of a value are an even integral value.</summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool2 IsEvenInteger(float2 value)
{
return new bool2(float.IsEvenInteger(value.X), float.IsEvenInteger(value.Y));
}
/// <summary>Determines which components of a value are an odd integral value.</summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool2 IsOddInteger(float2 value)
{
return new bool2(float.IsOddInteger(value.X), float.IsOddInteger(value.Y));
}
/// <summary>Determines which components of a value are negative.</summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool2 IsNegative(float2 value)
{
return new bool2(float.IsNegative(value.X), float.IsNegative(value.Y));
}
/// <summary>Determines which components of a value are positive.</summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool2 IsPositive(float2 value)
{
return new bool2(float.IsPositive(value.X), float.IsPositive(value.Y));
}
/// <summary>Determines which components of a value are finite.</summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool2 IsFinite(float2 value)
{
return new bool2(float.IsFinite(value.X), float.IsFinite(value.Y));
}
/// <summary>Determines which components of a value are infinite.</summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool2 IsInfinity(float2 value)
{
return new bool2(float.IsInfinity(value.X), float.IsInfinity(value.Y));
}
/// <summary>Determines which components of a value are negative infinity.</summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool2 IsNegativeInfinity(float2 value)
{
return new bool2(float.IsNegativeInfinity(value.X), float.IsNegativeInfinity(value.Y));
}
/// <summary>Determines which components of a value are positive infinity.</summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool2 IsPositiveInfinity(float2 value)
{
return new bool2(float.IsPositiveInfinity(value.X), float.IsPositiveInfinity(value.Y));
}
/// <summary>Determines which components of a value are an integral value.</summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool2 IsInteger(float2 value)
{
return new bool2(float.IsInteger(value.X), float.IsInteger(value.Y));
}
/// <summary>Determines which components of a value are a real value.</summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool2 IsRealNumber(float2 value)
{
return new bool2(float.IsRealNumber(value.X), float.IsRealNumber(value.Y));
}
/// <summary>Determines which components of a value are NaN.</summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool2 IsNaN(float2 value)
{
return new bool2(float.IsNaN(value.X), float.IsNaN(value.Y));
}
/// <summary>Determines which components of a value are normal.</summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool2 IsNormal(float2 value)
{
return new bool2(float.IsNormal(value.X), float.IsNormal(value.Y));
}
/// <summary>Determines which components of a value are subnormal.</summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool2 IsSubnormal(float2 value)
{
return new bool2(float.IsSubnormal(value.X), float.IsSubnormal(value.Y));
}
}
// ISignedNumber
public partial struct float2 : ISignedNumber<float2>
{
/// <inheritdoc />
public static float2 NegativeOne => new(-1);
}

View file

@ -0,0 +1,210 @@
// <auto-generated /> - edit Vector.pack.tt to modify
#nullable enable
namespace Brutal.Numerics;
public partial struct float2
{
public static float2 Unpack(in sbyte2 vector, Func<sbyte, float> elementConverter)
{
VectorPack.Pack(vector, out float2 result, elementConverter);
return result;
}
public static float2 Unpack(in byte2 vector, Func<byte, float> elementConverter)
{
VectorPack.Pack(vector, out float2 result, elementConverter);
return result;
}
public static float2 Unpack(in short2 vector, Func<short, float> elementConverter)
{
VectorPack.Pack(vector, out float2 result, elementConverter);
return result;
}
public static float2 Unpack(in ushort2 vector, Func<ushort, float> elementConverter)
{
VectorPack.Pack(vector, out float2 result, elementConverter);
return result;
}
public static float2 Unpack(in int2 vector, Func<int, float> elementConverter)
{
VectorPack.Pack(vector, out float2 result, elementConverter);
return result;
}
public static float2 Unpack(in uint2 vector, Func<uint, float> elementConverter)
{
VectorPack.Pack(vector, out float2 result, elementConverter);
return result;
}
public static float2 Pack(in double2 vector, Func<double, float> elementConverter)
{
VectorPack.Pack(vector, out float2 result, elementConverter);
return result;
}
public static float2 Unpack(in sbyte2 vector, Unpack.Float mode = Numerics.Unpack.Float.Cast)
{
return Unpack(vector, PackUtils.SByte.ToFloat(mode));
}
public static float2 Unpack(in byte2 vector, Unpack.Float mode = Numerics.Unpack.Float.Cast)
{
return Unpack(vector, PackUtils.Byte.ToFloat(mode));
}
public static float2 Unpack(in short2 vector, Unpack.Float mode = Numerics.Unpack.Float.Cast)
{
return Unpack(vector, PackUtils.Short.ToFloat(mode));
}
public static float2 Unpack(in ushort2 vector, Unpack.Float mode = Numerics.Unpack.Float.Cast)
{
return Unpack(vector, PackUtils.UShort.ToFloat(mode));
}
public static float2 Unpack(in int2 vector, Unpack.Float mode = Numerics.Unpack.Float.Cast)
{
return Unpack(vector, PackUtils.Int.ToFloat(mode));
}
public static float2 Unpack(in uint2 vector, Unpack.Float mode = Numerics.Unpack.Float.Cast)
{
return Unpack(vector, PackUtils.UInt.ToFloat(mode));
}
public static float2 Pack(in double2 vector, Pack.Float mode = Numerics.Pack.Float.Truncate)
{
return Pack(vector, PackUtils.Double.ToFloat(mode));
}
public static void UnpackSpan(
in ReadOnlySpan<sbyte2> source,
Span<float2> destination,
Func<sbyte, float> elementConverter
)
{
VectorPack.Pack(source, destination, elementConverter);
}
public static void UnpackSpan(
in ReadOnlySpan<byte2> source,
Span<float2> destination,
Func<byte, float> elementConverter
)
{
VectorPack.Pack(source, destination, elementConverter);
}
public static void UnpackSpan(
in ReadOnlySpan<short2> source,
Span<float2> destination,
Func<short, float> elementConverter
)
{
VectorPack.Pack(source, destination, elementConverter);
}
public static void UnpackSpan(
in ReadOnlySpan<ushort2> source,
Span<float2> destination,
Func<ushort, float> elementConverter
)
{
VectorPack.Pack(source, destination, elementConverter);
}
public static void UnpackSpan(
in ReadOnlySpan<int2> source,
Span<float2> destination,
Func<int, float> elementConverter
)
{
VectorPack.Pack(source, destination, elementConverter);
}
public static void UnpackSpan(
in ReadOnlySpan<uint2> source,
Span<float2> destination,
Func<uint, float> elementConverter
)
{
VectorPack.Pack(source, destination, elementConverter);
}
public static void PackSpan(
in ReadOnlySpan<double2> source,
Span<float2> destination,
Func<double, float> elementConverter
)
{
VectorPack.Pack(source, destination, elementConverter);
}
public static void UnpackSpan(
in ReadOnlySpan<sbyte2> source,
Span<float2> destination,
Unpack.Float mode = Numerics.Unpack.Float.Cast
)
{
UnpackSpan(source, destination, PackUtils.SByte.ToFloat(mode));
}
public static void UnpackSpan(
in ReadOnlySpan<byte2> source,
Span<float2> destination,
Unpack.Float mode = Numerics.Unpack.Float.Cast
)
{
UnpackSpan(source, destination, PackUtils.Byte.ToFloat(mode));
}
public static void UnpackSpan(
in ReadOnlySpan<short2> source,
Span<float2> destination,
Unpack.Float mode = Numerics.Unpack.Float.Cast
)
{
UnpackSpan(source, destination, PackUtils.Short.ToFloat(mode));
}
public static void UnpackSpan(
in ReadOnlySpan<ushort2> source,
Span<float2> destination,
Unpack.Float mode = Numerics.Unpack.Float.Cast
)
{
UnpackSpan(source, destination, PackUtils.UShort.ToFloat(mode));
}
public static void UnpackSpan(
in ReadOnlySpan<int2> source,
Span<float2> destination,
Unpack.Float mode = Numerics.Unpack.Float.Cast
)
{
UnpackSpan(source, destination, PackUtils.Int.ToFloat(mode));
}
public static void UnpackSpan(
in ReadOnlySpan<uint2> source,
Span<float2> destination,
Unpack.Float mode = Numerics.Unpack.Float.Cast
)
{
UnpackSpan(source, destination, PackUtils.UInt.ToFloat(mode));
}
public static void PackSpan(
in ReadOnlySpan<double2> source,
Span<float2> destination,
Pack.Float mode = Numerics.Pack.Float.Truncate
)
{
PackSpan(source, destination, PackUtils.Double.ToFloat(mode));
}
}

View file

@ -0,0 +1,80 @@
// <auto-generated /> - edit Vector.swizzle.tt to modify
#nullable enable
namespace Brutal.Numerics;
public partial struct float2
{
/// <summary>
/// Swizzle readonly getter/setter for the X and Y components of the vector.
/// </summary>
[XmlIgnore]
public float2 XY
{
readonly get => this;
set => this = value;
}
/// <summary>
/// Swizzle readonly getter/setter for the Y and X components of the vector.
/// </summary>
[XmlIgnore]
public float2 YX
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
readonly get => new(Y, X);
set
{
Y = value.X;
X = value.Y;
}
}
}
public partial struct float2
{
/// <summary>
/// The Red component of the vector (synonym for X).
/// </summary>
[XmlIgnore]
public float R
{
readonly get => X;
set => X = value;
}
/// <summary>
/// The Green component of the vector (synonym for Y).
/// </summary>
[XmlIgnore]
public float G
{
readonly get => Y;
set => Y = value;
}
/// <summary>
/// Swizzle readonly getter/setter for the Red and Green components of the vector.
/// </summary>
[XmlIgnore]
public float2 RG
{
readonly get => this;
set => this = value;
}
/// <summary>
/// Swizzle readonly getter/setter for the Green and Red components of the vector.
/// </summary>
[XmlIgnore]
public float2 GR
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
readonly get => new(Y, X);
set
{
G = value.R;
R = value.G;
}
}
}