brutal/Brutal.Numerics/Vector/bool4/bool4.gen.cs
Rian Drake b578433e37 first
2026-10-15 17:10:50 +13:00

146 lines
4.6 KiB
C#

// <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);
}
}