added determinant

This commit is contained in:
Jon Janzen
2021-03-31 15:19:48 -06:00
parent c78c1ed8f6
commit 588acf36a3

View File

@@ -38,7 +38,11 @@ impl<const COUNT: usize> Matrix<COUNT> {
[self.matrix[0][2], self.matrix[1][2], self.matrix[2][2], self.matrix[3][2], ],
[self.matrix[0][3], self.matrix[1][3], self.matrix[2][3], self.matrix[3][3], ],
];
self.matrix = tmp;
// self.matrix = tmp;
}
pub fn determinant(&self) -> f32 {
self.matrix[0][0] * self.matrix[1][1] - self.matrix[0][1] * self.matrix[1][0]
}
}
@@ -320,4 +324,14 @@ mod tests {
m.transpose();
assert_eq!(m, Matrix::<4>::identity());
}
#[test]
fn determinant_2x2() {
let m = Matrix::from_array([
[1.0, 5.0],
[-3.0, 2.0],
]);
assert_eq!(17.0, m.determinant());
}
}