fmt and test fixes

This commit is contained in:
Joshua Smith 2024-03-28 21:13:06 -04:00
parent 3235751526
commit 0c343fd9ac
2 changed files with 23 additions and 18 deletions

View File

@ -113,7 +113,6 @@ where
#[inline] #[inline]
#[must_use] #[must_use]
pub fn slerp(&self, other: &Self, t: T) -> Self { pub fn slerp(&self, other: &Self, t: T) -> Self {
//The best option here would be to use #[feature(specialization)], but until //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 //that's stabilized, this is the best we can do. Theoretically, the compiler should
//pretty thoroughly optimize away all the excess checks and conversions //pretty thoroughly optimize away all the excess checks and conversions
@ -125,29 +124,35 @@ where
2 => { 2 => {
let self2d = Rotation2::from_matrix_unchecked( 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( 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( 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 => { 3 => {
let self3d = Rotation3::from_matrix_unchecked( 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( 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( 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 //the multiplication order matters here
_ => (other / self).powf(t) * self, _ => (other / self).powf(t) * self,

View File

@ -341,7 +341,7 @@ mod proptest_tests {
//ambiguous when at ends of angle range, so we don't really care here //ambiguous when at ends of angle range, so we don't really care here
if let Some(axis) = q.axis() { if let Some(axis) = q.axis() {
if dtheta.abs() != f64::pi() {
//make two quaternions separated by an angle between -pi and pi //make two quaternions separated by an angle between -pi and pi
let (q1, q2) = (q, q * UnitQuaternion::from_axis_angle(&axis, dtheta)); let (q1, q2) = (q, q * UnitQuaternion::from_axis_angle(&axis, dtheta));
let q3 = q1.slerp(&q2, t); let q3 = q1.slerp(&q2, t);
@ -349,8 +349,8 @@ mod proptest_tests {
//since the angle is no larger than a half-turn, and t is between 0 and 1, //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 //the shortest path just corresponds to adding the scaled angle
let q4 = q1 * UnitQuaternion::from_axis_angle(&axis, dtheta*t); let q4 = q1 * UnitQuaternion::from_axis_angle(&axis, dtheta*t);
prop_assert!(relative_eq!(q3, q4, epsilon=1e-10)); prop_assert!(relative_eq!(q3, q4, epsilon=1e-9));
}
} }
} }