Start from random rotation in from_matrix to prevent issues when calling from_matrix on rotation matrices
-use na::{Quaternion, RealField, UnitQuaternion, Vector2, Vector3};
+use std::f64::consts::PI;
+use na::{Matrix3, Quaternion, RealField, Rotation3, UnitQuaternion, UnitVector3, Vector2, Vector3};
#[test]
fn angle_2() {
@@ -16,6 +17,19 @@ fn angle_3() {
assert_eq!(a.angle(&b), 0.0);
}
+#[test]
+fn from_rotation_matrix() {
+ // Test degenerate case when from_matrix_eps gets stuck in maximum
+ let identity = Rotation3::from_matrix(&Matrix3::new(
+ 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0,
+ ));
+ assert_relative_eq!(identity, &Rotation3::identity(), epsilon = 0.001);
+ let rotated_z = Rotation3::from_matrix(&Matrix3::new(
+ 1.0, 0.0, 0.0, 0.0, -1.0, 0.0, 0.0, 0.0, -1.0,
+ ));
+ assert_relative_eq!(rotated_z, &Rotation3::from_axis_angle(&UnitVector3::new_unchecked(Vector3::new(1.0, 0.0, 0.0)), PI), epsilon = 0.001);
+}
+
#[test]
fn quaternion_euler_angles_issue_494() {
let quat = UnitQuaternion::from_quaternion(Quaternion::new(
