Fix determinant/inver for 2x2.

This commit is contained in:
Luqman Aden 2012-11-07 21:52:16 -05:00
parent a76378e83e
commit 520ba818e6
2 changed files with 7 additions and 6 deletions

View file

@ -201,8 +201,8 @@ pub impl<T:Copy Num NumCast FuzzyEq> Mat2<T>: SquareMatrix<T> {
if d.fuzzy_eq(&_0) {
None
} else {
Some(Mat2::new(self[1][1]/d, -self[1][0]/d,
-self[0][1]/d, self[0][0]/d))
Some(Mat2::new(self[1][1]/d, -self[0][1]/d,
-self[1][0]/d, self[0][0]/d))
}
}

View file

@ -30,7 +30,7 @@ fn test_Mat2() {
assert a.col(0) == Vec2::new(1f, 3f);
assert a.col(1) == Vec2::new(2f, 4f);
assert a.det() == 4f;
assert a.det() == -2f;
assert a.neg() == Mat2::new(-1f, -3f,
-2f, -4f);
@ -50,11 +50,12 @@ fn test_Mat2() {
assert a.transpose() == Mat2::new(1f, 2f,
3f, 4f);
assert option::unwrap(a.invert()) == Mat2::new(1f, -0.5f,
-0.75f, 0.25f);
io::println(#fmt("%?", option::unwrap(a.invert())));
assert option::unwrap(a.invert()) == Mat2::new(-2f, 1.5f,
1f, -0.5f);
assert Mat2::new(0f, 2f,
3f, 5f).invert().is_none();
0f, 5f).invert().is_none();
// exact_eq
// fuzzy_eq