// - edit Vector.tt to modify
#nullable enable
namespace Brutal.Numerics;
///
/// Implements a quaternion with double components.
///
[DebuggerTypeProxy(typeof(QuaternionDebugView))]
public partial struct doubleQuat : IQuaternion
, IMultiplyOperators
, IMultiplyOperators
, IMultiplyOperators
, IQuaternionFactories
{
///
public static int ComponentSize => sizeof(double);
/// Gets the number of components.
public static int ComponentCount => 4;
///
[XmlAttribute]
public double X;
///
[XmlAttribute]
public double Y;
///
[XmlAttribute]
public double Z;
///
[XmlAttribute]
public double W;
///
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public doubleQuat(double x, double y, double z, double w)
{
X = x;
Y = y;
Z = z;
W = w;
}
///
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public doubleQuat(double3 vectorPart, double scalarPart)
{
X = vectorPart.X;
Y = vectorPart.Y;
Z = vectorPart.Z;
W = scalarPart;
}
/// Creates a quaternion from the leading 4 elements of a span.
/// The elements to read; must contain at least 4, and any beyond that are ignored.
/// holds fewer than 4 elements.
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public doubleQuat(ReadOnlySpan span)
{
if (span.Length < 4)
throw new ArgumentOutOfRangeException(nameof(span), "Length must be at least 4.");
this = Unsafe.ReadUnaligned(ref Unsafe.As(ref MemoryMarshal.GetReference(span)));
}
///
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static doubleQuat IComponentTuple.Create(ReadOnlySpan span) => new(span);
///
public double 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 double x, out double y, out double z, out double w)
{
x = X;
y = Y;
z = Z;
w = W;
}
///
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public Span AsSpan()
{
return MemoryMarshal.CreateSpan(ref Unsafe.As(ref this), 4);
}
///
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public readonly ReadOnlySpan AsReadOnlySpan()
{
return MemoryMarshal.CreateReadOnlySpan(in Unsafe.As(ref Unsafe.AsRef(in this)), 4);
}
}