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