mirror of
https://github.com/ahwootech/BRUTAL.git
synced 2026-11-25 20:48:24 +01:00
105 lines
3.2 KiB
C#
105 lines
3.2 KiB
C#
// <auto-generated /> - edit Vector.tt to modify
|
|
#nullable enable
|
|
|
|
namespace Brutal.Numerics;
|
|
|
|
/// <summary>
|
|
/// Implements a 2D vector with bool components.
|
|
/// </summary>
|
|
public partial struct bool2 : IVector2<bool2, bool>
|
|
, IBooleanVector<bool2, bool>
|
|
{
|
|
/// <inheritdoc />
|
|
public static int ComponentSize => sizeof(bool);
|
|
|
|
/// <summary>Gets the number of components.</summary>
|
|
public static int ComponentCount => 2;
|
|
|
|
/// <inheritdoc cref="Vector2.X" />
|
|
[XmlAttribute]
|
|
public bool X;
|
|
|
|
/// <inheritdoc cref="Vector2.Y" />
|
|
[XmlAttribute]
|
|
public bool Y;
|
|
|
|
bool IVector2<bool2, bool>.X { readonly get => X; set => X = value; }
|
|
|
|
bool IVector2<bool2, bool>.Y { readonly get => Y; set => Y = value; }
|
|
|
|
/// <inheritdoc cref="Vector2(float, float)" />
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public bool2(bool x, bool y)
|
|
{
|
|
X = x;
|
|
Y = y;
|
|
}
|
|
|
|
/// <inheritdoc cref="Vector2(float)" />
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public bool2(bool xy)
|
|
: this(xy, xy) { }
|
|
|
|
/// <summary>Creates a vector from the leading 2 elements of a span.</summary>
|
|
/// <param name="span">The elements to read; must contain at least 2, and any beyond that are ignored.</param>
|
|
/// <exception cref="ArgumentOutOfRangeException"><paramref name="span" /> holds fewer than 2 elements.</exception>
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public bool2(ReadOnlySpan<bool> span)
|
|
{
|
|
if (span.Length < 2)
|
|
throw new ArgumentOutOfRangeException(nameof(span), "Length must be at least 2.");
|
|
|
|
this = Unsafe.ReadUnaligned<bool2>(ref Unsafe.As<bool, byte>(ref MemoryMarshal.GetReference(span)));
|
|
}
|
|
|
|
/// <inheritdoc cref="bool2(ReadOnlySpan{bool})" />
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
static bool2 IComponentTuple<bool2, bool>.Create(ReadOnlySpan<bool> span) => new(span);
|
|
|
|
/// <inheritdoc />
|
|
public static bool2 UnitX => new(true, false);
|
|
|
|
/// <inheritdoc />
|
|
public static bool2 UnitY => new(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)
|
|
{
|
|
x = X;
|
|
y = Y;
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public Span<bool> AsSpan()
|
|
{
|
|
return MemoryMarshal.CreateSpan(ref Unsafe.As<bool2, bool>(ref this), 2);
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public readonly ReadOnlySpan<bool> AsReadOnlySpan()
|
|
{
|
|
return MemoryMarshal.CreateReadOnlySpan(in Unsafe.As<bool2, bool>(ref Unsafe.AsRef(in this)), 2);
|
|
}
|
|
}
|