SOURCE DUMP v1

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

View file

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

View file

@ -0,0 +1,28 @@
// <auto-generated /> - edit Vector.copy.tt to modify
#nullable enable
namespace Brutal.Numerics;
public partial struct ushort4
{
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public readonly void CopyTo(Span<ushort> destination)
{
if (destination.Length < ComponentCount)
throw new ArgumentException("Length must be at least 4.", nameof(destination));
Unsafe.WriteUnaligned(ref Unsafe.As<ushort, byte>(ref MemoryMarshal.GetReference(destination)), this);
}
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public readonly bool TryCopyTo(Span<ushort> destination)
{
if (destination.Length < ComponentCount)
return false;
Unsafe.WriteUnaligned(ref Unsafe.As<ushort, 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 ushort4
{
/// <inheritdoc />
public readonly override int GetHashCode()
{
return HashCode.Combine(X, Y, Z, W);
}
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public readonly bool Equals(ushort4 other)
{
return X.Equals(other.X) && Y.Equals(other.Y) && Z.Equals(other.Z) && W.Equals(other.W);
}
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public readonly override bool Equals([NotNullWhen(true)] object? obj)
{
return obj is ushort4 other && Equals(other);
}
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool operator ==(ushort4 a, ushort4 b)
{
return a.X == b.X && a.Y == b.Y && a.Z == b.Z && a.W == b.W;
}
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool operator !=(ushort4 a, ushort4 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 ushort4 : ISpanFormattable, IUtf8SpanFormattable, ISpanParsable<ushort4>
{
/// <inheritdoc />
public readonly override string ToString()
{
return ToString("G", CultureInfo.CurrentCulture);
}
/// <inheritdoc cref="Vector4.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)}{separator} {W.ToString(format, formatProvider)}>";
}
/// <inheritdoc />
public readonly bool TryFormat(Span<char> destination, out int charsWritten, ReadOnlySpan<char> format, IFormatProvider? provider)
{
return StringHelpers.TryFormat<ushort4, ushort>(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<ushort4, ushort>(this, destination, out bytesWritten, format, provider);
}
/// <inheritdoc cref="Parse(ReadOnlySpan{char}, NumberStyles, IFormatProvider?)" />
public static ushort4 Parse(string s, IFormatProvider? provider)
{
ArgumentNullException.ThrowIfNull(s);
return Parse(s.AsSpan(), NumberStyles.Integer, provider);
}
/// <inheritdoc cref="Parse(ReadOnlySpan{char}, NumberStyles, IFormatProvider?)" />
public static ushort4 Parse(ReadOnlySpan<char> s, IFormatProvider? provider = null)
{
return Parse(s, NumberStyles.Integer, provider);
}
/// <inheritdoc cref="Parse(ReadOnlySpan{char}, NumberStyles, IFormatProvider?)" />
public static ushort4 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 ushort4 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 ushort4 format.");
return result;
}
/// <inheritdoc cref="TryParse(ReadOnlySpan{char}, NumberStyles, IFormatProvider?, out ushort4)" />
public static bool TryParse([NotNullWhen(true)] string? s, IFormatProvider? provider, out ushort4 result)
{
return TryParse(s.AsSpan(), NumberStyles.Integer, provider, out result);
}
/// <inheritdoc cref="TryParse(ReadOnlySpan{char}, NumberStyles, IFormatProvider?, out ushort4)" />
public static bool TryParse(ReadOnlySpan<char> s, IFormatProvider? provider, out ushort4 result)
{
return TryParse(s, NumberStyles.Integer, provider, out result);
}
/// <inheritdoc cref="TryParse(ReadOnlySpan{char}, NumberStyles, IFormatProvider?, out ushort4)" />
public static bool TryParse([NotNullWhen(true)] string? s, NumberStyles style, IFormatProvider? provider, out ushort4 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 ushort4.</returns>
public static bool TryParse(ReadOnlySpan<char> s, NumberStyles style, IFormatProvider? provider, out ushort4 result)
{
return StringHelpers.TryParse<ushort4, ushort>(s, style, provider, out result);
}
}

View file

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

View file

@ -0,0 +1,42 @@
// <auto-generated /> - edit Vector.math-metric.tt to modify
#nullable enable
namespace Brutal.Numerics;
public partial struct ushort4
{
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public readonly float Length()
{
return (float)double.Sqrt((double)X * X + (double)Y * Y + (double)Z * Z + (double)W * W);
}
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public readonly int LengthSquared()
{
return Dot(this, this);
}
/// <inheritdoc cref="Vector4.Distance" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float Distance(ushort4 a, ushort4 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) + ((double)a.Z - b.Z) * ((double)a.Z - b.Z) + ((double)a.W - b.W) * ((double)a.W - b.W));
}
/// <inheritdoc cref="Vector4.DistanceSquared" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static int DistanceSquared(ushort4 a, ushort4 b)
{
return (a.X - b.X) * (a.X - b.X) + (a.Y - b.Y) * (a.Y - b.Y) + (a.Z - b.Z) * (a.Z - b.Z) + (a.W - b.W) * (a.W - b.W);
}
/// <inheritdoc cref="Vector4.Dot" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static int Dot(ushort4 a, ushort4 b)
{
return a.X * b.X + a.Y * b.Y + a.Z * b.Z + a.W * b.W;
}
}

View file

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

View file

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

View file

@ -0,0 +1,210 @@
// <auto-generated /> - edit Vector.pack.tt to modify
#nullable enable
namespace Brutal.Numerics;
public partial struct ushort4
{
public static ushort4 Unpack(in sbyte4 vector, Func<sbyte, ushort> elementConverter)
{
VectorPack.Pack(vector, out ushort4 result, elementConverter);
return result;
}
public static ushort4 Unpack(in byte4 vector, Func<byte, ushort> elementConverter)
{
VectorPack.Pack(vector, out ushort4 result, elementConverter);
return result;
}
public static ushort4 Unpack(in short4 vector, Func<short, ushort> elementConverter)
{
VectorPack.Pack(vector, out ushort4 result, elementConverter);
return result;
}
public static ushort4 Pack(in int4 vector, Func<int, ushort> elementConverter)
{
VectorPack.Pack(vector, out ushort4 result, elementConverter);
return result;
}
public static ushort4 Pack(in uint4 vector, Func<uint, ushort> elementConverter)
{
VectorPack.Pack(vector, out ushort4 result, elementConverter);
return result;
}
public static ushort4 Pack(in float4 vector, Func<float, ushort> elementConverter)
{
VectorPack.Pack(vector, out ushort4 result, elementConverter);
return result;
}
public static ushort4 Pack(in double4 vector, Func<double, ushort> elementConverter)
{
VectorPack.Pack(vector, out ushort4 result, elementConverter);
return result;
}
public static ushort4 Unpack(in sbyte4 vector, Unpack.IntegerMixed mode = Numerics.Unpack.IntegerMixed.Cast)
{
return Unpack(vector, PackUtils.SByte.ToUShort(mode));
}
public static ushort4 Unpack(in byte4 vector, Unpack.Integer mode = Numerics.Unpack.Integer.Cast)
{
return Unpack(vector, PackUtils.Byte.ToUShort(mode));
}
public static ushort4 Unpack(in short4 vector, Unpack.IntegerMixed mode = Numerics.Unpack.IntegerMixed.Cast)
{
return Unpack(vector, PackUtils.Short.ToUShort(mode));
}
public static ushort4 Pack(in int4 vector, Pack.IntegerMixed mode = Numerics.Pack.IntegerMixed.Cast)
{
return Pack(vector, PackUtils.Int.ToUShort(mode));
}
public static ushort4 Pack(in uint4 vector, Pack.Integer mode = Numerics.Pack.Integer.Cast)
{
return Pack(vector, PackUtils.UInt.ToUShort(mode));
}
public static ushort4 Pack(in float4 vector, Pack.Float mode = Numerics.Pack.Float.Truncate)
{
return Pack(vector, PackUtils.Float.ToUShort(mode));
}
public static ushort4 Pack(in double4 vector, Pack.Float mode = Numerics.Pack.Float.Truncate)
{
return Pack(vector, PackUtils.Double.ToUShort(mode));
}
public static void UnpackSpan(
in ReadOnlySpan<sbyte4> source,
Span<ushort4> destination,
Func<sbyte, ushort> elementConverter
)
{
VectorPack.Pack(source, destination, elementConverter);
}
public static void UnpackSpan(
in ReadOnlySpan<byte4> source,
Span<ushort4> destination,
Func<byte, ushort> elementConverter
)
{
VectorPack.Pack(source, destination, elementConverter);
}
public static void UnpackSpan(
in ReadOnlySpan<short4> source,
Span<ushort4> destination,
Func<short, ushort> elementConverter
)
{
VectorPack.Pack(source, destination, elementConverter);
}
public static void PackSpan(
in ReadOnlySpan<int4> source,
Span<ushort4> destination,
Func<int, ushort> elementConverter
)
{
VectorPack.Pack(source, destination, elementConverter);
}
public static void PackSpan(
in ReadOnlySpan<uint4> source,
Span<ushort4> destination,
Func<uint, ushort> elementConverter
)
{
VectorPack.Pack(source, destination, elementConverter);
}
public static void PackSpan(
in ReadOnlySpan<float4> source,
Span<ushort4> destination,
Func<float, ushort> elementConverter
)
{
VectorPack.Pack(source, destination, elementConverter);
}
public static void PackSpan(
in ReadOnlySpan<double4> source,
Span<ushort4> destination,
Func<double, ushort> elementConverter
)
{
VectorPack.Pack(source, destination, elementConverter);
}
public static void UnpackSpan(
in ReadOnlySpan<sbyte4> source,
Span<ushort4> destination,
Unpack.IntegerMixed mode = Numerics.Unpack.IntegerMixed.Cast
)
{
UnpackSpan(source, destination, PackUtils.SByte.ToUShort(mode));
}
public static void UnpackSpan(
in ReadOnlySpan<byte4> source,
Span<ushort4> destination,
Unpack.Integer mode = Numerics.Unpack.Integer.Cast
)
{
UnpackSpan(source, destination, PackUtils.Byte.ToUShort(mode));
}
public static void UnpackSpan(
in ReadOnlySpan<short4> source,
Span<ushort4> destination,
Unpack.IntegerMixed mode = Numerics.Unpack.IntegerMixed.Cast
)
{
UnpackSpan(source, destination, PackUtils.Short.ToUShort(mode));
}
public static void PackSpan(
in ReadOnlySpan<int4> source,
Span<ushort4> destination,
Pack.IntegerMixed mode = Numerics.Pack.IntegerMixed.Cast
)
{
PackSpan(source, destination, PackUtils.Int.ToUShort(mode));
}
public static void PackSpan(
in ReadOnlySpan<uint4> source,
Span<ushort4> destination,
Pack.Integer mode = Numerics.Pack.Integer.Cast
)
{
PackSpan(source, destination, PackUtils.UInt.ToUShort(mode));
}
public static void PackSpan(
in ReadOnlySpan<float4> source,
Span<ushort4> destination,
Pack.Float mode = Numerics.Pack.Float.Truncate
)
{
PackSpan(source, destination, PackUtils.Float.ToUShort(mode));
}
public static void PackSpan(
in ReadOnlySpan<double4> source,
Span<ushort4> destination,
Pack.Float mode = Numerics.Pack.Float.Truncate
)
{
PackSpan(source, destination, PackUtils.Double.ToUShort(mode));
}
}

File diff suppressed because it is too large Load diff