This commit is contained in:
Rian Drake 2026-10-15 14:09:11 +13:00
commit b578433e37
9 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 uint2
{
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public readonly void CopyTo(Span<uint> destination)
{
if (destination.Length < ComponentCount)
throw new ArgumentException("Length must be at least 2.", nameof(destination));
Unsafe.WriteUnaligned(ref Unsafe.As<uint, byte>(ref MemoryMarshal.GetReference(destination)), this);
}
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public readonly bool TryCopyTo(Span<uint> destination)
{
if (destination.Length < ComponentCount)
return false;
Unsafe.WriteUnaligned(ref Unsafe.As<uint, 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 uint2
{
/// <inheritdoc />
public readonly override int GetHashCode()
{
return HashCode.Combine(X, Y);
}
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public readonly bool Equals(uint2 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 uint2 other && Equals(other);
}
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool operator ==(uint2 a, uint2 b)
{
return a.X == b.X && a.Y == b.Y;
}
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool operator !=(uint2 a, uint2 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 uint2 : ISpanFormattable, IUtf8SpanFormattable, ISpanParsable<uint2>
{
/// <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<uint2, uint>(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<uint2, uint>(this, destination, out bytesWritten, format, provider);
}
/// <inheritdoc cref="Parse(ReadOnlySpan{char}, NumberStyles, IFormatProvider?)" />
public static uint2 Parse(string s, IFormatProvider? provider)
{
ArgumentNullException.ThrowIfNull(s);
return Parse(s.AsSpan(), NumberStyles.Integer, provider);
}
/// <inheritdoc cref="Parse(ReadOnlySpan{char}, NumberStyles, IFormatProvider?)" />
public static uint2 Parse(ReadOnlySpan<char> s, IFormatProvider? provider = null)
{
return Parse(s, NumberStyles.Integer, provider);
}
/// <inheritdoc cref="Parse(ReadOnlySpan{char}, NumberStyles, IFormatProvider?)" />
public static uint2 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 uint2 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 uint2 format.");
return result;
}
/// <inheritdoc cref="TryParse(ReadOnlySpan{char}, NumberStyles, IFormatProvider?, out uint2)" />
public static bool TryParse([NotNullWhen(true)] string? s, IFormatProvider? provider, out uint2 result)
{
return TryParse(s.AsSpan(), NumberStyles.Integer, provider, out result);
}
/// <inheritdoc cref="TryParse(ReadOnlySpan{char}, NumberStyles, IFormatProvider?, out uint2)" />
public static bool TryParse(ReadOnlySpan<char> s, IFormatProvider? provider, out uint2 result)
{
return TryParse(s, NumberStyles.Integer, provider, out result);
}
/// <inheritdoc cref="TryParse(ReadOnlySpan{char}, NumberStyles, IFormatProvider?, out uint2)" />
public static bool TryParse([NotNullWhen(true)] string? s, NumberStyles style, IFormatProvider? provider, out uint2 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 uint2.</returns>
public static bool TryParse(ReadOnlySpan<char> s, NumberStyles style, IFormatProvider? provider, out uint2 result)
{
return StringHelpers.TryParse<uint2, uint>(s, style, provider, out result);
}
}

View file

@ -0,0 +1,106 @@
// <auto-generated /> - edit Vector.tt to modify
#nullable enable
namespace Brutal.Numerics;
/// <summary>
/// Implements a 2D vector with uint components.
/// </summary>
[DebuggerTypeProxy(typeof(VectorDebugView2<uint2, uint, float>))]
public partial struct uint2 : IVector2<uint2, uint>
, IIntegerVector<uint2, uint, uint, float>
{
/// <inheritdoc />
public static int ComponentSize => sizeof(uint);
/// <summary>Gets the number of components.</summary>
public static int ComponentCount => 2;
/// <inheritdoc cref="Vector2.X" />
[XmlAttribute]
public uint X;
/// <inheritdoc cref="Vector2.Y" />
[XmlAttribute]
public uint Y;
uint IVector2<uint2, uint>.X { readonly get => X; set => X = value; }
uint IVector2<uint2, uint>.Y { readonly get => Y; set => Y = value; }
/// <inheritdoc cref="Vector2(float, float)" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public uint2(uint x, uint y)
{
X = x;
Y = y;
}
/// <inheritdoc cref="Vector2(float)" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public uint2(uint 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 uint2(ReadOnlySpan<uint> span)
{
if (span.Length < 2)
throw new ArgumentOutOfRangeException(nameof(span), "Length must be at least 2.");
this = Unsafe.ReadUnaligned<uint2>(ref Unsafe.As<uint, byte>(ref MemoryMarshal.GetReference(span)));
}
/// <inheritdoc cref="uint2(ReadOnlySpan{uint})" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static uint2 IComponentTuple<uint2, uint>.Create(ReadOnlySpan<uint> span) => new(span);
/// <inheritdoc />
public static uint2 UnitX => new(1, 0);
/// <inheritdoc />
public static uint2 UnitY => new(0, 1);
/// <inheritdoc />
public uint 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 uint x, out uint y)
{
x = X;
y = Y;
}
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public Span<uint> AsSpan()
{
return MemoryMarshal.CreateSpan(ref Unsafe.As<uint2, uint>(ref this), 2);
}
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public readonly ReadOnlySpan<uint> AsReadOnlySpan()
{
return MemoryMarshal.CreateReadOnlySpan(in Unsafe.As<uint2, uint>(ref Unsafe.AsRef(in this)), 2);
}
}

View file

@ -0,0 +1,43 @@
// <auto-generated /> - edit Vector.math-metric.tt to modify
#nullable enable
namespace Brutal.Numerics;
public partial struct uint2
{
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public readonly float Length()
{
return (float)double.Sqrt((double)X * X + (double)Y * Y);
}
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public readonly uint LengthSquared()
{
return Dot(this, this);
}
/// <inheritdoc cref="Vector2.Distance" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float Distance(uint2 a, uint2 b)
{
return (float)double.Sqrt(((double)a.X - b.X) * ((double)a.X - b.X) + ((double)a.Y - b.Y) * ((double)a.Y - b.Y));
}
/// <inheritdoc cref="Vector2.DistanceSquared" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static uint DistanceSquared(uint2 a, uint2 b)
{
var difference = a - b;
return Dot(difference, difference);
}
/// <inheritdoc cref="Vector2.Dot" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static uint Dot(uint2 a, uint2 b)
{
return a.X * b.X + a.Y * b.Y;
}
}

View file

@ -0,0 +1,100 @@
// <auto-generated /> - edit Vector.numerics-binary.tt to modify
#nullable enable
namespace Brutal.Numerics;
// IBinaryNumber
public partial struct uint2 : IBinaryNumber<uint2>
{
/// <summary>Determines if every component of a value is a power of two.</summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static bool IBinaryNumber<uint2>.IsPow2(uint2 value)
{
return uint.IsPow2(value.X) && uint.IsPow2(value.Y);
}
/// <inheritdoc cref="IBinaryNumber{TSelf}.Log2" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static uint2 Log2(uint2 value)
{
return new uint2(uint.Log2(value.X), uint.Log2(value.Y));
}
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static uint2 operator &(uint2 a, uint2 b)
{
return new(a.X & b.X, a.Y & b.Y);
}
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static uint2 operator |(uint2 a, uint2 b)
{
return new(a.X | b.X, a.Y | b.Y);
}
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static uint2 operator ^(uint2 a, uint2 b)
{
return new(a.X ^ b.X, a.Y ^ b.Y);
}
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static uint2 operator ~(uint2 value)
{
return new(~value.X, ~value.Y);
}
}
// the componentwise predicate mask (no interface to mirror) - the per-lane truth IsPow2 collapses
public partial struct uint2
{
/// <summary>Determines which components of a value are powers of two.</summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool2 IsPow2(uint2 value)
{
return new bool2(uint.IsPow2(value.X), uint.IsPow2(value.Y));
}
}
// the good bits from IBinaryInteger - declared on IIntegerVector
public partial struct uint2
{
/// <inheritdoc cref="IBinaryInteger{TSelf}.PopCount" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static uint2 PopCount(uint2 value)
{
return new uint2(uint.PopCount(value.X), uint.PopCount(value.Y));
}
/// <inheritdoc cref="IBinaryInteger{TSelf}.LeadingZeroCount" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static uint2 LeadingZeroCount(uint2 value)
{
return new uint2(uint.LeadingZeroCount(value.X), uint.LeadingZeroCount(value.Y));
}
/// <inheritdoc cref="IBinaryInteger{TSelf}.TrailingZeroCount" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static uint2 TrailingZeroCount(uint2 value)
{
return new uint2(uint.TrailingZeroCount(value.X), uint.TrailingZeroCount(value.Y));
}
/// <inheritdoc cref="IBinaryInteger{TSelf}.RotateLeft" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static uint2 RotateLeft(uint2 value, int rotateAmount)
{
return new uint2(uint.RotateLeft(value.X, rotateAmount), uint.RotateLeft(value.Y, rotateAmount));
}
/// <inheritdoc cref="IBinaryInteger{TSelf}.RotateRight" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static uint2 RotateRight(uint2 value, int rotateAmount)
{
return new uint2(uint.RotateRight(value.X, rotateAmount), uint.RotateRight(value.Y, rotateAmount));
}
}

View file

@ -0,0 +1,389 @@
// <auto-generated /> - edit Vector.numerics.tt to modify
#nullable enable
namespace Brutal.Numerics;
// INumberBase
public partial struct uint2 : INumberBase<uint2>
{
/// <inheritdoc />
public static uint2 Zero => new(0);
/// <inheritdoc />
public static uint2 One => new(1);
static uint2 IAdditiveIdentity<uint2, uint2>.AdditiveIdentity => Zero;
static uint2 IMultiplicativeIdentity<uint2, uint2>.MultiplicativeIdentity => One;
static int INumberBase<uint2>.Radix => 2; // every component type is binary
static uint2 INumberBase<uint2>.Abs(uint2 value) => value;
static bool INumberBase<uint2>.IsCanonical(uint2 value) => true;
static bool INumberBase<uint2>.IsComplexNumber(uint2 value) => false;
static bool INumberBase<uint2>.IsImaginaryNumber(uint2 value) => false;
/// <summary>Determines if every component of a value is zero.</summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static bool INumberBase<uint2>.IsZero(uint2 value)
{
return value == Zero;
}
/// <summary>Determines if every component of a value is an even integral value.</summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static bool INumberBase<uint2>.IsEvenInteger(uint2 value)
{
return (value.X & 1) == 0 && (value.Y & 1) == 0;
}
/// <summary>Determines if every component of a value is an odd integral value.</summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static bool INumberBase<uint2>.IsOddInteger(uint2 value)
{
return (value.X & 1) == 1 && (value.Y & 1) == 1;
}
static bool INumberBase<uint2>.IsNegative(uint2 value) => false;
static bool INumberBase<uint2>.IsPositive(uint2 value) => true;
static bool INumberBase<uint2>.IsFinite(uint2 value) => true;
static bool INumberBase<uint2>.IsInfinity(uint2 value) => false;
static bool INumberBase<uint2>.IsNegativeInfinity(uint2 value) => false;
static bool INumberBase<uint2>.IsPositiveInfinity(uint2 value) => false;
static bool INumberBase<uint2>.IsInteger(uint2 value) => true;
static bool INumberBase<uint2>.IsRealNumber(uint2 value) => true;
static bool INumberBase<uint2>.IsNaN(uint2 value) => false;
static bool INumberBase<uint2>.IsNormal(uint2 value) => value.X != 0 && value.Y != 0;
static bool INumberBase<uint2>.IsSubnormal(uint2 value) => false;
/// <summary>Computes, componentwise, the value whose magnitude is greater.</summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static uint2 MaxMagnitude(uint2 a, uint2 b)
{
return Max(a, b);
}
/// <summary>Computes, componentwise, the value whose magnitude is greater.</summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static uint2 MaxMagnitudeNumber(uint2 a, uint2 b)
{
return Max(a, b);
}
/// <summary>Computes, componentwise, the value whose magnitude is smaller.</summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static uint2 MinMagnitude(uint2 a, uint2 b)
{
return Min(a, b);
}
/// <summary>Computes, componentwise, the value whose magnitude is smaller.</summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static uint2 MinMagnitudeNumber(uint2 a, uint2 b)
{
return Min(a, b);
}
/// <inheritdoc cref="Vector2.Add" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static uint2 Add(uint2 a, uint2 b)
{
return a + b;
}
/// <inheritdoc cref="Vector2.Divide(Vector2, Vector2)" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static uint2 Divide(uint2 a, uint2 b)
{
return a / b;
}
/// <inheritdoc cref="Vector2.Multiply(Vector2, Vector2)" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static uint2 Multiply(uint2 a, uint2 b)
{
return a * b;
}
/// <inheritdoc cref="Vector2.Negate" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static uint2 Negate(uint2 value)
{
return -value;
}
/// <inheritdoc cref="Vector2.Subtract" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static uint2 Subtract(uint2 a, uint2 b)
{
return a - b;
}
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static uint2 operator +(uint2 a, uint2 b)
{
return new(a.X + b.X, a.Y + b.Y);
}
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static uint2 operator -(uint2 a, uint2 b)
{
return new(a.X - b.X, a.Y - b.Y);
}
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static uint2 operator *(uint2 a, uint2 b)
{
return new(a.X * b.X, a.Y * b.Y);
}
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static uint2 operator /(uint2 a, uint2 b)
{
return new(a.X / b.X, a.Y / b.Y);
}
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static uint2 operator -(uint2 a)
{
return new(0 - a.X, 0 - a.Y);
}
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static uint2 operator +(uint2 a)
{
return a;
}
// ++/-- are well-defined (+/- One) but a footgun on a concrete vector: generic-plane only.
static uint2 IIncrementOperators<uint2>.operator ++(uint2 value) => value + One;
static uint2 IDecrementOperators<uint2>.operator --(uint2 value) => value - One;
static bool INumberBase<uint2>.TryConvertFromChecked<TOther>(TOther value, out uint2 result)
{
return NumberConversion.TryConvertFrom<uint2, uint, TOther, NumberConversion.Checked>(value, out result);
}
static bool INumberBase<uint2>.TryConvertToChecked<TOther>(uint2 value, [MaybeNullWhen(false)] out TOther result)
{
result = default;
return false;
}
static bool INumberBase<uint2>.TryConvertFromSaturating<TOther>(TOther value, out uint2 result)
{
return NumberConversion.TryConvertFrom<uint2, uint, TOther, NumberConversion.Saturating>(value, out result);
}
static bool INumberBase<uint2>.TryConvertToSaturating<TOther>(uint2 value, [MaybeNullWhen(false)] out TOther result)
{
result = default;
return false;
}
static bool INumberBase<uint2>.TryConvertFromTruncating<TOther>(TOther value, out uint2 result)
{
return NumberConversion.TryConvertFrom<uint2, uint, TOther, NumberConversion.Truncating>(value, out result);
}
static bool INumberBase<uint2>.TryConvertToTruncating<TOther>(uint2 value, [MaybeNullWhen(false)] out TOther result)
{
result = default;
return false;
}
}
// IMultiplyOperators<TSelf, TComponent, TSelf>, IDivisionOperators<TSelf, TComponent, TSelf>
public partial struct uint2
: IMultiplyOperators<uint2, uint, uint2>
, IDivisionOperators<uint2, uint, uint2>
{
/// <inheritdoc cref="Vector2.Divide(Vector2, float)" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static uint2 Divide(uint2 a, uint b)
{
return a / b;
}
/// <inheritdoc cref="Vector2.Multiply(Vector2, float)" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static uint2 Multiply(uint2 a, uint b)
{
return a * b;
}
/// <inheritdoc cref="Vector2.Multiply(float, Vector2)" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static uint2 Multiply(uint a, uint2 b)
{
return a * b;
}
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static uint2 operator *(uint2 a, uint b)
{
return new(a.X * b, a.Y * b);
}
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static uint2 operator /(uint2 a, uint b)
{
return new(a.X / b, a.Y / b);
}
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static uint2 operator *(uint a, uint2 b)
{
return new(a * b.X, a * b.Y);
}
}
// INumber
public partial struct uint2 : INumber<uint2>
{
/// <inheritdoc cref="Vector2.Clamp" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static uint2 Clamp(uint2 value, uint2 min, uint2 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 uint2 Max(uint2 a, uint2 b)
{
return new(uint.Max(a.X, b.X), uint.Max(a.Y, b.Y));
}
/// <inheritdoc cref="Vector2.Min" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static uint2 Min(uint2 a, uint2 b)
{
return new(uint.Min(a.X, b.X), uint.Min(a.Y, b.Y));
}
static uint2 INumber<uint2>.MaxNumber(uint2 a, uint2 b) => Max(a, b);
static uint2 INumber<uint2>.MinNumber(uint2 a, uint2 b) => Min(a, b);
static uint2 INumber<uint2>.CopySign(uint2 value, uint2 sign) => value;
// the Native variants permit either NaN/signed-zero behavior - forwarding is always legal
static uint2 INumber<uint2>.ClampNative(uint2 value, uint2 min, uint2 max) => Clamp(value, min, max);
static uint2 INumber<uint2>.MaxNative(uint2 a, uint2 b) => Max(a, b);
static uint2 INumber<uint2>.MinNative(uint2 a, uint2 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<uint2>.Sign(uint2 value) =>
throw new NotSupportedException($"{nameof(uint2)} has no scalar sign.");
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static uint2 operator %(uint2 a, uint2 b)
{
return new uint2(a.X % b.X, a.Y % b.Y);
}
int IComparable.CompareTo(object? obj) =>
throw new NotSupportedException($"{nameof(uint2)} has no total order.");
int IComparable<uint2>.CompareTo(uint2 other) =>
throw new NotSupportedException($"{nameof(uint2)} has no total order.");
static bool IComparisonOperators<uint2, uint2, bool>.operator <(uint2 a, uint2 b) =>
throw new NotSupportedException($"{nameof(uint2)} has no total order.");
static bool IComparisonOperators<uint2, uint2, bool>.operator <=(uint2 a, uint2 b) =>
throw new NotSupportedException($"{nameof(uint2)} has no total order.");
static bool IComparisonOperators<uint2, uint2, bool>.operator >(uint2 a, uint2 b) =>
throw new NotSupportedException($"{nameof(uint2)} has no total order.");
static bool IComparisonOperators<uint2, uint2, bool>.operator >=(uint2 a, uint2 b) =>
throw new NotSupportedException($"{nameof(uint2)} has no total order.");
}
// IComponentwiseComparison + the componentwise predicate masks (no interface to mirror)
public partial struct uint2 : IComponentwiseComparison<uint2, bool2>
{
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool2 operator <(uint2 a, uint2 b)
{
return new bool2(a.X < b.X, a.Y < b.Y);
}
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool2 operator <=(uint2 a, uint2 b)
{
return new bool2(a.X <= b.X, a.Y <= b.Y);
}
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool2 operator >(uint2 a, uint2 b)
{
return new bool2(a.X > b.X, a.Y > b.Y);
}
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool2 operator >=(uint2 a, uint2 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(uint2 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(uint2 value)
{
return new bool2(uint.IsEvenInteger(value.X), uint.IsEvenInteger(value.Y));
}
/// <summary>Determines which components of a value are an odd integral value.</summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool2 IsOddInteger(uint2 value)
{
return new bool2(uint.IsOddInteger(value.X), uint.IsOddInteger(value.Y));
}
}
// IUnsignedNumber - a marker, so there is nothing to implement
public partial struct uint2 : IUnsignedNumber<uint2>;

View file

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

View file

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