use crate::geometry::{Rotation, UnitComplex, UnitQuaternion}; use crate::{Const, OVector, Point, SVector, Scalar, SimdRealField, Unit}; use simba::scalar::ClosedMul; /// Trait implemented by rotations that can be used inside of an `Isometry` or `Similarity`. pub trait AbstractRotation: PartialEq + ClosedMul + Clone { /// The rotation identity. fn identity() -> Self; /// The rotation inverse. fn inverse(&self) -> Self; /// Change `self` to its inverse. fn inverse_mut(&mut self); /// Apply the rotation to the given vector. fn transform_vector(&self, v: &SVector) -> SVector; /// Apply the rotation to the given point. fn transform_point(&self, p: &Point) -> Point; /// Apply the inverse rotation to the given vector. fn inverse_transform_vector(&self, v: &OVector>) -> OVector>; /// Apply the inverse rotation to the given unit vector. fn inverse_transform_unit_vector(&self, v: &Unit>) -> Unit> { Unit::new_unchecked(self.inverse_transform_vector(&**v)) } /// Apply the inverse rotation to the given point. fn inverse_transform_point(&self, p: &Point) -> Point; } impl AbstractRotation for Rotation where T::Element: SimdRealField, { #[inline] fn identity() -> Self { Self::identity() } #[inline] fn inverse(&self) -> Self { self.inverse() } #[inline] fn inverse_mut(&mut self) { self.inverse_mut() } #[inline] fn transform_vector(&self, v: &SVector) -> SVector { self * v } #[inline] fn transform_point(&self, p: &Point) -> Point { self * p } #[inline] fn inverse_transform_vector(&self, v: &SVector) -> SVector { self.inverse_transform_vector(v) } #[inline] fn inverse_transform_unit_vector(&self, v: &Unit>) -> Unit> { self.inverse_transform_unit_vector(v) } #[inline] fn inverse_transform_point(&self, p: &Point) -> Point { self.inverse_transform_point(p) } } impl AbstractRotation for UnitQuaternion where T::Element: SimdRealField, { #[inline] fn identity() -> Self { Self::identity() } #[inline] fn inverse(&self) -> Self { self.inverse() } #[inline] fn inverse_mut(&mut self) { self.inverse_mut() } #[inline] fn transform_vector(&self, v: &SVector) -> SVector { self * v } #[inline] fn transform_point(&self, p: &Point) -> Point { self * p } #[inline] fn inverse_transform_vector(&self, v: &SVector) -> SVector { self.inverse_transform_vector(v) } #[inline] fn inverse_transform_point(&self, p: &Point) -> Point { self.inverse_transform_point(p) } } impl AbstractRotation for UnitComplex where T::Element: SimdRealField, { #[inline] fn identity() -> Self { Self::identity() } #[inline] fn inverse(&self) -> Self { self.inverse() } #[inline] fn inverse_mut(&mut self) { self.inverse_mut() } #[inline] fn transform_vector(&self, v: &SVector) -> SVector { self * v } #[inline] fn transform_point(&self, p: &Point) -> Point { self * p } #[inline] fn inverse_transform_vector(&self, v: &SVector) -> SVector { self.inverse_transform_vector(v) } #[inline] fn inverse_transform_point(&self, p: &Point) -> Point { self.inverse_transform_point(p) } }