namespace Brutal.Numerics;
/// Defines a generic matrix type.
/// The type that implements the interface.
/// The component type.
public interface IMatrix : IEquatable, IFormattable
where TSelf : IMatrix
{
/// Gets the stride of one component in bytes.
static abstract int ComponentSize { get; }
/// Gets the number of rows.
static abstract int RowCount { get; }
/// Gets the number of columns.
static abstract int ColumnCount { get; }
/// Gets or sets the element at the specified row and column.
/// The row of the element to get or set.
/// The column of the element to get or set.
/// The element at , .
///
/// was less than zero or greater than the number of
/// rows.
///
///
/// was less than zero or greater than the number
/// of columns.
///
T this[int row, int column] { get; set; }
/// Gets the identity matrix.
static abstract TSelf Identity { get; }
/// Returns true if this matrix is the identity matrix.
bool IsIdentity { get; }
/// Construct a matrix of this type from a span
static abstract TSelf Create(ReadOnlySpan span);
/// Cast this value to a span
Span AsSpan();
/// A read-only view over the elements, safe in the readonly contexts where would view a defensive copy.
ReadOnlySpan AsReadOnlySpan();
}
/// Everything a 3x2 (2D affine) floating-point matrix can do.
/// Multiplying by a yields a .
public interface IFloatingMatrix3x2
: IMatrix,
IMultiplyOperators
where TSelf : IFloatingMatrix3x2
{
/// Static-method twin of the matrix * vector2 operator (expands to 3 components).
static abstract TVector3 Multiply(TSelf matrix, TVector2 vector);
///
TVector2 Translation { get; }
///
TComponent GetDeterminant();
///
static abstract bool Invert(TSelf matrix, out TSelf result);
///
static abstract TSelf CreateRotation(TComponent radians);
///
static abstract TSelf CreateSkew(TComponent radiansX, TComponent radiansY);
///
static abstract TSelf CreateSkew(TComponent radiansX, TComponent radiansY, TVector2 centerPoint);
}
/// Everything a 4x4 floating-point matrix can do.
/// The operators and factories are declared inline for the same CS0695 reason as the vector bundles.
/// CreateReflection/CreateShadow are absent: they take a plane, and planes have no interface yet.
public interface IFloatingMatrix4x4 : IMatrix
where TSelf : IFloatingMatrix4x4
{
///
TVector3 Translation { get; }
///
TComponent GetDeterminant();
///
static abstract TSelf operator +(TSelf left, TSelf right);
///
static abstract TSelf operator -(TSelf left, TSelf right);
///
static abstract TSelf operator -(TSelf value);
///
static abstract TSelf operator *(TSelf left, TSelf right);
///
static abstract TSelf operator *(TSelf left, TComponent right);
/// Multiplies a matrix by a column vector: each result component is the dot of a row with the vector.
/// The W-row translation is not applied; transform points with vector-times-matrix, which is the row-vector product.
static abstract TVector4 operator *(TSelf matrix, TVector4 vector);
///
static abstract TVector4 Multiply(TSelf matrix, TVector4 vector);
///
static abstract TSelf Lerp(TSelf a, TSelf b, TComponent amount);
///
static abstract TSelf Transpose(TSelf matrix);
///
static abstract TSelf Transform(TSelf value, TQuaternion rotation);
///
static abstract bool Invert(TSelf matrix, out TSelf result);
///
static abstract bool Decompose(
TSelf matrix,
out TVector3 scale,
out TQuaternion rotation,
out TVector3 translation
);
///
static abstract TSelf CreateBillboard(
TVector3 objectPosition,
TVector3 cameraPosition,
TVector3 cameraUpVector,
TVector3 cameraForwardVector
);
///
static abstract TSelf CreateConstrainedBillboard(
TVector3 objectPosition,
TVector3 cameraPosition,
TVector3 rotateAxis,
TVector3 cameraForwardVector,
TVector3 objectForwardVector
);
///
static abstract TSelf CreateFromAxisAngle(TVector3 axis, TComponent angle);
///
static abstract TSelf CreateFromQuaternion(TQuaternion quaternion);
///
static abstract TSelf CreateFromYawPitchRoll(TComponent yaw, TComponent pitch, TComponent roll);
///
static abstract TSelf CreateLookAt(TVector3 cameraPosition, TVector3 cameraTarget, TVector3 cameraUpVector);
///
static abstract TSelf CreateLookAtLeftHanded(
TVector3 cameraPosition,
TVector3 cameraTarget,
TVector3 cameraUpVector
);
///
static abstract TSelf CreateLookTo(TVector3 cameraPosition, TVector3 cameraDirection, TVector3 cameraUpVector);
///
static abstract TSelf CreateLookToLeftHanded(
TVector3 cameraPosition,
TVector3 cameraDirection,
TVector3 cameraUpVector
);
///
static abstract TSelf CreateOrthographic(
TComponent width,
TComponent height,
TComponent zNearPlane,
TComponent zFarPlane
);
///
static abstract TSelf CreateOrthographicOffCenter(
TComponent left,
TComponent right,
TComponent bottom,
TComponent top,
TComponent zNearPlane,
TComponent zFarPlane
);
///
static abstract TSelf CreateOrthographicOffCenterLeftHanded(
TComponent left,
TComponent right,
TComponent bottom,
TComponent top,
TComponent zNearPlane,
TComponent zFarPlane
);
///
static abstract TSelf CreatePerspective(
TComponent width,
TComponent height,
TComponent nearPlaneDistance,
TComponent farPlaneDistance
);
///
static abstract TSelf CreatePerspectiveLeftHanded(
TComponent width,
TComponent height,
TComponent nearPlaneDistance,
TComponent farPlaneDistance
);
///
static abstract TSelf CreatePerspectiveFieldOfView(
TComponent fieldOfView,
TComponent aspectRatio,
TComponent nearPlaneDistance,
TComponent farPlaneDistance
);
///
static abstract TSelf CreatePerspectiveFieldOfViewLeftHanded(
TComponent fieldOfView,
TComponent aspectRatio,
TComponent nearPlaneDistance,
TComponent farPlaneDistance
);
///
static abstract TSelf CreatePerspectiveOffCenter(
TComponent left,
TComponent right,
TComponent bottom,
TComponent top,
TComponent nearPlaneDistance,
TComponent farPlaneDistance
);
///
static abstract TSelf CreatePerspectiveOffCenterLeftHanded(
TComponent left,
TComponent right,
TComponent bottom,
TComponent top,
TComponent nearPlaneDistance,
TComponent farPlaneDistance
);
///
static abstract TSelf CreateRotationX(TComponent radians);
///
static abstract TSelf CreateRotationX(TComponent radians, TVector3 centerPoint);
///
static abstract TSelf CreateRotationY(TComponent radians);
///
static abstract TSelf CreateRotationY(TComponent radians, TVector3 centerPoint);
///
static abstract TSelf CreateRotationZ(TComponent radians);
///
static abstract TSelf CreateRotationZ(TComponent radians, TVector3 centerPoint);
///
static abstract TSelf CreateScale(TComponent xScale, TComponent yScale, TComponent zScale);
///
static abstract TSelf CreateScale(TComponent xScale, TComponent yScale, TComponent zScale, TVector3 centerPoint);
///
static abstract TSelf CreateScale(TVector3 scales);
///
static abstract TSelf CreateScale(TComponent scale);
///
static abstract TSelf CreateScale(TComponent scale, TVector3 centerPoint);
///
static abstract TSelf CreateTranslation(TComponent xPosition, TComponent yPosition, TComponent zPosition);
///
static abstract TSelf CreateTranslation(TVector3 position);
///
static abstract TSelf CreateViewport(
TComponent x,
TComponent y,
TComponent width,
TComponent height,
TComponent minDepth,
TComponent maxDepth
);
///
static abstract TSelf CreateViewportLeftHanded(
TComponent x,
TComponent y,
TComponent width,
TComponent height,
TComponent minDepth,
TComponent maxDepth
);
///
static abstract TSelf CreateWorld(TVector3 position, TVector3 forward, TVector3 up);
}