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