mirror of
https://github.com/ahwootech/BRUTAL.git
synced 2026-11-25 20:48:24 +01:00
116 lines
3.6 KiB
C#
116 lines
3.6 KiB
C#
// <auto-generated /> - edit Vector.tt to modify
|
|
#nullable enable
|
|
|
|
namespace Brutal.Numerics;
|
|
|
|
/// <summary>
|
|
/// Implements a quaternion with float components.
|
|
/// </summary>
|
|
[DebuggerTypeProxy(typeof(QuaternionDebugView<floatQuat, float>))]
|
|
public partial struct floatQuat : IQuaternion<floatQuat, float>
|
|
, IMultiplyOperators<floatQuat, float2, float2>
|
|
, IMultiplyOperators<floatQuat, float3, float3>
|
|
, IMultiplyOperators<floatQuat, float4, float4>
|
|
, IQuaternionFactories<floatQuat, float, float3, float4x4>
|
|
{
|
|
/// <inheritdoc />
|
|
public static int ComponentSize => sizeof(float);
|
|
|
|
/// <summary>Gets the number of components.</summary>
|
|
public static int ComponentCount => 4;
|
|
|
|
/// <inheritdoc cref="Quaternion.X" />
|
|
[XmlAttribute]
|
|
public float X;
|
|
|
|
/// <inheritdoc cref="Quaternion.Y" />
|
|
[XmlAttribute]
|
|
public float Y;
|
|
|
|
/// <inheritdoc cref="Quaternion.Z" />
|
|
[XmlAttribute]
|
|
public float Z;
|
|
|
|
/// <inheritdoc cref="Quaternion.W" />
|
|
[XmlAttribute]
|
|
public float W;
|
|
|
|
/// <inheritdoc cref="Quaternion(float, float, float, float)" />
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public floatQuat(float x, float y, float z, float w)
|
|
{
|
|
X = x;
|
|
Y = y;
|
|
Z = z;
|
|
W = w;
|
|
}
|
|
|
|
/// <inheritdoc cref="Quaternion(Vector3, float)" />
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public floatQuat(float3 vectorPart, float scalarPart)
|
|
{
|
|
X = vectorPart.X;
|
|
Y = vectorPart.Y;
|
|
Z = vectorPart.Z;
|
|
W = scalarPart;
|
|
}
|
|
|
|
/// <summary>Creates a quaternion 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 floatQuat(ReadOnlySpan<float> span)
|
|
{
|
|
if (span.Length < 4)
|
|
throw new ArgumentOutOfRangeException(nameof(span), "Length must be at least 4.");
|
|
|
|
this = Unsafe.ReadUnaligned<floatQuat>(ref Unsafe.As<float, byte>(ref MemoryMarshal.GetReference(span)));
|
|
}
|
|
|
|
/// <inheritdoc cref="floatQuat(ReadOnlySpan{float})" />
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
static floatQuat IComponentTuple<floatQuat, float>.Create(ReadOnlySpan<float> span) => new(span);
|
|
|
|
/// <inheritdoc />
|
|
public float 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 float x, out float y, out float z, out float w)
|
|
{
|
|
x = X;
|
|
y = Y;
|
|
z = Z;
|
|
w = W;
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public Span<float> AsSpan()
|
|
{
|
|
return MemoryMarshal.CreateSpan(ref Unsafe.As<floatQuat, float>(ref this), 4);
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public readonly ReadOnlySpan<float> AsReadOnlySpan()
|
|
{
|
|
return MemoryMarshal.CreateReadOnlySpan(in Unsafe.As<floatQuat, float>(ref Unsafe.AsRef(in this)), 4);
|
|
}
|
|
}
|