SOURCE DUMP v1

This commit is contained in:
Rian Drake 2026-10-15 14:09:11 +13:00
commit fb20299e9d
8 changed files with 768360 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 ulong2
{
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public readonly void CopyTo(Span<ulong> destination)
{
if (destination.Length < ComponentCount)
throw new ArgumentException("Length must be at least 2.", nameof(destination));
Unsafe.WriteUnaligned(ref Unsafe.As<ulong, byte>(ref MemoryMarshal.GetReference(destination)), this);
}
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public readonly bool TryCopyTo(Span<ulong> destination)
{
if (destination.Length < ComponentCount)
return false;
Unsafe.WriteUnaligned(ref Unsafe.As<ulong, 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 ulong2
{
/// <inheritdoc />
public readonly override int GetHashCode()
{
return HashCode.Combine(X, Y);
}
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public readonly bool Equals(ulong2 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 ulong2 other && Equals(other);
}
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool operator ==(ulong2 a, ulong2 b)
{
return a.X == b.X && a.Y == b.Y;
}
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool operator !=(ulong2 a, ulong2 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 ulong2 : ISpanFormattable, IUtf8SpanFormattable, ISpanParsable<ulong2>
{
/// <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<ulong2, ulong>(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<ulong2, ulong>(this, destination, out bytesWritten, format, provider);
}
/// <inheritdoc cref="Parse(ReadOnlySpan{char}, NumberStyles, IFormatProvider?)" />
public static ulong2 Parse(string s, IFormatProvider? provider)
{
ArgumentNullException.ThrowIfNull(s);
return Parse(s.AsSpan(), NumberStyles.Integer, provider);
}
/// <inheritdoc cref="Parse(ReadOnlySpan{char}, NumberStyles, IFormatProvider?)" />
public static ulong2 Parse(ReadOnlySpan<char> s, IFormatProvider? provider = null)
{
return Parse(s, NumberStyles.Integer, provider);
}
/// <inheritdoc cref="Parse(ReadOnlySpan{char}, NumberStyles, IFormatProvider?)" />
public static ulong2 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 ulong2 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 ulong2 format.");
return result;
}
/// <inheritdoc cref="TryParse(ReadOnlySpan{char}, NumberStyles, IFormatProvider?, out ulong2)" />
public static bool TryParse([NotNullWhen(true)] string? s, IFormatProvider? provider, out ulong2 result)
{
return TryParse(s.AsSpan(), NumberStyles.Integer, provider, out result);
}
/// <inheritdoc cref="TryParse(ReadOnlySpan{char}, NumberStyles, IFormatProvider?, out ulong2)" />
public static bool TryParse(ReadOnlySpan<char> s, IFormatProvider? provider, out ulong2 result)
{
return TryParse(s, NumberStyles.Integer, provider, out result);
}
/// <inheritdoc cref="TryParse(ReadOnlySpan{char}, NumberStyles, IFormatProvider?, out ulong2)" />
public static bool TryParse([NotNullWhen(true)] string? s, NumberStyles style, IFormatProvider? provider, out ulong2 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 ulong2.</returns>
public static bool TryParse(ReadOnlySpan<char> s, NumberStyles style, IFormatProvider? provider, out ulong2 result)
{
return StringHelpers.TryParse<ulong2, ulong>(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 ulong components.
/// </summary>
[DebuggerTypeProxy(typeof(VectorDebugView2<ulong2, ulong, double>))]
public partial struct ulong2 : IVector2<ulong2, ulong>
, IIntegerVector<ulong2, ulong, ulong, double>
{
/// <inheritdoc />
public static int ComponentSize => sizeof(ulong);
/// <summary>Gets the number of components.</summary>
public static int ComponentCount => 2;
/// <inheritdoc cref="Vector2.X" />
[XmlAttribute]
public ulong X;
/// <inheritdoc cref="Vector2.Y" />
[XmlAttribute]
public ulong Y;
ulong IVector2<ulong2, ulong>.X { readonly get => X; set => X = value; }
ulong IVector2<ulong2, ulong>.Y { readonly get => Y; set => Y = value; }
/// <inheritdoc cref="Vector2(float, float)" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public ulong2(ulong x, ulong y)
{
X = x;
Y = y;
}
/// <inheritdoc cref="Vector2(float)" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public ulong2(ulong 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 ulong2(ReadOnlySpan<ulong> span)
{
if (span.Length < 2)
throw new ArgumentOutOfRangeException(nameof(span), "Length must be at least 2.");
this = Unsafe.ReadUnaligned<ulong2>(ref Unsafe.As<ulong, byte>(ref MemoryMarshal.GetReference(span)));
}
/// <inheritdoc cref="ulong2(ReadOnlySpan{ulong})" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static ulong2 IComponentTuple<ulong2, ulong>.Create(ReadOnlySpan<ulong> span) => new(span);
/// <inheritdoc />
public static ulong2 UnitX => new(1, 0);
/// <inheritdoc />
public static ulong2 UnitY => new(0, 1);
/// <inheritdoc />
public ulong 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 ulong x, out ulong y)
{
x = X;
y = Y;
}
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public Span<ulong> AsSpan()
{
return MemoryMarshal.CreateSpan(ref Unsafe.As<ulong2, ulong>(ref this), 2);
}
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public readonly ReadOnlySpan<ulong> AsReadOnlySpan()
{
return MemoryMarshal.CreateReadOnlySpan(in Unsafe.As<ulong2, ulong>(ref Unsafe.AsRef(in this)), 2);
}
}

View file

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

View file

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