From 4ea1dd92e62357f66b80b0fe6aa83efb3fe5efa3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Crozet?= Date: Tue, 23 Jul 2013 11:15:20 +0200 Subject: [PATCH] Fixed transposition. --- src/mat_macros.rs | 2 +- src/tests/mat.rs | 55 ++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 55 insertions(+), 2 deletions(-) diff --git a/src/mat_macros.rs b/src/mat_macros.rs index f25b59ba..ed15c500 100644 --- a/src/mat_macros.rs +++ b/src/mat_macros.rs @@ -340,7 +340,7 @@ macro_rules! transpose_impl( { for iterate(1u, $dim) |i| { - for iterate(0u, $dim - 1) |j| + for iterate(0u, i) |j| { self.swap((i, j), (j, i)) } } } diff --git a/src/tests/mat.rs b/src/tests/mat.rs index dd9e9937..fae11d1f 100644 --- a/src/tests/mat.rs +++ b/src/tests/mat.rs @@ -5,6 +5,10 @@ use std::rand::random; #[test] use std::cmp::ApproxEq; #[test] +use traits::norm::Norm; +#[test] +use traits::scalar_op::ScalarMul; +#[test] use traits::inv::Inv; #[test] use traits::rotation::{Rotation, Rotatable}; @@ -13,7 +17,7 @@ use traits::indexable::Indexable; #[test] use traits::transpose::Transpose; #[test] -use vec::Vec1; +use vec::{Vec1, Vec3}; #[test] use mat::{Mat1, Mat2, Mat3, Mat4, Mat5, Mat6}; #[test] @@ -30,6 +34,41 @@ macro_rules! test_inv_mat_impl( ); ) +macro_rules! test_transpose_mat_impl( + ($t: ty) => ( + for 10000.times + { + let randmat : $t = random(); + + assert!(randmat.transposed().transposed().eq(&randmat)); + } + ); +) + +#[test] +fn test_transpose_mat1() +{ test_transpose_mat_impl!(Mat1); } + +#[test] +fn test_transpose_mat2() +{ test_transpose_mat_impl!(Mat2); } + +#[test] +fn test_transpose_mat3() +{ test_transpose_mat_impl!(Mat3); } + +#[test] +fn test_transpose_mat4() +{ test_transpose_mat_impl!(Mat4); } + +#[test] +fn test_transpose_mat5() +{ test_transpose_mat_impl!(Mat5); } + +#[test] +fn test_transpose_mat6() +{ test_transpose_mat_impl!(Mat6); } + #[test] fn test_inv_mat1() { test_inv_mat_impl!(Mat1); } @@ -73,3 +112,17 @@ fn test_index_mat2() assert!(mat.at((0, 1)) == mat.transposed().at((1, 0))); } + +#[test] +fn test_inv_rotation3() +{ + for 10000.times + { + let randmat = One::one::>>(); + let dir: Vec3 = random(); + let ang = &dir.normalized().scalar_mul(&(abs::(random()) % Real::pi())); + let rot = randmat.rotated(ang); + + assert!((rot.transposed() * rot).approx_eq(&One::one())); + } +}