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 short components.
|
|
/// </summary>
|
|
[DebuggerTypeProxy(typeof(VectorDebugView2<short2, short, float>))]
|
|
public partial struct short2 : IVector2<short2, short>
|
|
, ISignedIntegerVector<short2, short, int, float>
|
|
{
|
|
/// <inheritdoc />
|
|
public static int ComponentSize => sizeof(short);
|
|
|
|
/// <summary>Gets the number of components.</summary>
|
|
public static int ComponentCount => 2;
|
|
|
|
/// <inheritdoc cref="Vector2.X" />
|
|
[XmlAttribute]
|
|
public short X;
|
|
|
|
/// <inheritdoc cref="Vector2.Y" />
|
|
[XmlAttribute]
|
|
public short Y;
|
|
|
|
short IVector2<short2, short>.X { readonly get => X; set => X = value; }
|
|
|
|
short IVector2<short2, short>.Y { readonly get => Y; set => Y = value; }
|
|
|
|
/// <inheritdoc cref="Vector2(float, float)" />
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public short2(short x, short y)
|
|
{
|
|
X = x;
|
|
Y = y;
|
|
}
|
|
|
|
/// <inheritdoc cref="Vector2(float)" />
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public short2(short 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 short2(ReadOnlySpan<short> span)
|
|
{
|
|
if (span.Length < 2)
|
|
throw new ArgumentOutOfRangeException(nameof(span), "Length must be at least 2.");
|
|
|
|
this = Unsafe.ReadUnaligned<short2>(ref Unsafe.As<short, byte>(ref MemoryMarshal.GetReference(span)));
|
|
}
|
|
|
|
/// <inheritdoc cref="short2(ReadOnlySpan{short})" />
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
static short2 IComponentTuple<short2, short>.Create(ReadOnlySpan<short> span) => new(span);
|
|
|
|
/// <inheritdoc />
|
|
public static short2 UnitX => new(1, 0);
|
|
|
|
/// <inheritdoc />
|
|
public static short2 UnitY => new(0, 1);
|
|
|
|
/// <inheritdoc />
|
|
public short 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 short x, out short y)
|
|
{
|
|
x = X;
|
|
y = Y;
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public Span<short> AsSpan()
|
|
{
|
|
return MemoryMarshal.CreateSpan(ref Unsafe.As<short2, short>(ref this), 2);
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public readonly ReadOnlySpan<short> AsReadOnlySpan()
|
|
{
|
|
return MemoryMarshal.CreateReadOnlySpan(in Unsafe.As<short2, short>(ref Unsafe.AsRef(in this)), 2);
|
|
}
|
|
}
|