mirror of
https://github.com/ahwootech/BRUTAL.git
synced 2026-11-25 12:38:24 +01:00
121 lines
3.7 KiB
C#
121 lines
3.7 KiB
C#
// <auto-generated /> - edit Vector.tt to modify
|
|
#nullable enable
|
|
|
|
namespace Brutal.Numerics;
|
|
|
|
/// <summary>
|
|
/// Implements a 3D vector with bool components.
|
|
/// </summary>
|
|
public partial struct bool3 : IVector3<bool3, bool>
|
|
, IBooleanVector<bool3, bool>
|
|
{
|
|
/// <inheritdoc />
|
|
public static int ComponentSize => sizeof(bool);
|
|
|
|
/// <summary>Gets the number of components.</summary>
|
|
public static int ComponentCount => 3;
|
|
|
|
/// <inheritdoc cref="Vector3.X" />
|
|
[XmlAttribute]
|
|
public bool X;
|
|
|
|
/// <inheritdoc cref="Vector3.Y" />
|
|
[XmlAttribute]
|
|
public bool Y;
|
|
|
|
/// <inheritdoc cref="Vector3.Z" />
|
|
[XmlAttribute]
|
|
public bool Z;
|
|
|
|
bool IVector3<bool3, bool>.X { readonly get => X; set => X = value; }
|
|
|
|
bool IVector3<bool3, bool>.Y { readonly get => Y; set => Y = value; }
|
|
|
|
bool IVector3<bool3, bool>.Z { readonly get => Z; set => Z = value; }
|
|
|
|
/// <inheritdoc cref="Vector3(float, float, float)" />
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public bool3(bool x, bool y, bool z)
|
|
{
|
|
X = x;
|
|
Y = y;
|
|
Z = z;
|
|
}
|
|
|
|
/// <inheritdoc cref="Vector3(float)" />
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public bool3(bool xyz)
|
|
: this(xyz, xyz, xyz) { }
|
|
|
|
/// <inheritdoc cref="Vector3(Vector2, float)" />
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public bool3(bool2 xy, bool 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 bool3(ReadOnlySpan<bool> span)
|
|
{
|
|
if (span.Length < 3)
|
|
throw new ArgumentOutOfRangeException(nameof(span), "Length must be at least 3.");
|
|
|
|
this = Unsafe.ReadUnaligned<bool3>(ref Unsafe.As<bool, byte>(ref MemoryMarshal.GetReference(span)));
|
|
}
|
|
|
|
/// <inheritdoc cref="bool3(ReadOnlySpan{bool})" />
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
static bool3 IComponentTuple<bool3, bool>.Create(ReadOnlySpan<bool> span) => new(span);
|
|
|
|
/// <inheritdoc />
|
|
public static bool3 UnitX => new(true, false, false);
|
|
|
|
/// <inheritdoc />
|
|
public static bool3 UnitY => new(false, true, false);
|
|
|
|
/// <inheritdoc />
|
|
public static bool3 UnitZ => new(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)
|
|
{
|
|
x = X;
|
|
y = Y;
|
|
z = Z;
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public Span<bool> AsSpan()
|
|
{
|
|
return MemoryMarshal.CreateSpan(ref Unsafe.As<bool3, bool>(ref this), 3);
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public readonly ReadOnlySpan<bool> AsReadOnlySpan()
|
|
{
|
|
return MemoryMarshal.CreateReadOnlySpan(in Unsafe.As<bool3, bool>(ref Unsafe.AsRef(in this)), 3);
|
|
}
|
|
}
|