// - edit Matrix.tt to modify
#nullable enable
namespace Brutal.Numerics;
///
/// Implements a 3x2 matrix with float components.
///
[DebuggerTypeProxy(typeof(DebugView))]
public partial struct float3x2 : IMatrix
, IFloatingMatrix3x2
{
internal class DebugView(float3x2 m)
{
public float2 X => m.X;
public float2 Y => m.Y;
public float2 Z => m.Z;
}
/// The first row of the matrix.
[XmlIgnore]
public float2 X;
/// The second row of the matrix.
[XmlIgnore]
public float2 Y;
/// The third row of the matrix.
[XmlIgnore]
public float2 Z;
///
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public float3x2(
float m11,
float m12,
float m21,
float m22,
float m31,
float m32
)
{
X = new float2(m11, m12);
Y = new float2(m21, m22);
Z = new float2(m31, m32);
}
/// Creates a matrix from the leading 6 elements of a span, row by row.
/// The elements to read; must contain at least 6, and any beyond that are ignored.
/// holds fewer than 6 elements.
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public float3x2(ReadOnlySpan span)
{
if (span.Length < 6)
throw new ArgumentOutOfRangeException(nameof(span), "Length must be at least 6.");
this = Unsafe.ReadUnaligned(ref Unsafe.As(ref MemoryMarshal.GetReference(span)));
}
static float3x2 IMatrix.Create(ReadOnlySpan span) => new(span);
///
public static float3x2 Identity
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get
{
float3x2 result;
result.X = float2.UnitX;
result.Y = float2.UnitY;
result.Z = float2.Zero;
return result;
}
}
///
public static int ComponentSize => sizeof(float);
///
public static int RowCount => 3;
///
public static int ColumnCount => 2;
///
public readonly bool IsIdentity
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get => X == float2.UnitX && Y == float2.UnitY && Z == float2.Zero;
}
}