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

107 lines
3.4 KiB
C#

// <auto-generated /> - edit Vector.tt to modify
#nullable enable
namespace Brutal.Numerics;
/// <summary>
/// Implements a 2D vector with double components.
/// </summary>
[DebuggerTypeProxy(typeof(VectorDebugView2<double2, double, double>))]
public partial struct double2 : IVector2<double2, double>
, IFloatingVector<double2, double>
, IFloatingVector2<double2, double, doubleQuat, double3x2, double4x4>
{
/// <inheritdoc />
public static int ComponentSize => sizeof(double);
/// <summary>Gets the number of components.</summary>
public static int ComponentCount => 2;
/// <inheritdoc cref="Vector2.X" />
[XmlAttribute]
public double X;
/// <inheritdoc cref="Vector2.Y" />
[XmlAttribute]
public double Y;
double IVector2<double2, double>.X { readonly get => X; set => X = value; }
double IVector2<double2, double>.Y { readonly get => Y; set => Y = value; }
/// <inheritdoc cref="Vector2(float, float)" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public double2(double x, double y)
{
X = x;
Y = y;
}
/// <inheritdoc cref="Vector2(float)" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public double2(double xy)
: this(xy, xy) { }
/// <summary>Creates a vector from the leading 2 elements of a span.</summary>
/// <param name="span">The elements to read; must contain at least 2, and any beyond that are ignored.</param>
/// <exception cref="ArgumentOutOfRangeException"><paramref name="span" /> holds fewer than 2 elements.</exception>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public double2(ReadOnlySpan<double> span)
{
if (span.Length < 2)
throw new ArgumentOutOfRangeException(nameof(span), "Length must be at least 2.");
this = Unsafe.ReadUnaligned<double2>(ref Unsafe.As<double, byte>(ref MemoryMarshal.GetReference(span)));
}
/// <inheritdoc cref="double2(ReadOnlySpan{double})" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static double2 IComponentTuple<double2, double>.Create(ReadOnlySpan<double> span) => new(span);
/// <inheritdoc />
public static double2 UnitX => new(1, 0);
/// <inheritdoc />
public static double2 UnitY => new(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)
{
x = X;
y = Y;
}
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public Span<double> AsSpan()
{
return MemoryMarshal.CreateSpan(ref Unsafe.As<double2, double>(ref this), 2);
}
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public readonly ReadOnlySpan<double> AsReadOnlySpan()
{
return MemoryMarshal.CreateReadOnlySpan(in Unsafe.As<double2, double>(ref Unsafe.AsRef(in this)), 2);
}
}