use alga::general::{ AbstractGroup, AbstractLoop, AbstractMagma, AbstractMonoid, AbstractQuasigroup, AbstractSemigroup, Id, Identity, TwoSidedInverse, Multiplicative, RealField, }; use alga::linear::Translation as AlgaTranslation; use alga::linear::{ AffineTransformation, DirectIsometry, Isometry, ProjectiveTransformation, Similarity, Transformation, }; use crate::base::allocator::Allocator; use crate::base::dimension::DimName; use crate::base::{DefaultAllocator, VectorN}; use crate::geometry::{Point, Translation}; /* * * Algebraic structures. * */ impl Identity for Translation where DefaultAllocator: Allocator { #[inline] fn identity() -> Self { Self::identity() } } impl TwoSidedInverse for Translation where DefaultAllocator: Allocator { #[inline] fn two_sided_inverse(&self) -> Self { self.inverse() } #[inline] fn two_sided_inverse_mut(&mut self) { self.inverse_mut() } } impl AbstractMagma for Translation where DefaultAllocator: Allocator { #[inline] fn operate(&self, rhs: &Self) -> Self { self * rhs } } macro_rules! impl_multiplicative_structures( ($($marker: ident<$operator: ident>),* $(,)*) => {$( impl $marker<$operator> for Translation where DefaultAllocator: Allocator { } )*} ); impl_multiplicative_structures!( AbstractSemigroup, AbstractMonoid, AbstractQuasigroup, AbstractLoop, AbstractGroup ); /* * * Transformation groups. * */ impl Transformation> for Translation where DefaultAllocator: Allocator { #[inline] fn transform_point(&self, pt: &Point) -> Point { self.transform_point(pt) } #[inline] fn transform_vector(&self, v: &VectorN) -> VectorN { v.clone() } } impl ProjectiveTransformation> for Translation where DefaultAllocator: Allocator { #[inline] fn inverse_transform_point(&self, pt: &Point) -> Point { self.inverse_transform_point(pt) } #[inline] fn inverse_transform_vector(&self, v: &VectorN) -> VectorN { v.clone() } } impl AffineTransformation> for Translation where DefaultAllocator: Allocator { type Rotation = Id; type NonUniformScaling = Id; type Translation = Self; #[inline] fn decompose(&self) -> (Self, Id, Id, Id) { (self.clone(), Id::new(), Id::new(), Id::new()) } #[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, _: &Self::Rotation) -> Self { self.clone() } #[inline] fn prepend_rotation(&self, _: &Self::Rotation) -> Self { self.clone() } #[inline] fn append_scaling(&self, _: &Self::NonUniformScaling) -> Self { self.clone() } #[inline] fn prepend_scaling(&self, _: &Self::NonUniformScaling) -> Self { self.clone() } } impl Similarity> for Translation where DefaultAllocator: Allocator { type Scaling = Id; #[inline] fn translation(&self) -> Self { self.clone() } #[inline] fn rotation(&self) -> Id { Id::new() } #[inline] fn scaling(&self) -> Id { Id::new() } } macro_rules! marker_impl( ($($Trait: ident),*) => {$( impl $Trait> for Translation where DefaultAllocator: Allocator { } )*} ); marker_impl!(Isometry, DirectIsometry); /// Subgroups of the n-dimensional translation group `T(n)`. impl AlgaTranslation> for Translation where DefaultAllocator: Allocator { #[inline] fn to_vector(&self) -> VectorN { self.vector.clone() } #[inline] fn from_vector(v: VectorN) -> Option { Some(Self::from(v)) } #[inline] fn powf(&self, n: N) -> Option { Some(Self::from(&self.vector * n)) } #[inline] fn translation_between(a: &Point, b: &Point) -> Option { Some(Self::from(b - a)) } }