From 0c343fd9ac5221e14f21c9cd5e45fce75747679f Mon Sep 17 00:00:00 2001 From: Joshua Smith Date: Thu, 28 Mar 2024 21:13:06 -0400 Subject: [PATCH] fmt and test fixes --- src/geometry/rotation_interpolation.rs | 23 ++++++++++++++--------- tests/geometry/rotation.rs | 18 +++++++++--------- 2 files changed, 23 insertions(+), 18 deletions(-) diff --git a/src/geometry/rotation_interpolation.rs b/src/geometry/rotation_interpolation.rs index 39cde669..338a1139 100644 --- a/src/geometry/rotation_interpolation.rs +++ b/src/geometry/rotation_interpolation.rs @@ -113,7 +113,6 @@ where #[inline] #[must_use] pub fn slerp(&self, other: &Self, t: T) -> Self { - //The best option here would be to use #[feature(specialization)], but until //that's stabilized, this is the best we can do. Theoretically, the compiler should //pretty thoroughly optimize away all the excess checks and conversions @@ -125,29 +124,35 @@ where 2 => { let self2d = Rotation2::from_matrix_unchecked( - self.clone().into_inner().fixed_resize(T::zero()) + self.clone().into_inner().fixed_resize(T::zero()), ); let other2d = Rotation2::from_matrix_unchecked( - other.clone().into_inner().fixed_resize(T::zero()) + other.clone().into_inner().fixed_resize(T::zero()), ); Self::from_matrix_unchecked( - self2d.slerp_2d(&other2d, t).into_inner().fixed_resize(T::zero()) + self2d + .slerp_2d(&other2d, t) + .into_inner() + .fixed_resize(T::zero()), ) - }, + } 3 => { let self3d = Rotation3::from_matrix_unchecked( - self.clone().into_inner().fixed_resize(T::zero()) + self.clone().into_inner().fixed_resize(T::zero()), ); let other3d = Rotation3::from_matrix_unchecked( - other.clone().into_inner().fixed_resize(T::zero()) + other.clone().into_inner().fixed_resize(T::zero()), ); Self::from_matrix_unchecked( - self3d.slerp_3d(&other3d, t).into_inner().fixed_resize(T::zero()) + self3d + .slerp_3d(&other3d, t) + .into_inner() + .fixed_resize(T::zero()), ) - }, + } //the multiplication order matters here _ => (other / self).powf(t) * self, diff --git a/tests/geometry/rotation.rs b/tests/geometry/rotation.rs index dde2e764..097416d7 100644 --- a/tests/geometry/rotation.rs +++ b/tests/geometry/rotation.rs @@ -341,16 +341,16 @@ mod proptest_tests { //ambiguous when at ends of angle range, so we don't really care here if let Some(axis) = q.axis() { + if dtheta.abs() != f64::pi() { + //make two quaternions separated by an angle between -pi and pi + let (q1, q2) = (q, q * UnitQuaternion::from_axis_angle(&axis, dtheta)); + let q3 = q1.slerp(&q2, t); - //make two quaternions separated by an angle between -pi and pi - let (q1, q2) = (q, q * UnitQuaternion::from_axis_angle(&axis, dtheta)); - let q3 = q1.slerp(&q2, t); - - //since the angle is no larger than a half-turn, and t is between 0 and 1, - //the shortest path just corresponds to adding the scaled angle - let q4 = q1 * UnitQuaternion::from_axis_angle(&axis, dtheta*t); - prop_assert!(relative_eq!(q3, q4, epsilon=1e-10)); - + //since the angle is no larger than a half-turn, and t is between 0 and 1, + //the shortest path just corresponds to adding the scaled angle + let q4 = q1 * UnitQuaternion::from_axis_angle(&axis, dtheta*t); + prop_assert!(relative_eq!(q3, q4, epsilon=1e-9)); + } } }