diff --git a/matrix/src/lib.rs b/matrix/src/lib.rs index e5b5709..4eafa95 100644 --- a/matrix/src/lib.rs +++ b/matrix/src/lib.rs @@ -51,7 +51,14 @@ impl Matrix { self.matrix[0][0] * self.matrix[1][1] - self.matrix[0][1] * self.matrix[1][0] } - pub fn sub_matrix(&self, skip_row: usize, skip_col: usize) -> Matrix<{H - 1}, {W - 1}> + pub fn minor(&self, row: usize, col: usize) -> f32 where + [(); H - 1]: , + [(); W - 1]: , + { + self.sub_matrix(row, col).determinant() + } + + pub fn sub_matrix(&self, skip_row: usize, skip_col: usize) -> Matrix<{H - 1}, {W - 1}> { let mut idx_row: usize = 0; @@ -391,4 +398,18 @@ mod tests { assert_eq!(expected, start.sub_matrix(2, 1)); } + + #[test] + fn minor_3x3() { + let m = Matrix::from_array([ + [3.0, 5.0, 0.0], + [2.0, -1.0, -7.0], + [6.0, -1.0, 5.0], + ]); + + let s = m.sub_matrix(1, 0); + + assert_eq!(25.0, s.determinant()); + assert_eq!(25.0, m.minor(1, 0)); + } }