Unmark Mat4 inverse method as unsafe
This commit is contained in:
parent
e39f02ccf7
commit
c8f3f1919a
1 changed files with 22 additions and 15 deletions
35
src/mat.rs
35
src/mat.rs
|
@ -1461,7 +1461,7 @@ pub impl<T:Copy Float Sign> Mat4<T>: Matrix<T, Vec4<T>> {
|
||||||
self[0][0] + self[1][1] + self[2][2] + self[3][3]
|
self[0][0] + self[1][1] + self[2][2] + self[3][3]
|
||||||
}
|
}
|
||||||
|
|
||||||
pure fn inverse(&self) -> Option<Mat4<T>> unsafe {
|
pure fn inverse(&self) -> Option<Mat4<T>> {
|
||||||
let d = self.determinant();
|
let d = self.determinant();
|
||||||
// let _0 = Number::from(0); // FIXME: Triggers ICE
|
// let _0 = Number::from(0); // FIXME: Triggers ICE
|
||||||
let _0 = cast(0);
|
let _0 = cast(0);
|
||||||
|
@ -1486,21 +1486,28 @@ pub impl<T:Copy Float Sign> Mat4<T>: Matrix<T, Vec4<T>> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Swap columns i1 and j in A and I to
|
// We need to use an unsafe block in order to use these inpure
|
||||||
// put pivot on diagonal
|
// functions. This *should* be ok because A and I are never
|
||||||
A.swap_cols(i1, j);
|
// exposed to the outside world.
|
||||||
I.swap_cols(i1, j);
|
unsafe {
|
||||||
|
// Swap columns i1 and j in A and I to
|
||||||
|
// put pivot on diagonal
|
||||||
|
A.swap_cols(i1, j);
|
||||||
|
I.swap_cols(i1, j);
|
||||||
|
|
||||||
// Scale col j to have a unit diagonal
|
// Scale col j to have a unit diagonal
|
||||||
I.col_mut(j).div_self_t(&A[j][j]);
|
I.col_mut(j).div_self_t(&A[j][j]);
|
||||||
A.col_mut(j).div_self_t(&A[j][j]);
|
A.col_mut(j).div_self_t(&A[j][j]);
|
||||||
|
|
||||||
// Eliminate off-diagonal elems in col j of A,
|
// Eliminate off-diagonal elems in col j of A,
|
||||||
// doing identical ops to I
|
// doing identical ops to I
|
||||||
for uint::range(0, 4) |i| {
|
for uint::range(0, 4) |i| {
|
||||||
if i != j {
|
if i != j {
|
||||||
I.col_mut(i).sub_self_v(&I[j].mul_t(A[i][j]));
|
unsafe {
|
||||||
A.col_mut(i).sub_self_v(&A[j].mul_t(A[i][j]));
|
I.col_mut(i).sub_self_v(&I[j].mul_t(A[i][j]));
|
||||||
|
A.col_mut(i).sub_self_v(&A[j].mul_t(A[i][j]));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue