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