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