added determinant
This commit is contained in:
@@ -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][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[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();
|
m.transpose();
|
||||||
assert_eq!(m, Matrix::<4>::identity());
|
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());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user