use alga::general::{ AbstractGroup, AbstractLoop, AbstractMagma, AbstractMonoid, AbstractQuasigroup, AbstractSemigroup, Identity, Inverse, Multiplicative, Real, }; use alga::linear::Similarity as AlgaSimilarity; use alga::linear::{AffineTransformation, ProjectiveTransformation, Rotation, Transformation}; use base::allocator::Allocator; use base::dimension::DimName; use base::{DefaultAllocator, VectorN}; use geometry::{Point, Similarity, Translation}; /* * * Algebraic structures. * */ impl Identity for Similarity where R: Rotation>, DefaultAllocator: Allocator, { #[inline] fn identity() -> Self { Self::identity() } } impl Inverse for Similarity where R: Rotation>, DefaultAllocator: Allocator, { #[inline] fn inverse(&self) -> Self { self.inverse() } #[inline] fn inverse_mut(&mut self) { self.inverse_mut() } } impl AbstractMagma for Similarity where R: Rotation>, DefaultAllocator: Allocator, { #[inline] fn operate(&self, rhs: &Self) -> Self { self * rhs } } macro_rules! impl_multiplicative_structures( ($($marker: ident<$operator: ident>),* $(,)*) => {$( impl $marker<$operator> for Similarity where R: Rotation>, DefaultAllocator: Allocator { } )*} ); impl_multiplicative_structures!( AbstractSemigroup, AbstractMonoid, AbstractQuasigroup, AbstractLoop, AbstractGroup ); /* * * Transformation groups. * */ impl Transformation> for Similarity where R: Rotation>, DefaultAllocator: Allocator, { #[inline] fn transform_point(&self, pt: &Point) -> Point { self * pt } #[inline] fn transform_vector(&self, v: &VectorN) -> VectorN { self * v } } impl ProjectiveTransformation> for Similarity where R: Rotation>, DefaultAllocator: Allocator, { #[inline] fn inverse_transform_point(&self, pt: &Point) -> Point { self.isometry.inverse_transform_point(pt) / self.scaling() } #[inline] fn inverse_transform_vector(&self, v: &VectorN) -> VectorN { self.isometry.inverse_transform_vector(v) / self.scaling() } } impl AffineTransformation> for Similarity where R: Rotation>, DefaultAllocator: Allocator, { type NonUniformScaling = N; type Rotation = R; type Translation = Translation; #[inline] fn decompose(&self) -> (Translation, R, N, R) { ( self.isometry.translation.clone(), self.isometry.rotation.clone(), self.scaling(), 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 { Similarity::from_isometry(self.isometry.append_rotation(r), self.scaling()) } #[inline] fn prepend_rotation(&self, r: &Self::Rotation) -> Self { self * r } #[inline] fn append_scaling(&self, s: &Self::NonUniformScaling) -> Self { self.append_scaling(*s) } #[inline] fn prepend_scaling(&self, s: &Self::NonUniformScaling) -> Self { self.prepend_scaling(*s) } #[inline] fn append_rotation_wrt_point(&self, r: &Self::Rotation, p: &Point) -> Option { let mut res = self.clone(); res.append_rotation_wrt_point_mut(r, p); Some(res) } } impl AlgaSimilarity> for Similarity where R: Rotation>, DefaultAllocator: Allocator, { type Scaling = N; #[inline] fn translation(&self) -> Translation { self.isometry.translation() } #[inline] fn rotation(&self) -> R { self.isometry.rotation() } #[inline] fn scaling(&self) -> N { self.scaling() } }