mirror of
https://github.com/ahwootech/BRUTAL.git
synced 2026-11-25 20:48:24 +01:00
106 lines
3.3 KiB
C#
106 lines
3.3 KiB
C#
// <auto-generated /> - edit Vector.tt to modify
|
|
#nullable enable
|
|
|
|
namespace Brutal.Numerics;
|
|
|
|
/// <summary>
|
|
/// Implements a 2D vector with uint components.
|
|
/// </summary>
|
|
[DebuggerTypeProxy(typeof(VectorDebugView2<uint2, uint, float>))]
|
|
public partial struct uint2 : IVector2<uint2, uint>
|
|
, IIntegerVector<uint2, uint, uint, float>
|
|
{
|
|
/// <inheritdoc />
|
|
public static int ComponentSize => sizeof(uint);
|
|
|
|
/// <summary>Gets the number of components.</summary>
|
|
public static int ComponentCount => 2;
|
|
|
|
/// <inheritdoc cref="Vector2.X" />
|
|
[XmlAttribute]
|
|
public uint X;
|
|
|
|
/// <inheritdoc cref="Vector2.Y" />
|
|
[XmlAttribute]
|
|
public uint Y;
|
|
|
|
uint IVector2<uint2, uint>.X { readonly get => X; set => X = value; }
|
|
|
|
uint IVector2<uint2, uint>.Y { readonly get => Y; set => Y = value; }
|
|
|
|
/// <inheritdoc cref="Vector2(float, float)" />
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public uint2(uint x, uint y)
|
|
{
|
|
X = x;
|
|
Y = y;
|
|
}
|
|
|
|
/// <inheritdoc cref="Vector2(float)" />
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public uint2(uint 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 uint2(ReadOnlySpan<uint> span)
|
|
{
|
|
if (span.Length < 2)
|
|
throw new ArgumentOutOfRangeException(nameof(span), "Length must be at least 2.");
|
|
|
|
this = Unsafe.ReadUnaligned<uint2>(ref Unsafe.As<uint, byte>(ref MemoryMarshal.GetReference(span)));
|
|
}
|
|
|
|
/// <inheritdoc cref="uint2(ReadOnlySpan{uint})" />
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
static uint2 IComponentTuple<uint2, uint>.Create(ReadOnlySpan<uint> span) => new(span);
|
|
|
|
/// <inheritdoc />
|
|
public static uint2 UnitX => new(1, 0);
|
|
|
|
/// <inheritdoc />
|
|
public static uint2 UnitY => new(0, 1);
|
|
|
|
/// <inheritdoc />
|
|
public uint 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 uint x, out uint y)
|
|
{
|
|
x = X;
|
|
y = Y;
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public Span<uint> AsSpan()
|
|
{
|
|
return MemoryMarshal.CreateSpan(ref Unsafe.As<uint2, uint>(ref this), 2);
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public readonly ReadOnlySpan<uint> AsReadOnlySpan()
|
|
{
|
|
return MemoryMarshal.CreateReadOnlySpan(in Unsafe.As<uint2, uint>(ref Unsafe.AsRef(in this)), 2);
|
|
}
|
|
}
|