Skip to content

Commit

Permalink
fmt and test fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jsmith628 committed Mar 29, 2024
1 parent 3235751 commit 0c343fd
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 19 deletions.
23 changes: 14 additions & 9 deletions src/geometry/rotation_interpolation.rs
Expand Up @@ -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
Expand All @@ -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,
Expand Down
20 changes: 10 additions & 10 deletions tests/geometry/rotation.rs
Expand Up @@ -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() {

//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));

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);

//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));
}
}

}
Expand Down

0 comments on commit 0c343fd

Please sign in to comment.