diff --git a/src/mat.rs b/src/mat.rs index 15e14f0..f0d3757 100644 --- a/src/mat.rs +++ b/src/mat.rs @@ -1468,7 +1468,7 @@ pub impl Mat4: Matrix> { if d.fuzzy_eq(&_0) { None } else { - + // Gauss Jordan Elimination with partial pivoting // So take this matrix, A, augmented with the identity // and essentially reduce [A|I] @@ -1476,7 +1476,7 @@ pub impl Mat4: Matrix> { let mut A = *self; // let mut I: Mat4 = Matrix::identity(); // FIXME: there's something wrong with static functions here! let mut I = Mat4::identity(); - + for uint::range(0, 4) |j| { // Find largest element in col j let mut i1 = j; @@ -1486,27 +1486,22 @@ pub impl Mat4: Matrix> { } } - // We need to use an unsafe block in order to use these inpure - // functions. This *should* be ok because A and I are never - // exposed to the outside world. 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 I.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, // doing identical ops to I for uint::range(0, 4) |i| { if i != j { - unsafe { - 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])); - } + 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])); } } }