Fixed warnings
This commit is contained in:
parent
2b7339e734
commit
c026f520e1
2 changed files with 17 additions and 21 deletions
|
@ -556,42 +556,42 @@ for Mat4<S>
|
||||||
fn invert(&self) -> Option<Mat4<S>> {
|
fn invert(&self) -> Option<Mat4<S>> {
|
||||||
if self.is_invertible() {
|
if self.is_invertible() {
|
||||||
// Gauss Jordan Elimination with partial pivoting
|
// Gauss Jordan Elimination with partial pivoting
|
||||||
// So take this matrix, A, augmented with the identity
|
// So take this matrix ('mat') augmented with the identity ('ident'),
|
||||||
// and essentially reduce [A|I]
|
// and essentially reduce [mat|ident]
|
||||||
|
|
||||||
let mut A = self.clone();
|
let mut mat = self.clone();
|
||||||
let mut I = Mat4::identity();
|
let mut ident = Mat4::identity();
|
||||||
|
|
||||||
for j in range(0u, 4u) {
|
for j in range(0u, 4u) {
|
||||||
// Find largest element in col j
|
// Find largest element in col j
|
||||||
let mut i1 = j;
|
let mut i1 = j;
|
||||||
for i in range(j + 1, 4) {
|
for i in range(j + 1, 4) {
|
||||||
if A.cr(j, i).abs() > A.cr(j, i1).abs() {
|
if mat.cr(j, i).abs() > mat.cr(j, i1).abs() {
|
||||||
i1 = i;
|
i1 = i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Swap columns i1 and j in A and I to
|
// Swap columns i1 and j in mat and ident to
|
||||||
// put pivot on diagonal
|
// put pivot on diagonal
|
||||||
A.swap_c(i1, j);
|
mat.swap_c(i1, j);
|
||||||
I.swap_c(i1, j);
|
ident.swap_c(i1, j);
|
||||||
|
|
||||||
// Scale col j to have a unit diagonal
|
// Scale col j to have a unit diagonal
|
||||||
*I.mut_c(j) = I.c(j).div_s(A.cr(j, j).clone());
|
*ident.mut_c(j) = ident.c(j).div_s(mat.cr(j, j).clone());
|
||||||
*A.mut_c(j) = A.c(j).div_s(A.cr(j, j).clone());
|
*mat.mut_c(j) = mat.c(j).div_s(mat.cr(j, j).clone());
|
||||||
|
|
||||||
// Eliminate off-diagonal elems in col j of A,
|
// Eliminate off-diagonal elems in col j of 'mat',
|
||||||
// doing identical ops to I
|
// doing identical ops to 'ident'
|
||||||
for i in range(0u, 4u) {
|
for i in range(0u, 4u) {
|
||||||
if i != j {
|
if i != j {
|
||||||
let ij_mul_aij = I.c(j).mul_s(A.cr(i, j).clone());
|
let ij_mul_aij = ident.c(j).mul_s(mat.cr(i, j).clone());
|
||||||
let aj_mul_aij = A.c(j).mul_s(A.cr(i, j).clone());
|
let aj_mul_aij = mat.c(j).mul_s(mat.cr(i, j).clone());
|
||||||
*I.mut_c(i) = I.c(i).sub_v(&ij_mul_aij);
|
*ident.mut_c(i) = ident.c(i).sub_v(&ij_mul_aij);
|
||||||
*A.mut_c(i) = A.c(i).sub_v(&aj_mul_aij);
|
*mat.mut_c(i) = mat.c(i).sub_v(&aj_mul_aij);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Some(I)
|
Some(ident)
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,12 +16,10 @@
|
||||||
use cgmath::matrix::*;
|
use cgmath::matrix::*;
|
||||||
use cgmath::vector::*;
|
use cgmath::vector::*;
|
||||||
use cgmath::approx::ApproxEq;
|
use cgmath::approx::ApproxEq;
|
||||||
type float = f64;
|
|
||||||
|
|
||||||
pub mod mat2 {
|
pub mod mat2 {
|
||||||
use cgmath::matrix::*;
|
use cgmath::matrix::*;
|
||||||
use cgmath::vector::*;
|
use cgmath::vector::*;
|
||||||
type float = f64;
|
|
||||||
|
|
||||||
pub static A: Mat2<f64> = Mat2 { x: Vec2 { x: 1.0, y: 3.0 },
|
pub static A: Mat2<f64> = Mat2 { x: Vec2 { x: 1.0, y: 3.0 },
|
||||||
y: Vec2 { x: 2.0, y: 4.0 } };
|
y: Vec2 { x: 2.0, y: 4.0 } };
|
||||||
|
@ -37,7 +35,6 @@ pub mod mat2 {
|
||||||
pub mod mat3 {
|
pub mod mat3 {
|
||||||
use cgmath::matrix::*;
|
use cgmath::matrix::*;
|
||||||
use cgmath::vector::*;
|
use cgmath::vector::*;
|
||||||
type float = f64;
|
|
||||||
|
|
||||||
pub static A: Mat3<f64> = Mat3 { x: Vec3 { x: 1.0, y: 4.0, z: 7.0 },
|
pub static A: Mat3<f64> = Mat3 { x: Vec3 { x: 1.0, y: 4.0, z: 7.0 },
|
||||||
y: Vec3 { x: 2.0, y: 5.0, z: 8.0 },
|
y: Vec3 { x: 2.0, y: 5.0, z: 8.0 },
|
||||||
|
@ -59,7 +56,6 @@ pub mod mat3 {
|
||||||
pub mod mat4 {
|
pub mod mat4 {
|
||||||
use cgmath::matrix::*;
|
use cgmath::matrix::*;
|
||||||
use cgmath::vector::*;
|
use cgmath::vector::*;
|
||||||
type float = f64;
|
|
||||||
|
|
||||||
pub static A: Mat4<f64> = Mat4 { x: Vec4 { x: 1.0, y: 5.0, z: 9.0, w: 13.0 },
|
pub static A: Mat4<f64> = Mat4 { x: Vec4 { x: 1.0, y: 5.0, z: 9.0, w: 13.0 },
|
||||||
y: Vec4 { x: 2.0, y: 6.0, z: 10.0, w: 14.0 },
|
y: Vec4 { x: 2.0, y: 6.0, z: 10.0, w: 14.0 },
|
||||||
|
|
Loading…
Reference in a new issue