SOURCE DUMP v1

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

View file

@ -0,0 +1,87 @@
// <auto-generated /> - edit Vector.color.tt to modify
#nullable enable
namespace Brutal.Numerics;
public partial struct byte3
{
/// <summary>
/// Constructs a byte3 vector representing an RGB color.
/// </summary>
/// <param name="r">Red component.</param>
/// <param name="g">Green component.</param>
/// <param name="b">Blue component.</param>
/// <returns>A byte3 color with the specified RGB values.</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static byte3 Rgb(byte r, byte g, byte b)
{
return new byte3(r, g, b);
}
/// <summary>
/// Constructs a byte3 vector representing a grayscale color.
/// </summary>
/// <param name="v">Single value used for red, green, and blue components.</param>
/// <returns>A byte3 grayscale color with the specified value.</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static byte3 Grayscale(byte v)
{
return new byte3(v, v, v);
}
}
// Specialized for byte3
public partial struct byte3
{
/// <summary>
/// Construct a byte3 vector from a uint hex value
/// </summary>
/// <param name="hex">Color value as a uint</param>
/// <returns>A byte3 color with the specified RGB values.</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static byte3 Hex(uint hex)
{
return new byte3((byte)(hex >> 16), (byte)(hex >> 8), (byte)(hex >> 0));
}
/// <summary>
/// Construct a byte3 vector in a RGB color context, from a uint hex value
/// </summary>
/// <param name="hex">uint value</param>
/// <returns>A byte3 color with the specified RGB values.</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static byte3 HexColor(uint hex)
{
return Hex(hex);
}
/// <summary>
/// Construct a byte3 vector from a uint hex value string
/// </summary>
/// <param name="hex">Hexadecimal string representation in 0xRRGGBBAA format.</param>
/// <returns>vector</returns>
public static byte3 Hex(ReadOnlySpan<char> hex)
{
if (hex.Length != 8 || hex[0] != '0' || hex[1] != 'x')
throw new FormatException("Invalid hex format");
return Hex(uint.Parse(hex[2..], NumberStyles.HexNumber));
}
/// <summary>
/// Construct a byte3 vector in an RGB color context, from a uint hex value string
/// </summary>
/// <param name="hex">Hexadecimal string representation in 0xRRGGBBAA format.</param>
/// <returns>vector</returns>
public static byte3 HexColor(ReadOnlySpan<char> hex)
{
return Hex(hex);
}
/// <summary>
/// Converts the byte3 color to a hexadecimal string.
/// </summary>
public readonly string ToHexString()
{
return $"0x{R:X2}{G:X2}{B:X2}";
}
}

View file

@ -0,0 +1,28 @@
// <auto-generated /> - edit Vector.copy.tt to modify
#nullable enable
namespace Brutal.Numerics;
public partial struct byte3
{
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public readonly void CopyTo(Span<byte> destination)
{
if (destination.Length < ComponentCount)
throw new ArgumentException("Length must be at least 3.", nameof(destination));
Unsafe.WriteUnaligned(ref Unsafe.As<byte, byte>(ref MemoryMarshal.GetReference(destination)), this);
}
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public readonly bool TryCopyTo(Span<byte> destination)
{
if (destination.Length < ComponentCount)
return false;
Unsafe.WriteUnaligned(ref Unsafe.As<byte, 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 byte3
{
/// <inheritdoc />
public readonly override int GetHashCode()
{
return HashCode.Combine(X, Y, Z);
}
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public readonly bool Equals(byte3 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 byte3 other && Equals(other);
}
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool operator ==(byte3 a, byte3 b)
{
return a.X == b.X && a.Y == b.Y && a.Z == b.Z;
}
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool operator !=(byte3 a, byte3 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 byte3 : ISpanFormattable, IUtf8SpanFormattable, ISpanParsable<byte3>
{
/// <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<byte3, byte>(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<byte3, byte>(this, destination, out bytesWritten, format, provider);
}
/// <inheritdoc cref="Parse(ReadOnlySpan{char}, NumberStyles, IFormatProvider?)" />
public static byte3 Parse(string s, IFormatProvider? provider)
{
ArgumentNullException.ThrowIfNull(s);
return Parse(s.AsSpan(), NumberStyles.Integer, provider);
}
/// <inheritdoc cref="Parse(ReadOnlySpan{char}, NumberStyles, IFormatProvider?)" />
public static byte3 Parse(ReadOnlySpan<char> s, IFormatProvider? provider = null)
{
return Parse(s, NumberStyles.Integer, provider);
}
/// <inheritdoc cref="Parse(ReadOnlySpan{char}, NumberStyles, IFormatProvider?)" />
public static byte3 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 byte3 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 byte3 format.");
return result;
}
/// <inheritdoc cref="TryParse(ReadOnlySpan{char}, NumberStyles, IFormatProvider?, out byte3)" />
public static bool TryParse([NotNullWhen(true)] string? s, IFormatProvider? provider, out byte3 result)
{
return TryParse(s.AsSpan(), NumberStyles.Integer, provider, out result);
}
/// <inheritdoc cref="TryParse(ReadOnlySpan{char}, NumberStyles, IFormatProvider?, out byte3)" />
public static bool TryParse(ReadOnlySpan<char> s, IFormatProvider? provider, out byte3 result)
{
return TryParse(s, NumberStyles.Integer, provider, out result);
}
/// <inheritdoc cref="TryParse(ReadOnlySpan{char}, NumberStyles, IFormatProvider?, out byte3)" />
public static bool TryParse([NotNullWhen(true)] string? s, NumberStyles style, IFormatProvider? provider, out byte3 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 byte3.</returns>
public static bool TryParse(ReadOnlySpan<char> s, NumberStyles style, IFormatProvider? provider, out byte3 result)
{
return StringHelpers.TryParse<byte3, byte>(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 byte components.
/// </summary>
[DebuggerTypeProxy(typeof(VectorDebugView3<byte3, byte, float>))]
public partial struct byte3 : IVector3<byte3, byte>
, IIntegerVector<byte3, byte, int, float>
, ICrossProduct<byte3>
{
/// <inheritdoc />
public static int ComponentSize => sizeof(byte);
/// <summary>Gets the number of components.</summary>
public static int ComponentCount => 3;
/// <inheritdoc cref="Vector3.X" />
[XmlAttribute]
public byte X;
/// <inheritdoc cref="Vector3.Y" />
[XmlAttribute]
public byte Y;
/// <inheritdoc cref="Vector3.Z" />
[XmlAttribute]
public byte Z;
byte IVector3<byte3, byte>.X { readonly get => X; set => X = value; }
byte IVector3<byte3, byte>.Y { readonly get => Y; set => Y = value; }
byte IVector3<byte3, byte>.Z { readonly get => Z; set => Z = value; }
/// <inheritdoc cref="Vector3(float, float, float)" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public byte3(byte x, byte y, byte z)
{
X = x;
Y = y;
Z = z;
}
/// <inheritdoc cref="Vector3(float)" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public byte3(byte xyz)
: this(xyz, xyz, xyz) { }
/// <inheritdoc cref="Vector3(Vector2, float)" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public byte3(byte2 xy, byte 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 byte3(ReadOnlySpan<byte> span)
{
if (span.Length < 3)
throw new ArgumentOutOfRangeException(nameof(span), "Length must be at least 3.");
this = Unsafe.ReadUnaligned<byte3>(ref Unsafe.As<byte, byte>(ref MemoryMarshal.GetReference(span)));
}
/// <inheritdoc cref="byte3(ReadOnlySpan{byte})" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static byte3 IComponentTuple<byte3, byte>.Create(ReadOnlySpan<byte> span) => new(span);
/// <inheritdoc />
public static byte3 UnitX => new(1, 0, 0);
/// <inheritdoc />
public static byte3 UnitY => new(0, 1, 0);
/// <inheritdoc />
public static byte3 UnitZ => new(0, 0, 1);
/// <inheritdoc />
public byte 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 byte x, out byte y, out byte z)
{
x = X;
y = Y;
z = Z;
}
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public Span<byte> AsSpan()
{
return MemoryMarshal.CreateSpan(ref Unsafe.As<byte3, byte>(ref this), 3);
}
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public readonly ReadOnlySpan<byte> AsReadOnlySpan()
{
return MemoryMarshal.CreateReadOnlySpan(in Unsafe.As<byte3, byte>(ref Unsafe.AsRef(in this)), 3);
}
}

View file

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

View file

@ -0,0 +1,17 @@
// <auto-generated /> - edit Vector.math.tt to modify
#nullable enable
namespace Brutal.Numerics;
public partial struct byte3
{
/// <inheritdoc cref="Vector3.Cross" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static byte3 Cross(byte3 a, byte3 b)
{
return new(
(byte)(a.Y * b.Z - a.Z * b.Y),
(byte)(a.Z * b.X - a.X * b.Z),
(byte)(a.X * b.Y - a.Y * b.X));
}
}

View file

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

View file

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

View file

@ -0,0 +1,210 @@
// <auto-generated /> - edit Vector.pack.tt to modify
#nullable enable
namespace Brutal.Numerics;
public partial struct byte3
{
public static byte3 Unpack(in sbyte3 vector, Func<sbyte, byte> elementConverter)
{
VectorPack.Pack(vector, out byte3 result, elementConverter);
return result;
}
public static byte3 Pack(in short3 vector, Func<short, byte> elementConverter)
{
VectorPack.Pack(vector, out byte3 result, elementConverter);
return result;
}
public static byte3 Pack(in ushort3 vector, Func<ushort, byte> elementConverter)
{
VectorPack.Pack(vector, out byte3 result, elementConverter);
return result;
}
public static byte3 Pack(in int3 vector, Func<int, byte> elementConverter)
{
VectorPack.Pack(vector, out byte3 result, elementConverter);
return result;
}
public static byte3 Pack(in uint3 vector, Func<uint, byte> elementConverter)
{
VectorPack.Pack(vector, out byte3 result, elementConverter);
return result;
}
public static byte3 Pack(in float3 vector, Func<float, byte> elementConverter)
{
VectorPack.Pack(vector, out byte3 result, elementConverter);
return result;
}
public static byte3 Pack(in double3 vector, Func<double, byte> elementConverter)
{
VectorPack.Pack(vector, out byte3 result, elementConverter);
return result;
}
public static byte3 Unpack(in sbyte3 vector, Unpack.IntegerMixed mode = Numerics.Unpack.IntegerMixed.Cast)
{
return Unpack(vector, PackUtils.SByte.ToByte(mode));
}
public static byte3 Pack(in short3 vector, Pack.IntegerMixed mode = Numerics.Pack.IntegerMixed.Cast)
{
return Pack(vector, PackUtils.Short.ToByte(mode));
}
public static byte3 Pack(in ushort3 vector, Pack.Integer mode = Numerics.Pack.Integer.Cast)
{
return Pack(vector, PackUtils.UShort.ToByte(mode));
}
public static byte3 Pack(in int3 vector, Pack.IntegerMixed mode = Numerics.Pack.IntegerMixed.Cast)
{
return Pack(vector, PackUtils.Int.ToByte(mode));
}
public static byte3 Pack(in uint3 vector, Pack.Integer mode = Numerics.Pack.Integer.Cast)
{
return Pack(vector, PackUtils.UInt.ToByte(mode));
}
public static byte3 Pack(in float3 vector, Pack.Float mode = Numerics.Pack.Float.Truncate)
{
return Pack(vector, PackUtils.Float.ToByte(mode));
}
public static byte3 Pack(in double3 vector, Pack.Float mode = Numerics.Pack.Float.Truncate)
{
return Pack(vector, PackUtils.Double.ToByte(mode));
}
public static void UnpackSpan(
in ReadOnlySpan<sbyte3> source,
Span<byte3> destination,
Func<sbyte, byte> elementConverter
)
{
VectorPack.Pack(source, destination, elementConverter);
}
public static void PackSpan(
in ReadOnlySpan<short3> source,
Span<byte3> destination,
Func<short, byte> elementConverter
)
{
VectorPack.Pack(source, destination, elementConverter);
}
public static void PackSpan(
in ReadOnlySpan<ushort3> source,
Span<byte3> destination,
Func<ushort, byte> elementConverter
)
{
VectorPack.Pack(source, destination, elementConverter);
}
public static void PackSpan(
in ReadOnlySpan<int3> source,
Span<byte3> destination,
Func<int, byte> elementConverter
)
{
VectorPack.Pack(source, destination, elementConverter);
}
public static void PackSpan(
in ReadOnlySpan<uint3> source,
Span<byte3> destination,
Func<uint, byte> elementConverter
)
{
VectorPack.Pack(source, destination, elementConverter);
}
public static void PackSpan(
in ReadOnlySpan<float3> source,
Span<byte3> destination,
Func<float, byte> elementConverter
)
{
VectorPack.Pack(source, destination, elementConverter);
}
public static void PackSpan(
in ReadOnlySpan<double3> source,
Span<byte3> destination,
Func<double, byte> elementConverter
)
{
VectorPack.Pack(source, destination, elementConverter);
}
public static void UnpackSpan(
in ReadOnlySpan<sbyte3> source,
Span<byte3> destination,
Unpack.IntegerMixed mode = Numerics.Unpack.IntegerMixed.Cast
)
{
UnpackSpan(source, destination, PackUtils.SByte.ToByte(mode));
}
public static void PackSpan(
in ReadOnlySpan<short3> source,
Span<byte3> destination,
Pack.IntegerMixed mode = Numerics.Pack.IntegerMixed.Cast
)
{
PackSpan(source, destination, PackUtils.Short.ToByte(mode));
}
public static void PackSpan(
in ReadOnlySpan<ushort3> source,
Span<byte3> destination,
Pack.Integer mode = Numerics.Pack.Integer.Cast
)
{
PackSpan(source, destination, PackUtils.UShort.ToByte(mode));
}
public static void PackSpan(
in ReadOnlySpan<int3> source,
Span<byte3> destination,
Pack.IntegerMixed mode = Numerics.Pack.IntegerMixed.Cast
)
{
PackSpan(source, destination, PackUtils.Int.ToByte(mode));
}
public static void PackSpan(
in ReadOnlySpan<uint3> source,
Span<byte3> destination,
Pack.Integer mode = Numerics.Pack.Integer.Cast
)
{
PackSpan(source, destination, PackUtils.UInt.ToByte(mode));
}
public static void PackSpan(
in ReadOnlySpan<float3> source,
Span<byte3> destination,
Pack.Float mode = Numerics.Pack.Float.Truncate
)
{
PackSpan(source, destination, PackUtils.Float.ToByte(mode));
}
public static void PackSpan(
in ReadOnlySpan<double3> source,
Span<byte3> destination,
Pack.Float mode = Numerics.Pack.Float.Truncate
)
{
PackSpan(source, destination, PackUtils.Double.ToByte(mode));
}
}

View file

@ -0,0 +1,400 @@
// <auto-generated /> - edit Vector.swizzle.tt to modify
#nullable enable
namespace Brutal.Numerics;
public partial struct byte3
{
/// <summary>
/// Swizzle readonly getter/setter for the X and Y components of the vector.
/// </summary>
[XmlIgnore]
public byte2 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 byte2 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 byte2 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 byte2 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 byte2 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 byte2 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 byte3 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 byte3 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 byte3 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 byte3 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 byte3 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 byte3 ZYX
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
readonly get => new(Z, Y, X);
set
{
Z = value.X;
Y = value.Y;
X = value.Z;
}
}
}
public partial struct byte3
{
/// <summary>
/// The Red component of the vector (synonym for X).
/// </summary>
[XmlIgnore]
public byte R
{
readonly get => X;
set => X = value;
}
/// <summary>
/// The Green component of the vector (synonym for Y).
/// </summary>
[XmlIgnore]
public byte G
{
readonly get => Y;
set => Y = value;
}
/// <summary>
/// The Blue component of the vector (synonym for Z).
/// </summary>
[XmlIgnore]
public byte B
{
readonly get => Z;
set => Z = value;
}
/// <summary>
/// Swizzle readonly getter/setter for the Red and Green components of the vector.
/// </summary>
[XmlIgnore]
public byte2 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 byte2 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 byte2 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 byte2 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 byte2 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 byte2 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 byte3 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 byte3 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 byte3 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 byte3 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 byte3 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 byte3 BGR
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
readonly get => new(Z, Y, X);
set
{
B = value.R;
G = value.G;
R = value.B;
}
}
}