brutal/Brutal.Numerics/Vector/ushort4/ushort4.gen.cs
Rian Drake b578433e37 first
2026-10-15 17:10:50 +13:00

147 lines
4.7 KiB
C#

// <auto-generated /> - edit Vector.tt to modify
#nullable enable
namespace Brutal.Numerics;
/// <summary>
/// Implements a 4D vector with ushort components.
/// </summary>
[DebuggerTypeProxy(typeof(VectorDebugView4<ushort4, ushort, float>))]
public partial struct ushort4 : IVector4<ushort4, ushort>
, IIntegerVector<ushort4, ushort, int, float>
{
/// <inheritdoc />
public static int ComponentSize => sizeof(ushort);
/// <summary>Gets the number of components.</summary>
public static int ComponentCount => 4;
/// <inheritdoc cref="Vector4.X" />
[XmlAttribute]
public ushort X;
/// <inheritdoc cref="Vector4.Y" />
[XmlAttribute]
public ushort Y;
/// <inheritdoc cref="Vector4.Z" />
[XmlAttribute]
public ushort Z;
/// <inheritdoc cref="Vector4.W" />
[XmlAttribute]
public ushort W;
ushort IVector4<ushort4, ushort>.X { readonly get => X; set => X = value; }
ushort IVector4<ushort4, ushort>.Y { readonly get => Y; set => Y = value; }
ushort IVector4<ushort4, ushort>.Z { readonly get => Z; set => Z = value; }
ushort IVector4<ushort4, ushort>.W { readonly get => W; set => W = value; }
/// <inheritdoc cref="Vector4(float, float, float, float)" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public ushort4(ushort x, ushort y, ushort z, ushort w)
{
X = x;
Y = y;
Z = z;
W = w;
}
/// <inheritdoc cref="Vector4(float)" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public ushort4(ushort xyzw)
: this(xyzw, xyzw, xyzw, xyzw) { }
/// <inheritdoc cref="Vector4(Vector3, float)" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public ushort4(ushort3 xyz, ushort w)
: this(xyz.X, xyz.Y, xyz.Z, w) { }
/// <summary>
/// Creates a new instance of <see cref="ushort4" /> from two <see cref="ushort2" /> instances.
/// </summary>
/// <param name="xy">The first two components.</param>
/// <param name="zw">The last two components.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public ushort4(ushort2 xy, ushort2 zw)
: this(xy.X, xy.Y, zw.X, zw.Y) { }
/// <inheritdoc cref="Vector4(Vector2, float, float)" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public ushort4(ushort2 xy, ushort z, ushort w)
: this(xy.X, xy.Y, z, w) { }
/// <summary>Creates a vector from the leading 4 elements of a span.</summary>
/// <param name="span">The elements to read; must contain at least 4, and any beyond that are ignored.</param>
/// <exception cref="ArgumentOutOfRangeException"><paramref name="span" /> holds fewer than 4 elements.</exception>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public ushort4(ReadOnlySpan<ushort> span)
{
if (span.Length < 4)
throw new ArgumentOutOfRangeException(nameof(span), "Length must be at least 4.");
this = Unsafe.ReadUnaligned<ushort4>(ref Unsafe.As<ushort, byte>(ref MemoryMarshal.GetReference(span)));
}
/// <inheritdoc cref="ushort4(ReadOnlySpan{ushort})" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static ushort4 IComponentTuple<ushort4, ushort>.Create(ReadOnlySpan<ushort> span) => new(span);
/// <inheritdoc />
public static ushort4 UnitX => new(1, 0, 0, 0);
/// <inheritdoc />
public static ushort4 UnitY => new(0, 1, 0, 0);
/// <inheritdoc />
public static ushort4 UnitZ => new(0, 0, 1, 0);
/// <inheritdoc />
public static ushort4 UnitW => new(0, 0, 0, 1);
/// <inheritdoc />
public ushort 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 ushort x, out ushort y, out ushort z, out ushort w)
{
x = X;
y = Y;
z = Z;
w = W;
}
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public Span<ushort> AsSpan()
{
return MemoryMarshal.CreateSpan(ref Unsafe.As<ushort4, ushort>(ref this), 4);
}
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public readonly ReadOnlySpan<ushort> AsReadOnlySpan()
{
return MemoryMarshal.CreateReadOnlySpan(in Unsafe.As<ushort4, ushort>(ref Unsafe.AsRef(in this)), 4);
}
}