use alga::general::{AbstractMagma, AbstractGroup, AbstractLoop, AbstractMonoid, AbstractQuasigroup, AbstractSemigroup, Real, Inverse, Multiplicative, Identity, Id}; use alga::linear::{Transformation, Similarity, AffineTransformation, DirectIsometry, Isometry, Rotation, ProjectiveTransformation}; use core::ColumnVector; use core::dimension::{DimName, U1}; use core::storage::OwnedStorage; use core::allocator::OwnedAllocator; use geometry::{IsometryBase, TranslationBase, PointBase}; /* * * Algebraic structures. * */ impl Identity for IsometryBase where N: Real, S: OwnedStorage, R: Rotation>, S::Alloc: OwnedAllocator { #[inline] fn identity() -> Self { Self::identity() } } impl Inverse for IsometryBase where N: Real, S: OwnedStorage, R: Rotation>, S::Alloc: OwnedAllocator { #[inline] fn inverse(&self) -> Self { self.inverse() } #[inline] fn inverse_mut(&mut self) { self.inverse_mut() } } impl AbstractMagma for IsometryBase where N: Real, S: OwnedStorage, R: Rotation>, S::Alloc: OwnedAllocator { #[inline] fn operate(&self, rhs: &Self) -> Self { self * rhs } } macro_rules! impl_multiplicative_structures( ($($marker: ident<$operator: ident>),* $(,)*) => {$( impl $marker<$operator> for IsometryBase where N: Real, S: OwnedStorage, R: Rotation>, S::Alloc: OwnedAllocator { } )*} ); impl_multiplicative_structures!( AbstractSemigroup, AbstractMonoid, AbstractQuasigroup, AbstractLoop, AbstractGroup ); /* * * Transformation groups. * */ impl Transformation> for IsometryBase where N: Real, S: OwnedStorage, R: Rotation>, S::Alloc: OwnedAllocator { #[inline] fn transform_point(&self, pt: &PointBase) -> PointBase { self * pt } #[inline] fn transform_vector(&self, v: &ColumnVector) -> ColumnVector { self * v } } impl ProjectiveTransformation> for IsometryBase where N: Real, S: OwnedStorage, R: Rotation>, S::Alloc: OwnedAllocator { #[inline] fn inverse_transform_point(&self, pt: &PointBase) -> PointBase { self.rotation.inverse_transform_point(&(pt - &self.translation.vector)) } #[inline] fn inverse_transform_vector(&self, v: &ColumnVector) -> ColumnVector { self.rotation.inverse_transform_vector(v) } } impl AffineTransformation> for IsometryBase where N: Real, S: OwnedStorage, R: Rotation>, S::Alloc: OwnedAllocator { type Rotation = R; type NonUniformScaling = Id; type Translation = TranslationBase; #[inline] fn decompose(&self) -> (TranslationBase, R, Id, R) { (self.translation.clone(), self.rotation.clone(), Id::new(), R::identity()) } #[inline] fn append_translation(&self, t: &Self::Translation) -> Self { t * self } #[inline] fn prepend_translation(&self, t: &Self::Translation) -> Self { self * t } #[inline] fn append_rotation(&self, r: &Self::Rotation) -> Self { let shift = r.transform_vector(&self.translation.vector); IsometryBase::from_parts(TranslationBase::from_vector(shift), r.clone() * self.rotation.clone()) } #[inline] fn prepend_rotation(&self, r: &Self::Rotation) -> Self { self * r } #[inline] fn append_scaling(&self, _: &Self::NonUniformScaling) -> Self { self.clone() } #[inline] fn prepend_scaling(&self, _: &Self::NonUniformScaling) -> Self { self.clone() } #[inline] fn append_rotation_wrt_point(&self, r: &Self::Rotation, p: &PointBase) -> Option { let mut res = self.clone(); res.append_rotation_wrt_point_mut(r, p); Some(res) } } impl Similarity> for IsometryBase where N: Real, S: OwnedStorage, R: Rotation>, S::Alloc: OwnedAllocator { type Scaling = Id; #[inline] fn translation(&self) -> TranslationBase { self.translation.clone() } #[inline] fn rotation(&self) -> R { self.rotation.clone() } #[inline] fn scaling(&self) -> Id { Id::new() } } macro_rules! marker_impl( ($($Trait: ident),*) => {$( impl $Trait> for IsometryBase where N: Real, S: OwnedStorage, R: Rotation>, S::Alloc: OwnedAllocator { } )*} ); marker_impl!(Isometry, DirectIsometry);