pub mod matrix2x2;
pub mod matrix3x3;
pub mod matrix4x4;
use crate::vector::{Vector, VectorError};
pub enum MatrixError {
ZeroDeterminantError,
NonSquareMatrixError,
}
impl std::fmt::Debug for MatrixError {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
write!(f, "{:?}", self)
}
}
pub trait Matrix {
type Data;
fn new() -> Self;
fn from(value: Self::Data) -> Self;
fn from_slice(values: &[Self::Data]) -> Self;
fn scale(&self, scale: Self::Data) -> Self;
fn determinant(&self) -> Result<Self::Data, MatrixError>;
fn transpose(&self) -> Self;
fn cofactor(&self) -> Result<Self, MatrixError>
where
Self: Sized;
fn adjugate(&self) -> Result<Self, MatrixError>
where
Self: Sized;
fn inverse(&self) -> Result<Self, MatrixError>
where
Self: Sized;
}
pub trait TransformVector<T: Vector> {
fn transform_vector(&self, _other: T) -> Result<T, VectorError> {
Err(crate::vector::VectorError::NonExistingTransformError)
}
}