mirror of
https://github.com/ahwootech/BRUTAL.git
synced 2026-11-25 12:38:24 +01:00
148 lines
4.8 KiB
C#
148 lines
4.8 KiB
C#
// <auto-generated /> - edit Vector.tt to modify
|
|
#nullable enable
|
|
|
|
namespace Brutal.Numerics;
|
|
|
|
/// <summary>
|
|
/// Implements a 4D vector with double components.
|
|
/// </summary>
|
|
[DebuggerTypeProxy(typeof(VectorDebugView4<double4, double, double>))]
|
|
public partial struct double4 : IVector4<double4, double>
|
|
, IFloatingVector<double4, double>
|
|
, IFloatingVector4<double4, double, double2, double3, doubleQuat, double4x4>
|
|
{
|
|
/// <inheritdoc />
|
|
public static int ComponentSize => sizeof(double);
|
|
|
|
/// <summary>Gets the number of components.</summary>
|
|
public static int ComponentCount => 4;
|
|
|
|
/// <inheritdoc cref="Vector4.X" />
|
|
[XmlAttribute]
|
|
public double X;
|
|
|
|
/// <inheritdoc cref="Vector4.Y" />
|
|
[XmlAttribute]
|
|
public double Y;
|
|
|
|
/// <inheritdoc cref="Vector4.Z" />
|
|
[XmlAttribute]
|
|
public double Z;
|
|
|
|
/// <inheritdoc cref="Vector4.W" />
|
|
[XmlAttribute]
|
|
public double W;
|
|
|
|
double IVector4<double4, double>.X { readonly get => X; set => X = value; }
|
|
|
|
double IVector4<double4, double>.Y { readonly get => Y; set => Y = value; }
|
|
|
|
double IVector4<double4, double>.Z { readonly get => Z; set => Z = value; }
|
|
|
|
double IVector4<double4, double>.W { readonly get => W; set => W = value; }
|
|
|
|
/// <inheritdoc cref="Vector4(float, float, float, float)" />
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public double4(double x, double y, double z, double w)
|
|
{
|
|
X = x;
|
|
Y = y;
|
|
Z = z;
|
|
W = w;
|
|
}
|
|
|
|
/// <inheritdoc cref="Vector4(float)" />
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public double4(double xyzw)
|
|
: this(xyzw, xyzw, xyzw, xyzw) { }
|
|
|
|
/// <inheritdoc cref="Vector4(Vector3, float)" />
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public double4(double3 xyz, double w)
|
|
: this(xyz.X, xyz.Y, xyz.Z, w) { }
|
|
|
|
/// <summary>
|
|
/// Creates a new instance of <see cref="double4" /> from two <see cref="double2" /> instances.
|
|
/// </summary>
|
|
/// <param name="xy">The first two components.</param>
|
|
/// <param name="zw">The last two components.</param>
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public double4(double2 xy, double2 zw)
|
|
: this(xy.X, xy.Y, zw.X, zw.Y) { }
|
|
|
|
/// <inheritdoc cref="Vector4(Vector2, float, float)" />
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public double4(double2 xy, double z, double 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 double4(ReadOnlySpan<double> span)
|
|
{
|
|
if (span.Length < 4)
|
|
throw new ArgumentOutOfRangeException(nameof(span), "Length must be at least 4.");
|
|
|
|
this = Unsafe.ReadUnaligned<double4>(ref Unsafe.As<double, byte>(ref MemoryMarshal.GetReference(span)));
|
|
}
|
|
|
|
/// <inheritdoc cref="double4(ReadOnlySpan{double})" />
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
static double4 IComponentTuple<double4, double>.Create(ReadOnlySpan<double> span) => new(span);
|
|
|
|
/// <inheritdoc />
|
|
public static double4 UnitX => new(1, 0, 0, 0);
|
|
|
|
/// <inheritdoc />
|
|
public static double4 UnitY => new(0, 1, 0, 0);
|
|
|
|
/// <inheritdoc />
|
|
public static double4 UnitZ => new(0, 0, 1, 0);
|
|
|
|
/// <inheritdoc />
|
|
public static double4 UnitW => new(0, 0, 0, 1);
|
|
|
|
/// <inheritdoc />
|
|
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;
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public Span<double> AsSpan()
|
|
{
|
|
return MemoryMarshal.CreateSpan(ref Unsafe.As<double4, double>(ref this), 4);
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public readonly ReadOnlySpan<double> AsReadOnlySpan()
|
|
{
|
|
return MemoryMarshal.CreateReadOnlySpan(in Unsafe.As<double4, double>(ref Unsafe.AsRef(in this)), 4);
|
|
}
|
|
}
|