Fix bug when trying to create a rotation matrix with a zero angle.

This commit is contained in:
Sébastien Crozet 2013-06-30 21:19:36 +00:00
parent 02e22717a4
commit 6fd9696253
2 changed files with 40 additions and 28 deletions

View File

@ -37,6 +37,10 @@ pub fn rotmat2<N: Copy + Trigonometric + Neg<N>>(angle: N) -> Rotmat<Mat2<N>>
pub fn rotmat3<N: Copy + Trigonometric + DivisionRing + Algebraic>
(axisangle: Vec3<N>) -> Rotmat<Mat3<N>>
{
if axisangle.sqnorm().is_zero()
{ One::one() }
else
{
let mut axis = axisangle;
let angle = axis.normalize();
let _1 = One::one::<N>();
@ -64,6 +68,7 @@ pub fn rotmat3<N: Copy + Trigonometric + DivisionRing + Algebraic>
(uy * uz * one_m_cos + ux * sin),
(sqz + (_1 - sqz) * cos) ] )
}
}
}
impl<N: Trigonometric + DivisionRing + Copy>

View File

@ -15,7 +15,7 @@ use traits::transpose::Transpose;
#[test]
use vec::Vec1;
#[test]
use mat::{Mat1, Mat2, Mat3};
use mat::{Mat1, Mat2, Mat3, Mat4, Mat5, Mat6};
#[test]
use adaptors::rotmat::Rotmat;
@ -42,10 +42,17 @@ fn test_inv_mat2()
fn test_inv_mat3()
{ test_inv_mat_impl!(Mat3<f64>); }
// FIXME: ICE
// #[test]
// fn test_inv_nmat()
// { test_inv_mat_impl!(NMat<d7, f64>); }
#[test]
fn test_inv_mat4()
{ test_inv_mat_impl!(Mat4<f64>); }
#[test]
fn test_inv_mat5()
{ test_inv_mat_impl!(Mat5<f64>); }
#[test]
fn test_inv_mat6()
{ test_inv_mat_impl!(Mat6<f64>); }
#[test]
fn test_rotation2()