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