From 063140d53397d9bd3bbc88fd6c87ba2bba78e0a5 Mon Sep 17 00:00:00 2001 From: Joshua Smith Date: Tue, 29 Mar 2022 19:17:11 -0500 Subject: [PATCH] formatting --- src/geometry/rotation_interpolation.rs | 39 +++++++------- src/geometry/rotation_specialization.rs | 71 ++++++++++++------------- tests/geometry/rotation.rs | 5 +- 3 files changed, 55 insertions(+), 60 deletions(-) diff --git a/src/geometry/rotation_interpolation.rs b/src/geometry/rotation_interpolation.rs index 56a55f17..ffea917b 100644 --- a/src/geometry/rotation_interpolation.rs +++ b/src/geometry/rotation_interpolation.rs @@ -1,5 +1,7 @@ -use crate::{RealField, Rotation, Rotation2, Rotation3, SimdRealField, UnitComplex, UnitQuaternion}; -use crate::{Const, U1, DimSub, DimDiff, Storage, ArrayStorage, Allocator, DefaultAllocator}; +use crate::{Allocator, ArrayStorage, Const, DefaultAllocator, DimDiff, DimSub, Storage, U1}; +use crate::{ + RealField, Rotation, Rotation2, Rotation3, SimdRealField, UnitComplex, UnitQuaternion, +}; /// # Interpolation impl Rotation2 { @@ -81,14 +83,15 @@ impl Rotation3 { } } -impl Rotation where +impl Rotation +where Const: DimSub, - ArrayStorage: Storage,Const>, - DefaultAllocator: Allocator,Const,Buffer=ArrayStorage> + Allocator> + - Allocator,DimDiff,U1>> + - Allocator,U1>> + ArrayStorage: Storage, Const>, + DefaultAllocator: Allocator, Const, Buffer = ArrayStorage> + + Allocator> + + Allocator, DimDiff, U1>> + + Allocator, U1>>, { - /// /// Computes the spherical linear interpolation between two general rotations. /// @@ -109,15 +112,13 @@ impl Rotation where //from SimdRealField to RealField #[inline] #[must_use] - pub fn slerp(&self, other: &Self, t:T) -> Self { - + pub fn slerp(&self, other: &Self, t: T) -> Self { use std::mem::transmute; //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 match D { - 0 => self.clone(), //FIXME: this doesn't really work in 1D since we can't interp between -1 and 1 @@ -127,23 +128,21 @@ impl Rotation where //NOTE: This is safe because we directly check the dimension first 2 => unsafe { let (self2d, other2d) = ( - transmute::<&Self,&Rotation2>(self), - transmute::<&Self,&Rotation2>(other), + transmute::<&Self, &Rotation2>(self), + transmute::<&Self, &Rotation2>(other), ); - transmute::<&Rotation2,&Self>(&self2d.slerp_2d(other2d, t)).clone() + transmute::<&Rotation2, &Self>(&self2d.slerp_2d(other2d, t)).clone() }, 3 => unsafe { let (self3d, other3d) = ( - transmute::<&Self,&Rotation3>(self), - transmute::<&Self,&Rotation3>(other), + transmute::<&Self, &Rotation3>(self), + transmute::<&Self, &Rotation3>(other), ); - transmute::<&Rotation3,&Self>(&self3d.slerp_3d(other3d, t)).clone() + transmute::<&Rotation3, &Self>(&self3d.slerp_3d(other3d, t)).clone() }, //the multiplication order matters here - _ => (other/self).powf(t) * self + _ => (other / self).powf(t) * self, } - } - } diff --git a/src/geometry/rotation_specialization.rs b/src/geometry/rotation_specialization.rs index 40fe5b12..e37826bf 100644 --- a/src/geometry/rotation_specialization.rs +++ b/src/geometry/rotation_specialization.rs @@ -15,11 +15,11 @@ use simba::scalar::RealField; use simba::simd::{SimdBool, SimdRealField}; use std::ops::Neg; -use crate::base::dimension::{Const, U1, U2, U3, DimSub, DimDiff}; use crate::base::allocator::Allocator; +use crate::base::dimension::{Const, DimDiff, DimSub, U1, U2, U3}; use crate::base::storage::Storage; -use crate::base::{ Matrix2, Matrix3, SMatrix, SVector, Unit, Vector, Vector1, Vector2, Vector3}; use crate::base::{ArrayStorage, DefaultAllocator}; +use crate::base::{Matrix2, Matrix3, SMatrix, SVector, Unit, Vector, Vector1, Vector2, Vector3}; use crate::geometry::{Rotation, Rotation2, Rotation3, UnitComplex, UnitQuaternion}; @@ -1007,9 +1007,7 @@ where } } -impl Rotation -{ - +impl Rotation { /// /// Raise the rotation to a given floating power, i.e., returns the rotation with the same /// axis as `self` and an angle equal to `self.angle()` multiplied by `n`. @@ -1028,12 +1026,14 @@ impl Rotation /// assert_eq!(pow.angle(), 2.4); /// ``` //FIXME: merging powf for Rotation2 into this raises the trait bounds from SimdRealField to RealField - pub fn powf(&self, t: T) -> Self where + pub fn powf(&self, t: T) -> Self + where Const: DimSub, - ArrayStorage: Storage,Const>, - DefaultAllocator: Allocator,Const,Buffer=ArrayStorage> + Allocator> + - Allocator,DimDiff,U1>> + - Allocator,U1>> + ArrayStorage: Storage, Const>, + DefaultAllocator: Allocator, Const, Buffer = ArrayStorage> + + Allocator> + + Allocator, DimDiff, U1>> + + Allocator, U1>>, { use std::mem::*; @@ -1041,33 +1041,36 @@ impl Rotation //that's stabilized, this is the best we can do. Theoretically, the compiler should //pretty thoroughly optimize away all the excess checks and conversions match D { - 0 => self.clone(), 1 => self.clone(), //NOTE: Not pretty, but without refactoring the API, this is the best we can do //NOTE: This is safe because we directly check the dimension first 2 => unsafe { - let r2d = transmute::<&Self,&Rotation2>(self).powf_2d(t); - transmute::<&Rotation2,&Self>(&r2d).clone() + let r2d = transmute::<&Self, &Rotation2>(self).powf_2d(t); + transmute::<&Rotation2, &Self>(&r2d).clone() }, 3 => unsafe { - let r3d = transmute::<&Self,&Rotation3>(self).powf_3d(t); - transmute::<&Rotation3,&Self>(&r3d).clone() + let r3d = transmute::<&Self, &Rotation3>(self).powf_3d(t); + transmute::<&Rotation3, &Self>(&r3d).clone() }, - _ => self.clone().general_pow(t) + _ => self.clone().general_pow(t), } } - fn general_pow(self, t:T) -> Self where + fn general_pow(self, t: T) -> Self + where Const: DimSub, - ArrayStorage: Storage,Const>, - DefaultAllocator: Allocator,Const,Buffer=ArrayStorage> + Allocator> + - Allocator,DimDiff,U1>> + - Allocator,U1>> + ArrayStorage: Storage, Const>, + DefaultAllocator: Allocator, Const, Buffer = ArrayStorage> + + Allocator> + + Allocator, DimDiff, U1>> + + Allocator, U1>>, { - if D<=1 { return self; } + if D <= 1 { + return self; + } // println!("r:{}", self); // println!("{}", self.clone().into_inner().hessenberg().unpack_h()); @@ -1082,19 +1085,17 @@ impl Rotation //go down the diagonal and pow every block let mut i = 0; - while i < D-1 { - + while i < D - 1 { if - //For most 2x2 blocks - //NOTE: we use strict equality since `nalgebra`'s schur decomp sets the infradiagonal to zero - !d[(i+1,i)].is_zero() || + //For most 2x2 blocks + //NOTE: we use strict equality since `nalgebra`'s schur decomp sets the infradiagonal to zero + !d[(i+1,i)].is_zero() || //for +-180 deg rotations d[(i,i)] Rotation let (s2, c2) = angle2.sin_cos(); //convert back into a rot block - d[(i, i )] = c2.clone(); - d[(i, i+1)] = -s2.clone(); - d[(i+1,i )] = s2; - d[(i+1,i+1)] = c2; + d[(i, i)] = c2.clone(); + d[(i, i + 1)] = -s2.clone(); + d[(i + 1, i)] = s2; + d[(i + 1, i + 1)] = c2; //increase by 2 so we don't accidentally misinterpret the //next line as a 180deg rotation i += 2; - } else { i += 1; } - } // println!("d:{:.3}", d); let qt = q.transpose(); //avoids an extra clone Self::from_matrix_unchecked(q * d * qt) - } - } diff --git a/tests/geometry/rotation.rs b/tests/geometry/rotation.rs index d804b064..056df627 100644 --- a/tests/geometry/rotation.rs +++ b/tests/geometry/rotation.rs @@ -32,9 +32,9 @@ fn quaternion_euler_angles_issue_494() { #[cfg(feature = "proptest-support")] mod proptest_tests { - use na::{self, Rotation, Rotation2, Rotation3, Unit, Vector, Matrix, SMatrix}; - use simba::scalar::RealField; + use na::{self, Matrix, Rotation, Rotation2, Rotation3, SMatrix, Unit, Vector}; use num_traits::Zero; + use simba::scalar::RealField; use std::f64; use crate::proptest::*; @@ -338,7 +338,6 @@ mod proptest_tests { )*} } - gen_powf_rotation_test!( fn powf_rotation_4(v1 in vector4(), v2 in vector4(), v3 in vector4(), v4 in vector4()); fn powf_rotation_5(v1 in vector5(), v2 in vector5(), v3 in vector5(), v4 in vector5());