diff --git a/tests/mat.rs b/tests/mat.rs index c041569a..311b8906 100644 --- a/tests/mat.rs +++ b/tests/mat.rs @@ -2,8 +2,8 @@ extern crate nalgebra as na; extern crate rand; use rand::random; -use na::{Vec1, Vec3, Mat1, Mat2, Mat3, Mat4, Mat5, Mat6, Rot3, Persp3, PerspMat3, Ortho3, OrthoMat3, - DMat, DVec, Row, Col, BaseFloat}; +use na::{Vec1, Vec3, Mat1, Mat2, Mat3, Mat4, Mat5, Mat6, Rot2, Rot3, Persp3, PerspMat3, Ortho3, + OrthoMat3, DMat, DVec, Row, Col, BaseFloat}; macro_rules! test_inv_mat_impl( ($t: ty) => ( @@ -153,6 +153,48 @@ fn test_inv_rotation3() { } } +#[test] +fn test_rot3_rotation_between() { + let r1: Rot3 = random(); + let r2: Rot3 = random(); + + let delta = na::rotation_between(&r1, &r2); + + assert!(na::approx_eq(&(delta * r1), &r2)) +} + +#[test] +fn test_rot3_angle_between() { + let r1: Rot3 = random(); + let r2: Rot3 = random(); + + let delta = na::rotation_between(&r1, &r2); + let delta_angle = na::angle_between(&r1, &r2); + + assert!(na::approx_eq(&na::norm(&na::rotation(&delta)), &delta_angle)) +} + +#[test] +fn test_rot2_rotation_between() { + let r1: Rot2 = random(); + let r2: Rot2 = random(); + + let delta = na::rotation_between(&r1, &r2); + + assert!(na::approx_eq(&(delta * r1), &r2)) +} + +#[test] +fn test_rot2_angle_between() { + let r1: Rot2 = random(); + let r2: Rot2 = random(); + + let delta = na::rotation_between(&r1, &r2); + let delta_angle = na::angle_between(&r1, &r2); + + assert!(na::approx_eq(&na::norm(&na::rotation(&delta)), &delta_angle)) +} + #[test] fn test_mean_dmat() { let mat = DMat::from_row_vec( diff --git a/tests/quat.rs b/tests/quat.rs index df30a954..279ea623 100644 --- a/tests/quat.rs +++ b/tests/quat.rs @@ -69,3 +69,24 @@ fn test_quat_euler_angles() { assert!(na::approx_eq(&q.to_rot(), &m)) } } + +#[test] +fn test_quat_rotation_between() { + let q1: UnitQuat = random(); + let q2: UnitQuat = random(); + + let delta = na::rotation_between(&q1, &q2); + + assert!(na::approx_eq(&(delta * q1), &q2)) +} + +#[test] +fn test_quat_angle_between() { + let q1: UnitQuat = random(); + let q2: UnitQuat = random(); + + let delta = na::rotation_between(&q1, &q2); + let delta_angle = na::angle_between(&q1, &q2); + + assert!(na::approx_eq(&na::norm(&na::rotation(&delta)), &delta_angle)) +} diff --git a/tests/vec.rs b/tests/vec.rs index 140dca65..daceba03 100644 --- a/tests/vec.rs +++ b/tests/vec.rs @@ -2,7 +2,7 @@ extern crate nalgebra as na; extern crate rand; use rand::random; -use na::{Vec0, Vec1, Vec2, Vec3, Vec4, Vec5, Vec6, Mat3, Iterable, IterableMut}; +use na::{Vec0, Vec1, Vec2, Vec3, Vec4, Vec5, Vec6, Mat3, Rot2, Rot3, Iterable, IterableMut}; macro_rules! test_iterator_impl( ($t: ty, $n: ty) => ( @@ -317,3 +317,65 @@ fn test_outer_vec3() { 8.0, 10.0, 12.0, 12.0, 15.0, 18.0)); } + + +#[test] +fn test_vec3_rotation_between() { + for _ in (0usize .. 10000) { + let v1: Vec3 = random(); + + let mut v2: Vec3 = random(); + v2 = na::normalize(&v2) * na::norm(&v1); + + let rot = na::rotation_between(&v1, &v2); + + assert!(na::approx_eq(&(rot * v1), &v2)) + } +} + +#[test] +fn test_vec3_angle_between() { + for _ in (0usize .. 10000) { + let vec: Vec3 = random(); + let other: Vec3 = random(); + + // Ensure the axis we are using is orthogonal to `vec`. + let axis_ang = na::cross(&vec, &other); + let ang = na::norm(&axis_ang); + let rot = Rot3::new(axis_ang); + + let delta = na::angle_between(&vec, &(rot * vec)); + + assert!(na::approx_eq(&ang, &delta)) + } +} + + +#[test] +fn test_vec2_rotation_between() { + for _ in (0usize .. 10000) { + let v1: Vec2 = random(); + + let mut v2: Vec2 = random(); + v2 = na::normalize(&v2) * na::norm(&v1); + + let rot = na::rotation_between(&v1, &v2); + + assert!(na::approx_eq(&(rot * v1), &v2)) + } +} + +#[test] +fn test_vec2_angle_between() { + for _ in (0usize .. 10000) { + let axis_ang: Vec1 = random(); + let ang = na::norm(&axis_ang); + + let rot: Rot2 = Rot2::new(axis_ang); + let vec: Vec2 = random(); + + let delta = na::angle_between(&vec, &(rot * vec)); + + assert!(na::approx_eq(&ang, &delta)) + } +}