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

View file

@ -0,0 +1,28 @@
// <auto-generated /> - edit Vector.copy.tt to modify
#nullable enable
namespace Brutal.Numerics;
public partial struct bool4
{
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public readonly void CopyTo(Span<bool> destination)
{
if (destination.Length < ComponentCount)
throw new ArgumentException("Length must be at least 4.", nameof(destination));
Unsafe.WriteUnaligned(ref Unsafe.As<bool, byte>(ref MemoryMarshal.GetReference(destination)), this);
}
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public readonly bool TryCopyTo(Span<bool> destination)
{
if (destination.Length < ComponentCount)
return false;
Unsafe.WriteUnaligned(ref Unsafe.As<bool, 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 bool4
{
/// <inheritdoc />
public readonly override int GetHashCode()
{
return HashCode.Combine(X, Y, Z, W);
}
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public readonly bool Equals(bool4 other)
{
return X == other.X && Y == other.Y && Z == other.Z && W == other.W;
}
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public readonly override bool Equals([NotNullWhen(true)] object? obj)
{
return obj is bool4 other && Equals(other);
}
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool operator ==(bool4 a, bool4 b)
{
return a.Equals(b);
}
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool operator !=(bool4 a, bool4 b)
{
return !(a == b);
}
}

View file

@ -0,0 +1,38 @@
// <auto-generated /> - edit Vector.format.tt to modify
#nullable enable
namespace Brutal.Numerics;
public partial struct bool4 : ISpanFormattable, IUtf8SpanFormattable
{
/// <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()}{separator} {Y.ToString()}{separator} {Z.ToString()}{separator} {W.ToString()}>";
}
/// <inheritdoc />
public readonly bool TryFormat(Span<char> destination, out int charsWritten, ReadOnlySpan<char> format, IFormatProvider? provider)
{
return StringHelpers.TryFormat<bool4, bool>(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<bool4, bool>(this, destination, out bytesWritten, format, provider);
}
}

View file

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

View file

@ -0,0 +1,13 @@
// <auto-generated /> - edit Vector.math.tt to modify
#nullable enable
namespace Brutal.Numerics;
public partial struct bool4
{
/// <inheritdoc />
public readonly bool Any => X || Y || Z || W;
/// <inheritdoc />
public readonly bool All => X && Y && Z && W;
}

View file

@ -0,0 +1,53 @@
// <auto-generated /> - edit Vector.numerics.tt to modify
#nullable enable
namespace Brutal.Numerics;
// INumberBase
public partial struct bool4
{
/// <inheritdoc />
public static bool4 Zero => new(false);
/// <inheritdoc />
public static bool4 One => new(true);
}
// IBitwiseOperators
public partial struct bool4 : IBitwiseOperators<bool4, bool4, bool4>
{
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool4 operator |(bool4 a, bool4 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 &(bool4 a, bool4 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 ^(bool4 a, bool4 b)
{
return new bool4(a.X ^ b.X, a.Y ^ b.Y, a.Z ^ b.Z, a.W ^ b.W);
}
/// <inheritdoc cref="IBitwiseOperators{TSelf, TOther, TResult}.op_OnesComplement" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool4 operator !(bool4 value)
{
return new bool4(!value.X, !value.Y, !value.Z, !value.W);
}
// bool has no ~; the interface's complement is componentwise logical not
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static bool4 IBitwiseOperators<bool4, bool4, bool4>.operator ~(bool4 value)
{
return !value;
}
}

File diff suppressed because it is too large Load diff