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

View file

@ -0,0 +1,31 @@
// <auto-generated /> - edit Vector.color.tt to modify
#nullable enable
namespace Brutal.Numerics;
public partial struct float3
{
/// <summary>
/// Constructs a float3 vector representing an RGB color.
/// </summary>
/// <param name="r">Red component (0.0 - 1.0).</param>
/// <param name="g">Green component (0.0 - 1.0).</param>
/// <param name="b">Blue component (0.0 - 1.0).</param>
/// <returns>A float3 color with the specified RGB values.</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float3 Rgb(float r, float g, float b)
{
return new float3(r, g, b);
}
/// <summary>
/// Constructs a float3 vector representing a grayscale color.
/// </summary>
/// <param name="v">Single value used for red, green, and blue components (0.0 - 1.0).</param>
/// <returns>A float3 grayscale color with the specified value.</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float3 Grayscale(float v)
{
return new float3(v, v, v);
}
}

View file

@ -0,0 +1,28 @@
// <auto-generated /> - edit Vector.copy.tt to modify
#nullable enable
namespace Brutal.Numerics;
public partial struct float3
{
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public readonly void CopyTo(Span<float> destination)
{
if (destination.Length < ComponentCount)
throw new ArgumentException("Length must be at least 3.", 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 float3
{
/// <inheritdoc />
public readonly override int GetHashCode()
{
return HashCode.Combine(X, Y, Z);
}
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public readonly bool Equals(float3 other)
{
return X.Equals(other.X) && Y.Equals(other.Y) && Z.Equals(other.Z);
}
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public readonly override bool Equals([NotNullWhen(true)] object? obj)
{
return obj is float3 other && Equals(other);
}
/// <summary>IEEE lane-wise equality over every component: any NaN component makes this false (contrast <see cref="Equals(float3)" />, which is NaN-reflexive), and -0 equals +0.</summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool operator ==(float3 a, float3 b)
{
return a.X == b.X && a.Y == b.Y && a.Z == b.Z;
}
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool operator !=(float3 a, float3 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 float3 : ISpanFormattable, IUtf8SpanFormattable, ISpanParsable<float3>
{
/// <inheritdoc />
public readonly override string ToString()
{
return ToString("G", CultureInfo.CurrentCulture);
}
/// <inheritdoc cref="Vector3.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)}{separator} {Z.ToString(format, formatProvider)}>";
}
/// <inheritdoc />
public readonly bool TryFormat(Span<char> destination, out int charsWritten, ReadOnlySpan<char> format, IFormatProvider? provider)
{
return StringHelpers.TryFormat<float3, 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<float3, float>(this, destination, out bytesWritten, format, provider);
}
/// <inheritdoc cref="Parse(ReadOnlySpan{char}, NumberStyles, IFormatProvider?)" />
public static float3 Parse(string s, IFormatProvider? provider)
{
ArgumentNullException.ThrowIfNull(s);
return Parse(s.AsSpan(), NumberStyles.Float, provider);
}
/// <inheritdoc cref="Parse(ReadOnlySpan{char}, NumberStyles, IFormatProvider?)" />
public static float3 Parse(ReadOnlySpan<char> s, IFormatProvider? provider = null)
{
return Parse(s, NumberStyles.Float, provider);
}
/// <inheritdoc cref="Parse(ReadOnlySpan{char}, NumberStyles, IFormatProvider?)" />
public static float3 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 float3 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 float3 format.");
return result;
}
/// <inheritdoc cref="TryParse(ReadOnlySpan{char}, NumberStyles, IFormatProvider?, out float3)" />
public static bool TryParse([NotNullWhen(true)] string? s, IFormatProvider? provider, out float3 result)
{
return TryParse(s.AsSpan(), NumberStyles.Float, provider, out result);
}
/// <inheritdoc cref="TryParse(ReadOnlySpan{char}, NumberStyles, IFormatProvider?, out float3)" />
public static bool TryParse(ReadOnlySpan<char> s, IFormatProvider? provider, out float3 result)
{
return TryParse(s, NumberStyles.Float, provider, out result);
}
/// <inheritdoc cref="TryParse(ReadOnlySpan{char}, NumberStyles, IFormatProvider?, out float3)" />
public static bool TryParse([NotNullWhen(true)] string? s, NumberStyles style, IFormatProvider? provider, out float3 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 float3.</returns>
public static bool TryParse(ReadOnlySpan<char> s, NumberStyles style, IFormatProvider? provider, out float3 result)
{
return StringHelpers.TryParse<float3, float>(s, style, provider, out result);
}
}

View file

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

View file

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

View file

@ -0,0 +1,75 @@
// <auto-generated /> - edit Vector.math.tt to modify
#nullable enable
namespace Brutal.Numerics;
public partial struct float3
{
/// <inheritdoc cref="Vector3.Cross" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float3 Cross(float3 a, float3 b)
{
return new(
a.Y * b.Z - a.Z * b.Y,
a.Z * b.X - a.X * b.Z,
a.X * b.Y - a.Y * b.X);
}
/// <inheritdoc cref="float4.Multiply(float4, float4x4)" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float2 Multiply(float3 vector, float3x2 matrix)
{
float2 result = default;
result.X = Dot(vector, new float3(matrix.M11, matrix.M21, matrix.M31));
result.Y = Dot(vector, new float3(matrix.M12, matrix.M22, matrix.M32));
return result;
}
/// <inheritdoc cref="Multiply(float3, float3x2)" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float2 operator *(float3 vector, float3x2 matrix)
{
return Multiply(vector, matrix);
}
/// <inheritdoc cref="Vector3.Reflect" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float3 Reflect(float3 vector, float3 normal)
{
return vector - 2 * Dot(vector, normal) * normal;
}
/// <inheritdoc cref="Vector3.Transform(Vector3, Matrix4x4)" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float3 Transform(float3 position, float4x4 matrix)
{
var result = matrix.X * position.X;
result += matrix.Y * position.Y;
result += matrix.Z * position.Z;
result += matrix.W;
return result.XYZ;
}
/// <inheritdoc cref="Vector3.Transform(Vector3, Quaternion)" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float3 Transform(float3 value, floatQuat rotation)
{
return float4.Transform(value, rotation).XYZ;
}
/// <inheritdoc cref="Vector3.TransformNormal(Vector3, Matrix4x4)" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float3 TransformNormal(float3 normal, float4x4 matrix)
{
var result = matrix.X * normal.X;
result += matrix.Y * normal.Y;
result += matrix.Z * normal.Z;
return result.XYZ;
}
}

View file

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

View file

@ -0,0 +1,446 @@
// <auto-generated /> - edit Vector.numerics-floating.tt to modify
#nullable enable
namespace Brutal.Numerics;
// IFloatingPointConstants
public partial struct float3 : IFloatingPointConstants<float3>
{
/// <inheritdoc />
public static float3 E => new(float.E);
/// <inheritdoc />
public static float3 Pi => new(float.Pi);
/// <inheritdoc />
public static float3 Tau => new(float.Tau);
}
// IExponentialFunctions
public partial struct float3 : IExponentialFunctions<float3>
{
/// <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 float3 Exp(float3 value)
{
return new(float.Exp(value.X), float.Exp(value.Y), float.Exp(value.Z));
}
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float3 Exp2(float3 value)
{
return new float3(float.Exp2(value.X), float.Exp2(value.Y), float.Exp2(value.Z));
}
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float3 Exp10(float3 value)
{
return new float3(float.Exp10(value.X), float.Exp10(value.Y), float.Exp10(value.Z));
}
}
// ILogarithmicFunctions
public partial struct float3 : ILogarithmicFunctions<float3>
{
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float3 Log(float3 value)
{
return new(float.Log(value.X), float.Log(value.Y), float.Log(value.Z));
}
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float3 Log(float3 value, float3 newBase)
{
return new float3(float.Log(value.X, newBase.X), float.Log(value.Y, newBase.Y), float.Log(value.Z, newBase.Z));
}
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float3 Log2(float3 value)
{
return new(float.Log2(value.X), float.Log2(value.Y), float.Log2(value.Z));
}
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float3 Log10(float3 value)
{
return new float3(float.Log10(value.X), float.Log10(value.Y), float.Log10(value.Z));
}
}
// IPowerFunctions
public partial struct float3 : IPowerFunctions<float3>
{
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float3 Pow(float3 value, float3 power)
{
return new float3(float.Pow(value.X, power.X), float.Pow(value.Y, power.Y), float.Pow(value.Z, power.Z));
}
}
// IRootFunctions
public partial struct float3 : IRootFunctions<float3>
{
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float3 Cbrt(float3 value)
{
return new float3(float.Cbrt(value.X), float.Cbrt(value.Y), float.Cbrt(value.Z));
}
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float3 Hypot(float3 a, float3 b)
{
return new(float.Hypot(a.X, b.X), float.Hypot(a.Y, b.Y), float.Hypot(a.Z, b.Z));
}
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float3 RootN(float3 value, int n)
{
return new float3(float.RootN(value.X, n), float.RootN(value.Y, n), float.RootN(value.Z, n));
}
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float3 Sqrt(float3 value)
{
return new(float.Sqrt(value.X), float.Sqrt(value.Y), float.Sqrt(value.Z));
}
}
// ITrigonometricFunctions
public partial struct float3 : ITrigonometricFunctions<float3>
{
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float3 Sin(float3 value)
{
return new(float.Sin(value.X), float.Sin(value.Y), float.Sin(value.Z));
}
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float3 Cos(float3 value)
{
return new(float.Cos(value.X), float.Cos(value.Y), float.Cos(value.Z));
}
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static (float3 Sin, float3 Cos) SinCos(float3 value)
{
var (sinX, cosX) = float.SinCos(value.X);
var (sinY, cosY) = float.SinCos(value.Y);
var (sinZ, cosZ) = float.SinCos(value.Z);
return (new(sinX, sinY, sinZ), new(cosX, cosY, cosZ));
}
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float3 Tan(float3 value)
{
return new float3(float.Tan(value.X), float.Tan(value.Y), float.Tan(value.Z));
}
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float3 Asin(float3 value)
{
return new float3(float.Asin(value.X), float.Asin(value.Y), float.Asin(value.Z));
}
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float3 Acos(float3 value)
{
return new float3(float.Acos(value.X), float.Acos(value.Y), float.Acos(value.Z));
}
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float3 Atan(float3 value)
{
return new float3(float.Atan(value.X), float.Atan(value.Y), float.Atan(value.Z));
}
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float3 SinPi(float3 value)
{
return new float3(float.SinPi(value.X), float.SinPi(value.Y), float.SinPi(value.Z));
}
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float3 CosPi(float3 value)
{
return new float3(float.CosPi(value.X), float.CosPi(value.Y), float.CosPi(value.Z));
}
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float3 TanPi(float3 value)
{
return new float3(float.TanPi(value.X), float.TanPi(value.Y), float.TanPi(value.Z));
}
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float3 AsinPi(float3 value)
{
return new float3(float.AsinPi(value.X), float.AsinPi(value.Y), float.AsinPi(value.Z));
}
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float3 AcosPi(float3 value)
{
return new float3(float.AcosPi(value.X), float.AcosPi(value.Y), float.AcosPi(value.Z));
}
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float3 AtanPi(float3 value)
{
return new float3(float.AtanPi(value.X), float.AtanPi(value.Y), float.AtanPi(value.Z));
}
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static (float3 SinPi, float3 CosPi) SinCosPi(float3 value)
{
return (SinPi(value), CosPi(value));
}
/// <inheritdoc cref="float.DegreesToRadians" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float3 DegreesToRadians(float3 degrees)
{
return new(float.DegreesToRadians(degrees.X), float.DegreesToRadians(degrees.Y), float.DegreesToRadians(degrees.Z));
}
/// <inheritdoc cref="float.RadiansToDegrees" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float3 RadiansToDegrees(float3 radians)
{
return new(float.RadiansToDegrees(radians.X), float.RadiansToDegrees(radians.Y), float.RadiansToDegrees(radians.Z));
}
}
// IHyperbolicFunctions
public partial struct float3 : IHyperbolicFunctions<float3>
{
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float3 Sinh(float3 value)
{
return new float3(float.Sinh(value.X), float.Sinh(value.Y), float.Sinh(value.Z));
}
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float3 Cosh(float3 value)
{
return new float3(float.Cosh(value.X), float.Cosh(value.Y), float.Cosh(value.Z));
}
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float3 Tanh(float3 value)
{
return new float3(float.Tanh(value.X), float.Tanh(value.Y), float.Tanh(value.Z));
}
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float3 Asinh(float3 value)
{
return new float3(float.Asinh(value.X), float.Asinh(value.Y), float.Asinh(value.Z));
}
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float3 Acosh(float3 value)
{
return new float3(float.Acosh(value.X), float.Acosh(value.Y), float.Acosh(value.Z));
}
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float3 Atanh(float3 value)
{
return new float3(float.Atanh(value.X), float.Atanh(value.Y), float.Atanh(value.Z));
}
}
// IFloatingPoint
public partial struct float3 : IFloatingPoint<float3>
{
/// <inheritdoc cref="float.Floor(float)" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float3 Floor(float3 value)
{
return new(float.Floor(value.X), float.Floor(value.Y), float.Floor(value.Z));
}
/// <inheritdoc cref="float.Ceiling(float)" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float3 Ceiling(float3 value)
{
return new(float.Ceiling(value.X), float.Ceiling(value.Y), float.Ceiling(value.Z));
}
/// <inheritdoc cref="float.Round(float)" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float3 Round(float3 value)
{
return new(float.Round(value.X), float.Round(value.Y), float.Round(value.Z));
}
/// <inheritdoc cref="float.Truncate(float)" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float3 Truncate(float3 value)
{
return new(float.Truncate(value.X), float.Truncate(value.Y), float.Truncate(value.Z));
}
/// <inheritdoc cref="float.Round(float, int, MidpointRounding)" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float3 Round(float3 value, int digits, MidpointRounding mode)
{
return new float3(float.Round(value.X, digits, mode), float.Round(value.Y, digits, mode), float.Round(value.Z, digits, mode));
}
// One exponent and significand PER LANE, so there is no single honest answer: explicit and throwing.
int IFloatingPoint<float3>.GetExponentByteCount() =>
throw new NotSupportedException($"{nameof(float3)} has one exponent per component.");
int IFloatingPoint<float3>.GetExponentShortestBitLength() =>
throw new NotSupportedException($"{nameof(float3)} has one exponent per component.");
int IFloatingPoint<float3>.GetSignificandBitLength() =>
throw new NotSupportedException($"{nameof(float3)} has one significand per component.");
int IFloatingPoint<float3>.GetSignificandByteCount() =>
throw new NotSupportedException($"{nameof(float3)} has one significand per component.");
bool IFloatingPoint<float3>.TryWriteExponentBigEndian(Span<byte> destination, out int bytesWritten) =>
throw new NotSupportedException($"{nameof(float3)} has one exponent per component.");
bool IFloatingPoint<float3>.TryWriteExponentLittleEndian(Span<byte> destination, out int bytesWritten) =>
throw new NotSupportedException($"{nameof(float3)} has one exponent per component.");
bool IFloatingPoint<float3>.TryWriteSignificandBigEndian(Span<byte> destination, out int bytesWritten) =>
throw new NotSupportedException($"{nameof(float3)} has one significand per component.");
bool IFloatingPoint<float3>.TryWriteSignificandLittleEndian(Span<byte> destination, out int bytesWritten) =>
throw new NotSupportedException($"{nameof(float3)} has one significand per component.");
}
// IFloatingPointIeee754
public partial struct float3 : IFloatingPointIeee754<float3>
{
/// <summary>Gets a vector whose components are NaN.</summary>
public static float3 NaN => new(float.NaN);
/// <inheritdoc cref="float.Epsilon" />
public static float3 Epsilon => new(float.Epsilon);
/// <inheritdoc cref="float.NegativeZero" />
public static float3 NegativeZero => new(float.NegativeZero);
/// <inheritdoc cref="float.PositiveInfinity" />
public static float3 PositiveInfinity => new(float.PositiveInfinity);
/// <inheritdoc cref="float.NegativeInfinity" />
public static float3 NegativeInfinity => new(float.NegativeInfinity);
/// <inheritdoc cref="float.Atan2" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float3 Atan2(float3 y, float3 x)
{
return new float3(float.Atan2(y.X, x.X), float.Atan2(y.Y, x.Y), float.Atan2(y.Z, x.Z));
}
/// <inheritdoc cref="float.Atan2Pi" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float3 Atan2Pi(float3 y, float3 x)
{
return new float3(float.Atan2Pi(y.X, x.X), float.Atan2Pi(y.Y, x.Y), float.Atan2Pi(y.Z, x.Z));
}
/// <inheritdoc cref="float.BitDecrement" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float3 BitDecrement(float3 value)
{
return new float3(float.BitDecrement(value.X), float.BitDecrement(value.Y), float.BitDecrement(value.Z));
}
/// <inheritdoc cref="float.BitIncrement" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float3 BitIncrement(float3 value)
{
return new float3(float.BitIncrement(value.X), float.BitIncrement(value.Y), float.BitIncrement(value.Z));
}
/// <inheritdoc cref="float.FusedMultiplyAdd" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float3 FusedMultiplyAdd(float3 a, float3 b, float3 addend)
{
return new(float.FusedMultiplyAdd(a.X, b.X, addend.X), float.FusedMultiplyAdd(a.Y, b.Y, addend.Y), float.FusedMultiplyAdd(a.Z, b.Z, addend.Z));
}
/// <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 float3 MultiplyAddEstimate(float3 a, float3 b, float3 addend)
{
return new(float.MultiplyAddEstimate(a.X, b.X, addend.X), float.MultiplyAddEstimate(a.Y, b.Y, addend.Y), float.MultiplyAddEstimate(a.Z, b.Z, addend.Z));
}
/// <inheritdoc cref="float.Ieee754Remainder" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float3 Ieee754Remainder(float3 a, float3 b)
{
return new float3(float.Ieee754Remainder(a.X, b.X), float.Ieee754Remainder(a.Y, b.Y), float.Ieee754Remainder(a.Z, b.Z));
}
/// <inheritdoc cref="float.ScaleB" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float3 ScaleB(float3 value, int n)
{
return new float3(float.ScaleB(value.X, n), float.ScaleB(value.Y, n), float.ScaleB(value.Z, n));
}
// ILogB's int return cannot hold one exponent per lane - same shape as Sign
static int IFloatingPointIeee754<float3>.ILogB(float3 value) =>
throw new NotSupportedException($"{nameof(float3)} has one exponent per component.");
/// <inheritdoc cref="Vector3.Lerp(Vector3, Vector3, float)" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float3 Lerp(float3 a, float3 b, float amount)
{
return new(float.Lerp(a.X, b.X, amount), float.Lerp(a.Y, b.Y, amount), float.Lerp(a.Z, b.Z, amount));
}
/// <inheritdoc cref="Sqrt" />
[Obsolete("Renamed to Sqrt (the generic-math name; SquareRoot was the System.Numerics vector spelling).")]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float3 SquareRoot(float3 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 float3 : INumberBase<float3>
{
/// <inheritdoc />
public static float3 Zero => new(0);
/// <inheritdoc />
public static float3 One => new(1);
static float3 IAdditiveIdentity<float3, float3>.AdditiveIdentity => Zero;
static float3 IMultiplicativeIdentity<float3, float3>.MultiplicativeIdentity => One;
static int INumberBase<float3>.Radix => 2; // every component type is binary
/// <inheritdoc cref="Vector3.Abs" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float3 Abs(float3 value)
{
return new(float.Abs(value.X), float.Abs(value.Y), float.Abs(value.Z));
}
static bool INumberBase<float3>.IsCanonical(float3 value) => true;
static bool INumberBase<float3>.IsComplexNumber(float3 value) => false;
static bool INumberBase<float3>.IsImaginaryNumber(float3 value) => false;
/// <summary>Determines if every component of a value is zero.</summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static bool INumberBase<float3>.IsZero(float3 value)
{
return value == Zero;
}
/// <summary>Determines if every component of a value is an even integral value.</summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static bool INumberBase<float3>.IsEvenInteger(float3 value)
{
return float.IsEvenInteger(value.X) && float.IsEvenInteger(value.Y) && float.IsEvenInteger(value.Z);
}
/// <summary>Determines if every component of a value is an odd integral value.</summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static bool INumberBase<float3>.IsOddInteger(float3 value)
{
return float.IsOddInteger(value.X) && float.IsOddInteger(value.Y) && float.IsOddInteger(value.Z);
}
/// <summary>Determines if every component of a value is negative.</summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static bool INumberBase<float3>.IsNegative(float3 value)
{
return float.IsNegative(value.X) && float.IsNegative(value.Y) && float.IsNegative(value.Z);
}
/// <summary>Determines if every component of a value is positive.</summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static bool INumberBase<float3>.IsPositive(float3 value)
{
return float.IsPositive(value.X) && float.IsPositive(value.Y) && float.IsPositive(value.Z);
}
/// <summary>Determines if every component of a value is finite.</summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static bool INumberBase<float3>.IsFinite(float3 value)
{
return float.IsFinite(value.X) && float.IsFinite(value.Y) && float.IsFinite(value.Z);
}
/// <summary>Determines if every component of a value is infinite.</summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static bool INumberBase<float3>.IsInfinity(float3 value)
{
return float.IsInfinity(value.X) && float.IsInfinity(value.Y) && float.IsInfinity(value.Z);
}
/// <summary>Determines if every component of a value is negative infinity.</summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static bool INumberBase<float3>.IsNegativeInfinity(float3 value)
{
return float.IsNegativeInfinity(value.X) && float.IsNegativeInfinity(value.Y) && float.IsNegativeInfinity(value.Z);
}
/// <summary>Determines if every component of a value is positive infinity.</summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static bool INumberBase<float3>.IsPositiveInfinity(float3 value)
{
return float.IsPositiveInfinity(value.X) && float.IsPositiveInfinity(value.Y) && float.IsPositiveInfinity(value.Z);
}
/// <summary>Determines if every component of a value is an integral value.</summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static bool INumberBase<float3>.IsInteger(float3 value)
{
return float.IsInteger(value.X) && float.IsInteger(value.Y) && float.IsInteger(value.Z);
}
/// <summary>Determines if every component of a value is a real value.</summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static bool INumberBase<float3>.IsRealNumber(float3 value)
{
return float.IsRealNumber(value.X) && float.IsRealNumber(value.Y) && float.IsRealNumber(value.Z);
}
/// <summary>Determines if any component of a value is NaN.</summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static bool INumberBase<float3>.IsNaN(float3 value)
{
return float.IsNaN(value.X) || float.IsNaN(value.Y) || float.IsNaN(value.Z);
}
/// <summary>Determines if every component of a value is normal.</summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static bool INumberBase<float3>.IsNormal(float3 value)
{
return float.IsNormal(value.X) && float.IsNormal(value.Y) && float.IsNormal(value.Z);
}
/// <summary>Determines if every component of a value is subnormal.</summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static bool INumberBase<float3>.IsSubnormal(float3 value)
{
return float.IsSubnormal(value.X) && float.IsSubnormal(value.Y) && float.IsSubnormal(value.Z);
}
/// <summary>Computes, componentwise, the value whose magnitude is greater.</summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float3 MaxMagnitude(float3 a, float3 b)
{
return new(float.MaxMagnitude(a.X, b.X), float.MaxMagnitude(a.Y, b.Y), float.MaxMagnitude(a.Z, b.Z));
}
/// <summary>Computes, componentwise, the value whose magnitude is greater, preferring numbers over NaN.</summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float3 MaxMagnitudeNumber(float3 a, float3 b)
{
return new(float.MaxMagnitudeNumber(a.X, b.X), float.MaxMagnitudeNumber(a.Y, b.Y), float.MaxMagnitudeNumber(a.Z, b.Z));
}
/// <summary>Computes, componentwise, the value whose magnitude is smaller.</summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float3 MinMagnitude(float3 a, float3 b)
{
return new(float.MinMagnitude(a.X, b.X), float.MinMagnitude(a.Y, b.Y), float.MinMagnitude(a.Z, b.Z));
}
/// <summary>Computes, componentwise, the value whose magnitude is smaller, preferring numbers over NaN.</summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float3 MinMagnitudeNumber(float3 a, float3 b)
{
return new(float.MinMagnitudeNumber(a.X, b.X), float.MinMagnitudeNumber(a.Y, b.Y), float.MinMagnitudeNumber(a.Z, b.Z));
}
/// <inheritdoc cref="Vector3.Add" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float3 Add(float3 a, float3 b)
{
return a + b;
}
/// <inheritdoc cref="Vector3.Divide(Vector3, Vector3)" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float3 Divide(float3 a, float3 b)
{
return a / b;
}
/// <inheritdoc cref="Vector3.Multiply(Vector3, Vector3)" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float3 Multiply(float3 a, float3 b)
{
return a * b;
}
/// <inheritdoc cref="Vector3.Negate" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float3 Negate(float3 value)
{
return -value;
}
/// <inheritdoc cref="Vector3.Subtract" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float3 Subtract(float3 a, float3 b)
{
return a - b;
}
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float3 operator +(float3 a, float3 b)
{
return new(a.X + b.X, a.Y + b.Y, a.Z + b.Z);
}
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float3 operator -(float3 a, float3 b)
{
return new(a.X - b.X, a.Y - b.Y, a.Z - b.Z);
}
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float3 operator *(float3 a, float3 b)
{
return new(a.X * b.X, a.Y * b.Y, a.Z * b.Z);
}
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float3 operator /(float3 a, float3 b)
{
return new(a.X / b.X, a.Y / b.Y, a.Z / b.Z);
}
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float3 operator -(float3 a)
{
return new(-a.X, -a.Y, -a.Z);
}
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float3 operator +(float3 a)
{
return a;
}
// ++/-- are well-defined (+/- One) but a footgun on a concrete vector: generic-plane only.
static float3 IIncrementOperators<float3>.operator ++(float3 value) => value + One;
static float3 IDecrementOperators<float3>.operator --(float3 value) => value - One;
static bool INumberBase<float3>.TryConvertFromChecked<TOther>(TOther value, out float3 result)
{
return NumberConversion.TryConvertFrom<float3, float, TOther, NumberConversion.Checked>(value, out result);
}
static bool INumberBase<float3>.TryConvertToChecked<TOther>(float3 value, [MaybeNullWhen(false)] out TOther result)
{
result = default;
return false;
}
static bool INumberBase<float3>.TryConvertFromSaturating<TOther>(TOther value, out float3 result)
{
return NumberConversion.TryConvertFrom<float3, float, TOther, NumberConversion.Saturating>(value, out result);
}
static bool INumberBase<float3>.TryConvertToSaturating<TOther>(float3 value, [MaybeNullWhen(false)] out TOther result)
{
result = default;
return false;
}
static bool INumberBase<float3>.TryConvertFromTruncating<TOther>(TOther value, out float3 result)
{
return NumberConversion.TryConvertFrom<float3, float, TOther, NumberConversion.Truncating>(value, out result);
}
static bool INumberBase<float3>.TryConvertToTruncating<TOther>(float3 value, [MaybeNullWhen(false)] out TOther result)
{
result = default;
return false;
}
}
// IMultiplyOperators<TSelf, TComponent, TSelf>, IDivisionOperators<TSelf, TComponent, TSelf>
public partial struct float3
: IMultiplyOperators<float3, float, float3>
, IDivisionOperators<float3, float, float3>
{
/// <inheritdoc cref="Vector3.Divide(Vector3, float)" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float3 Divide(float3 a, float b)
{
return a / b;
}
/// <inheritdoc cref="Vector3.Multiply(Vector3, float)" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float3 Multiply(float3 a, float b)
{
return a * b;
}
/// <inheritdoc cref="Vector3.Multiply(float, Vector3)" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float3 Multiply(float a, float3 b)
{
return a * b;
}
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float3 operator *(float3 a, float b)
{
return new(a.X * b, a.Y * b, a.Z * b);
}
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float3 operator /(float3 a, float b)
{
return new(a.X / b, a.Y / b, a.Z / b);
}
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float3 operator *(float a, float3 b)
{
return new(a * b.X, a * b.Y, a * b.Z);
}
}
// INumber
public partial struct float3 : INumber<float3>
{
/// <inheritdoc cref="Vector3.Clamp" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float3 Clamp(float3 value, float3 min, float3 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="Vector3.Max" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float3 Max(float3 a, float3 b)
{
return new(float.Max(a.X, b.X), float.Max(a.Y, b.Y), float.Max(a.Z, b.Z));
}
/// <inheritdoc cref="Vector3.Min" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float3 Min(float3 a, float3 b)
{
return new(float.Min(a.X, b.X), float.Min(a.Y, b.Y), float.Min(a.Z, b.Z));
}
/// <summary>Selects, componentwise, the larger value, preferring numbers over NaN.</summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float3 MaxNumber(float3 a, float3 b)
{
return new(float.MaxNumber(a.X, b.X), float.MaxNumber(a.Y, b.Y), float.MaxNumber(a.Z, b.Z));
}
/// <summary>Selects, componentwise, the smaller value, preferring numbers over NaN.</summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float3 MinNumber(float3 a, float3 b)
{
return new(float.MinNumber(a.X, b.X), float.MinNumber(a.Y, b.Y), float.MinNumber(a.Z, b.Z));
}
/// <summary>Copies, componentwise, the sign of <paramref name="sign" /> onto the magnitude of <paramref name="value" />.</summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float3 CopySign(float3 value, float3 sign)
{
return new(float.CopySign(value.X, sign.X), float.CopySign(value.Y, sign.Y), float.CopySign(value.Z, sign.Z));
}
// the Native variants permit either NaN/signed-zero behavior - forwarding is always legal
static float3 INumber<float3>.ClampNative(float3 value, float3 min, float3 max) => Clamp(value, min, max);
static float3 INumber<float3>.MaxNative(float3 a, float3 b) => Max(a, b);
static float3 INumber<float3>.MinNative(float3 a, float3 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<float3>.Sign(float3 value) =>
throw new NotSupportedException($"{nameof(float3)} has no scalar sign.");
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float3 operator %(float3 a, float3 b)
{
return new float3(a.X % b.X, a.Y % b.Y, a.Z % b.Z);
}
int IComparable.CompareTo(object? obj) =>
throw new NotSupportedException($"{nameof(float3)} has no total order.");
int IComparable<float3>.CompareTo(float3 other) =>
throw new NotSupportedException($"{nameof(float3)} has no total order.");
static bool IComparisonOperators<float3, float3, bool>.operator <(float3 a, float3 b) =>
throw new NotSupportedException($"{nameof(float3)} has no total order.");
static bool IComparisonOperators<float3, float3, bool>.operator <=(float3 a, float3 b) =>
throw new NotSupportedException($"{nameof(float3)} has no total order.");
static bool IComparisonOperators<float3, float3, bool>.operator >(float3 a, float3 b) =>
throw new NotSupportedException($"{nameof(float3)} has no total order.");
static bool IComparisonOperators<float3, float3, bool>.operator >=(float3 a, float3 b) =>
throw new NotSupportedException($"{nameof(float3)} has no total order.");
}
// IComponentwiseComparison + the componentwise predicate masks (no interface to mirror)
public partial struct float3 : IComponentwiseComparison<float3, bool3>
{
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool3 operator <(float3 a, float3 b)
{
return new bool3(a.X < b.X, a.Y < b.Y, a.Z < b.Z);
}
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool3 operator <=(float3 a, float3 b)
{
return new bool3(a.X <= b.X, a.Y <= b.Y, a.Z <= b.Z);
}
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool3 operator >(float3 a, float3 b)
{
return new bool3(a.X > b.X, a.Y > b.Y, a.Z > b.Z);
}
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool3 operator >=(float3 a, float3 b)
{
return new bool3(a.X >= b.X, a.Y >= b.Y, a.Z >= b.Z);
}
/// <summary>Determines which components of a value are zero.</summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool3 IsZero(float3 value)
{
return new bool3(value.X == 0, value.Y == 0, value.Z == 0);
}
/// <summary>Determines which components of a value are an even integral value.</summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool3 IsEvenInteger(float3 value)
{
return new bool3(float.IsEvenInteger(value.X), float.IsEvenInteger(value.Y), float.IsEvenInteger(value.Z));
}
/// <summary>Determines which components of a value are an odd integral value.</summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool3 IsOddInteger(float3 value)
{
return new bool3(float.IsOddInteger(value.X), float.IsOddInteger(value.Y), float.IsOddInteger(value.Z));
}
/// <summary>Determines which components of a value are negative.</summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool3 IsNegative(float3 value)
{
return new bool3(float.IsNegative(value.X), float.IsNegative(value.Y), float.IsNegative(value.Z));
}
/// <summary>Determines which components of a value are positive.</summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool3 IsPositive(float3 value)
{
return new bool3(float.IsPositive(value.X), float.IsPositive(value.Y), float.IsPositive(value.Z));
}
/// <summary>Determines which components of a value are finite.</summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool3 IsFinite(float3 value)
{
return new bool3(float.IsFinite(value.X), float.IsFinite(value.Y), float.IsFinite(value.Z));
}
/// <summary>Determines which components of a value are infinite.</summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool3 IsInfinity(float3 value)
{
return new bool3(float.IsInfinity(value.X), float.IsInfinity(value.Y), float.IsInfinity(value.Z));
}
/// <summary>Determines which components of a value are negative infinity.</summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool3 IsNegativeInfinity(float3 value)
{
return new bool3(float.IsNegativeInfinity(value.X), float.IsNegativeInfinity(value.Y), float.IsNegativeInfinity(value.Z));
}
/// <summary>Determines which components of a value are positive infinity.</summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool3 IsPositiveInfinity(float3 value)
{
return new bool3(float.IsPositiveInfinity(value.X), float.IsPositiveInfinity(value.Y), float.IsPositiveInfinity(value.Z));
}
/// <summary>Determines which components of a value are an integral value.</summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool3 IsInteger(float3 value)
{
return new bool3(float.IsInteger(value.X), float.IsInteger(value.Y), float.IsInteger(value.Z));
}
/// <summary>Determines which components of a value are a real value.</summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool3 IsRealNumber(float3 value)
{
return new bool3(float.IsRealNumber(value.X), float.IsRealNumber(value.Y), float.IsRealNumber(value.Z));
}
/// <summary>Determines which components of a value are NaN.</summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool3 IsNaN(float3 value)
{
return new bool3(float.IsNaN(value.X), float.IsNaN(value.Y), float.IsNaN(value.Z));
}
/// <summary>Determines which components of a value are normal.</summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool3 IsNormal(float3 value)
{
return new bool3(float.IsNormal(value.X), float.IsNormal(value.Y), float.IsNormal(value.Z));
}
/// <summary>Determines which components of a value are subnormal.</summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool3 IsSubnormal(float3 value)
{
return new bool3(float.IsSubnormal(value.X), float.IsSubnormal(value.Y), float.IsSubnormal(value.Z));
}
}
// ISignedNumber
public partial struct float3 : ISignedNumber<float3>
{
/// <inheritdoc />
public static float3 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 float3
{
public static float3 Unpack(in sbyte3 vector, Func<sbyte, float> elementConverter)
{
VectorPack.Pack(vector, out float3 result, elementConverter);
return result;
}
public static float3 Unpack(in byte3 vector, Func<byte, float> elementConverter)
{
VectorPack.Pack(vector, out float3 result, elementConverter);
return result;
}
public static float3 Unpack(in short3 vector, Func<short, float> elementConverter)
{
VectorPack.Pack(vector, out float3 result, elementConverter);
return result;
}
public static float3 Unpack(in ushort3 vector, Func<ushort, float> elementConverter)
{
VectorPack.Pack(vector, out float3 result, elementConverter);
return result;
}
public static float3 Unpack(in int3 vector, Func<int, float> elementConverter)
{
VectorPack.Pack(vector, out float3 result, elementConverter);
return result;
}
public static float3 Unpack(in uint3 vector, Func<uint, float> elementConverter)
{
VectorPack.Pack(vector, out float3 result, elementConverter);
return result;
}
public static float3 Pack(in double3 vector, Func<double, float> elementConverter)
{
VectorPack.Pack(vector, out float3 result, elementConverter);
return result;
}
public static float3 Unpack(in sbyte3 vector, Unpack.Float mode = Numerics.Unpack.Float.Cast)
{
return Unpack(vector, PackUtils.SByte.ToFloat(mode));
}
public static float3 Unpack(in byte3 vector, Unpack.Float mode = Numerics.Unpack.Float.Cast)
{
return Unpack(vector, PackUtils.Byte.ToFloat(mode));
}
public static float3 Unpack(in short3 vector, Unpack.Float mode = Numerics.Unpack.Float.Cast)
{
return Unpack(vector, PackUtils.Short.ToFloat(mode));
}
public static float3 Unpack(in ushort3 vector, Unpack.Float mode = Numerics.Unpack.Float.Cast)
{
return Unpack(vector, PackUtils.UShort.ToFloat(mode));
}
public static float3 Unpack(in int3 vector, Unpack.Float mode = Numerics.Unpack.Float.Cast)
{
return Unpack(vector, PackUtils.Int.ToFloat(mode));
}
public static float3 Unpack(in uint3 vector, Unpack.Float mode = Numerics.Unpack.Float.Cast)
{
return Unpack(vector, PackUtils.UInt.ToFloat(mode));
}
public static float3 Pack(in double3 vector, Pack.Float mode = Numerics.Pack.Float.Truncate)
{
return Pack(vector, PackUtils.Double.ToFloat(mode));
}
public static void UnpackSpan(
in ReadOnlySpan<sbyte3> source,
Span<float3> destination,
Func<sbyte, float> elementConverter
)
{
VectorPack.Pack(source, destination, elementConverter);
}
public static void UnpackSpan(
in ReadOnlySpan<byte3> source,
Span<float3> destination,
Func<byte, float> elementConverter
)
{
VectorPack.Pack(source, destination, elementConverter);
}
public static void UnpackSpan(
in ReadOnlySpan<short3> source,
Span<float3> destination,
Func<short, float> elementConverter
)
{
VectorPack.Pack(source, destination, elementConverter);
}
public static void UnpackSpan(
in ReadOnlySpan<ushort3> source,
Span<float3> destination,
Func<ushort, float> elementConverter
)
{
VectorPack.Pack(source, destination, elementConverter);
}
public static void UnpackSpan(
in ReadOnlySpan<int3> source,
Span<float3> destination,
Func<int, float> elementConverter
)
{
VectorPack.Pack(source, destination, elementConverter);
}
public static void UnpackSpan(
in ReadOnlySpan<uint3> source,
Span<float3> destination,
Func<uint, float> elementConverter
)
{
VectorPack.Pack(source, destination, elementConverter);
}
public static void PackSpan(
in ReadOnlySpan<double3> source,
Span<float3> destination,
Func<double, float> elementConverter
)
{
VectorPack.Pack(source, destination, elementConverter);
}
public static void UnpackSpan(
in ReadOnlySpan<sbyte3> source,
Span<float3> destination,
Unpack.Float mode = Numerics.Unpack.Float.Cast
)
{
UnpackSpan(source, destination, PackUtils.SByte.ToFloat(mode));
}
public static void UnpackSpan(
in ReadOnlySpan<byte3> source,
Span<float3> destination,
Unpack.Float mode = Numerics.Unpack.Float.Cast
)
{
UnpackSpan(source, destination, PackUtils.Byte.ToFloat(mode));
}
public static void UnpackSpan(
in ReadOnlySpan<short3> source,
Span<float3> destination,
Unpack.Float mode = Numerics.Unpack.Float.Cast
)
{
UnpackSpan(source, destination, PackUtils.Short.ToFloat(mode));
}
public static void UnpackSpan(
in ReadOnlySpan<ushort3> source,
Span<float3> destination,
Unpack.Float mode = Numerics.Unpack.Float.Cast
)
{
UnpackSpan(source, destination, PackUtils.UShort.ToFloat(mode));
}
public static void UnpackSpan(
in ReadOnlySpan<int3> source,
Span<float3> destination,
Unpack.Float mode = Numerics.Unpack.Float.Cast
)
{
UnpackSpan(source, destination, PackUtils.Int.ToFloat(mode));
}
public static void UnpackSpan(
in ReadOnlySpan<uint3> source,
Span<float3> destination,
Unpack.Float mode = Numerics.Unpack.Float.Cast
)
{
UnpackSpan(source, destination, PackUtils.UInt.ToFloat(mode));
}
public static void PackSpan(
in ReadOnlySpan<double3> source,
Span<float3> destination,
Pack.Float mode = Numerics.Pack.Float.Truncate
)
{
PackSpan(source, destination, PackUtils.Double.ToFloat(mode));
}
}

View file

@ -0,0 +1,400 @@
// <auto-generated /> - edit Vector.swizzle.tt to modify
#nullable enable
namespace Brutal.Numerics;
public partial struct float3
{
/// <summary>
/// Swizzle readonly getter/setter for the X and Y components of the vector.
/// </summary>
[XmlIgnore]
public float2 XY
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
readonly get => new(X, Y);
set
{
X = value.X;
Y = value.Y;
}
}
/// <summary>
/// Swizzle readonly getter/setter for the X and Z components of the vector.
/// </summary>
[XmlIgnore]
public float2 XZ
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
readonly get => new(X, Z);
set
{
X = value.X;
Z = value.Y;
}
}
/// <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;
}
}
/// <summary>
/// Swizzle readonly getter/setter for the Y and Z components of the vector.
/// </summary>
[XmlIgnore]
public float2 YZ
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
readonly get => new(Y, Z);
set
{
Y = value.X;
Z = value.Y;
}
}
/// <summary>
/// Swizzle readonly getter/setter for the Z and X components of the vector.
/// </summary>
[XmlIgnore]
public float2 ZX
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
readonly get => new(Z, X);
set
{
Z = value.X;
X = value.Y;
}
}
/// <summary>
/// Swizzle readonly getter/setter for the Z and Y components of the vector.
/// </summary>
[XmlIgnore]
public float2 ZY
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
readonly get => new(Z, Y);
set
{
Z = value.X;
Y = value.Y;
}
}
/// <summary>
/// Swizzle readonly getter/setter for the X, Y and Z components of the vector.
/// </summary>
[XmlIgnore]
public float3 XYZ
{
readonly get => this;
set => this = value;
}
/// <summary>
/// Swizzle readonly getter/setter for the X, Z and Y components of the vector.
/// </summary>
[XmlIgnore]
public float3 XZY
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
readonly get => new(X, Z, Y);
set
{
X = value.X;
Z = value.Y;
Y = value.Z;
}
}
/// <summary>
/// Swizzle readonly getter/setter for the Y, X and Z components of the vector.
/// </summary>
[XmlIgnore]
public float3 YXZ
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
readonly get => new(Y, X, Z);
set
{
Y = value.X;
X = value.Y;
Z = value.Z;
}
}
/// <summary>
/// Swizzle readonly getter/setter for the Y, Z and X components of the vector.
/// </summary>
[XmlIgnore]
public float3 YZX
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
readonly get => new(Y, Z, X);
set
{
Y = value.X;
Z = value.Y;
X = value.Z;
}
}
/// <summary>
/// Swizzle readonly getter/setter for the Z, X and Y components of the vector.
/// </summary>
[XmlIgnore]
public float3 ZXY
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
readonly get => new(Z, X, Y);
set
{
Z = value.X;
X = value.Y;
Y = value.Z;
}
}
/// <summary>
/// Swizzle readonly getter/setter for the Z, Y and X components of the vector.
/// </summary>
[XmlIgnore]
public float3 ZYX
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
readonly get => new(Z, Y, X);
set
{
Z = value.X;
Y = value.Y;
X = value.Z;
}
}
}
public partial struct float3
{
/// <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>
/// The Blue component of the vector (synonym for Z).
/// </summary>
[XmlIgnore]
public float B
{
readonly get => Z;
set => Z = value;
}
/// <summary>
/// Swizzle readonly getter/setter for the Red and Green components of the vector.
/// </summary>
[XmlIgnore]
public float2 RG
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
readonly get => new(R, G);
set
{
R = value.R;
G = value.G;
}
}
/// <summary>
/// Swizzle readonly getter/setter for the Red and Blue components of the vector.
/// </summary>
[XmlIgnore]
public float2 RB
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
readonly get => new(R, B);
set
{
R = value.R;
B = value.G;
}
}
/// <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(G, R);
set
{
G = value.R;
R = value.G;
}
}
/// <summary>
/// Swizzle readonly getter/setter for the Green and Blue components of the vector.
/// </summary>
[XmlIgnore]
public float2 GB
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
readonly get => new(G, B);
set
{
G = value.R;
B = value.G;
}
}
/// <summary>
/// Swizzle readonly getter/setter for the Blue and Red components of the vector.
/// </summary>
[XmlIgnore]
public float2 BR
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
readonly get => new(B, R);
set
{
B = value.R;
R = value.G;
}
}
/// <summary>
/// Swizzle readonly getter/setter for the Blue and Green components of the vector.
/// </summary>
[XmlIgnore]
public float2 BG
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
readonly get => new(B, G);
set
{
B = value.R;
G = value.G;
}
}
/// <summary>
/// Swizzle readonly getter/setter for the Red, Green, and Blue components of the vector.
/// </summary>
[XmlIgnore]
public float3 RGB
{
readonly get => this;
set => this = value;
}
/// <summary>
/// Swizzle readonly getter/setter for the Red, Blue, and Green components of the vector.
/// </summary>
[XmlIgnore]
public float3 RBG
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
readonly get => new(X, Z, Y);
set
{
R = value.R;
B = value.G;
G = value.B;
}
}
/// <summary>
/// Swizzle readonly getter/setter for the Green, Red, and Blue components of the vector.
/// </summary>
[XmlIgnore]
public float3 GRB
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
readonly get => new(Y, X, Z);
set
{
G = value.R;
R = value.G;
B = value.B;
}
}
/// <summary>
/// Swizzle readonly getter/setter for the Green, Blue, and Red components of the vector.
/// </summary>
[XmlIgnore]
public float3 GBR
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
readonly get => new(Y, Z, X);
set
{
G = value.R;
B = value.G;
R = value.B;
}
}
/// <summary>
/// Swizzle readonly getter/setter for the Blue, Red, and Green components of the vector.
/// </summary>
[XmlIgnore]
public float3 BRG
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
readonly get => new(Z, X, Y);
set
{
B = value.R;
R = value.G;
G = value.B;
}
}
/// <summary>
/// Swizzle readonly getter/setter for the Blue, Green, and Red components of the vector.
/// </summary>
[XmlIgnore]
public float3 BGR
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
readonly get => new(Z, Y, X);
set
{
B = value.R;
G = value.G;
R = value.B;
}
}
}