mathf/
error.rs

1/// Error for mathf types
2#[derive(Debug, PartialEq)]
3pub enum Error {
4    /// Can't inverse a matrix which determinant is zero.
5    /// matrix.det() == 0
6    NonZeroDeterminantMatrix,
7    /// Can't inverse a 3x3 Singular Matrix.
8    /// *A square matrix is singular if and only if its determinant is zero.*
9    SingularMatrixNotInversible,
10}
11
12impl std::fmt::Display for Error {
13    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
14        match self {
15            Error::NonZeroDeterminantMatrix => {
16                write!(f, "Matrix determinant should be different from ZERO")
17            }
18            Error::SingularMatrixNotInversible => {
19                write!(f, "Matrix3x3 cannont be inverse because it is singular")
20            }
21        }
22    }
23}
24
25impl std::error::Error for Error {
26    fn description(&self) -> &str {
27        match self {
28            Error::NonZeroDeterminantMatrix => "Matrix determinant should be different from ZERO",
29            Error::SingularMatrixNotInversible => {
30                "Matrix3x3 cannont be inverse because it is singular"
31            }
32        }
33    }
34
35    fn cause(&self) -> Option<&dyn std::error::Error> {
36        Some(self)
37    }
38}