mirror of
https://github.com/ahwootech/BRUTAL.git
synced 2026-11-26 13:08: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 ulong components.
|
|
/// </summary>
|
|
[DebuggerTypeProxy(typeof(VectorDebugView3<ulong3, ulong, double>))]
|
|
public partial struct ulong3 : IVector3<ulong3, ulong>
|
|
, IIntegerVector<ulong3, ulong, ulong, double>
|
|
, ICrossProduct<ulong3>
|
|
{
|
|
/// <inheritdoc />
|
|
public static int ComponentSize => sizeof(ulong);
|
|
|
|
/// <summary>Gets the number of components.</summary>
|
|
public static int ComponentCount => 3;
|
|
|
|
/// <inheritdoc cref="Vector3.X" />
|
|
[XmlAttribute]
|
|
public ulong X;
|
|
|
|
/// <inheritdoc cref="Vector3.Y" />
|
|
[XmlAttribute]
|
|
public ulong Y;
|
|
|
|
/// <inheritdoc cref="Vector3.Z" />
|
|
[XmlAttribute]
|
|
public ulong Z;
|
|
|
|
ulong IVector3<ulong3, ulong>.X { readonly get => X; set => X = value; }
|
|
|
|
ulong IVector3<ulong3, ulong>.Y { readonly get => Y; set => Y = value; }
|
|
|
|
ulong IVector3<ulong3, ulong>.Z { readonly get => Z; set => Z = value; }
|
|
|
|
/// <inheritdoc cref="Vector3(float, float, float)" />
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public ulong3(ulong x, ulong y, ulong z)
|
|
{
|
|
X = x;
|
|
Y = y;
|
|
Z = z;
|
|
}
|
|
|
|
/// <inheritdoc cref="Vector3(float)" />
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public ulong3(ulong xyz)
|
|
: this(xyz, xyz, xyz) { }
|
|
|
|
/// <inheritdoc cref="Vector3(Vector2, float)" />
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public ulong3(ulong2 xy, ulong 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 ulong3(ReadOnlySpan<ulong> span)
|
|
{
|
|
if (span.Length < 3)
|
|
throw new ArgumentOutOfRangeException(nameof(span), "Length must be at least 3.");
|
|
|
|
this = Unsafe.ReadUnaligned<ulong3>(ref Unsafe.As<ulong, byte>(ref MemoryMarshal.GetReference(span)));
|
|
}
|
|
|
|
/// <inheritdoc cref="ulong3(ReadOnlySpan{ulong})" />
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
static ulong3 IComponentTuple<ulong3, ulong>.Create(ReadOnlySpan<ulong> span) => new(span);
|
|
|
|
/// <inheritdoc />
|
|
public static ulong3 UnitX => new(1, 0, 0);
|
|
|
|
/// <inheritdoc />
|
|
public static ulong3 UnitY => new(0, 1, 0);
|
|
|
|
/// <inheritdoc />
|
|
public static ulong3 UnitZ => new(0, 0, 1);
|
|
|
|
/// <inheritdoc />
|
|
public ulong 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 ulong x, out ulong y, out ulong z)
|
|
{
|
|
x = X;
|
|
y = Y;
|
|
z = Z;
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public Span<ulong> AsSpan()
|
|
{
|
|
return MemoryMarshal.CreateSpan(ref Unsafe.As<ulong3, ulong>(ref this), 3);
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public readonly ReadOnlySpan<ulong> AsReadOnlySpan()
|
|
{
|
|
return MemoryMarshal.CreateReadOnlySpan(in Unsafe.As<ulong3, ulong>(ref Unsafe.AsRef(in this)), 3);
|
|
}
|
|
}
|