use alga::general::{ AbstractGroup, AbstractLoop, AbstractMagma, AbstractMonoid, AbstractQuasigroup, AbstractSemigroup, Identity, Multiplicative, RealField, TwoSidedInverse, }; use alga::linear::{ProjectiveTransformation, Transformation}; use crate::base::allocator::Allocator; use crate::base::dimension::{DimNameAdd, DimNameSum, U1}; use crate::base::{Const, DefaultAllocator, SVector}; use crate::geometry::{Point, SubTCategoryOf, TCategory, TProjective, Transform}; /* * * Algebraic structures. * */ impl Identity for Transform where Const: DimNameAdd, C: TCategory, DefaultAllocator: Allocator, U1>, DimNameSum, U1>>, { #[inline] fn identity() -> Self { Self::identity() } } impl TwoSidedInverse for Transform where Const: DimNameAdd, C: SubTCategoryOf, DefaultAllocator: Allocator, U1>, DimNameSum, U1>>, { #[inline] fn two_sided_inverse(&self) -> Self { self.clone().inverse() } #[inline] fn two_sided_inverse_mut(&mut self) { self.inverse_mut() } } impl AbstractMagma for Transform where Const: DimNameAdd, C: TCategory, DefaultAllocator: Allocator, U1>, DimNameSum, U1>>, { #[inline] fn operate(&self, rhs: &Self) -> Self { self * rhs } } macro_rules! impl_multiplicative_structures( ($($marker: ident<$operator: ident>),* $(,)*) => {$( impl $marker<$operator> for Transform where Const: DimNameAdd, C: TCategory, DefaultAllocator: Allocator, U1>, DimNameSum, U1>> { } )*} ); macro_rules! impl_inversible_multiplicative_structures( ($($marker: ident<$operator: ident>),* $(,)*) => {$( impl $marker<$operator> for Transform where Const: DimNameAdd, C: SubTCategoryOf, DefaultAllocator: Allocator, U1>, DimNameSum, U1>> { } )*} ); impl_multiplicative_structures!( AbstractSemigroup, AbstractMonoid, ); impl_inversible_multiplicative_structures!( AbstractQuasigroup, AbstractLoop, AbstractGroup ); /* * * Transformation groups. * */ impl Transformation> for Transform where Const: DimNameAdd, T: RealField + simba::scalar::RealField, C: TCategory, DefaultAllocator: Allocator, U1>, DimNameSum, U1>> + Allocator, U1>>, { #[inline] fn transform_point(&self, pt: &Point) -> Point { self.transform_point(pt) } #[inline] fn transform_vector(&self, v: &SVector) -> SVector { self.transform_vector(v) } } impl ProjectiveTransformation> for Transform where Const: DimNameAdd, T: RealField + simba::scalar::RealField, C: SubTCategoryOf, DefaultAllocator: Allocator, U1>, DimNameSum, U1>> + Allocator, U1>>, { #[inline] fn inverse_transform_point(&self, pt: &Point) -> Point { self.inverse_transform_point(pt) } #[inline] fn inverse_transform_vector(&self, v: &SVector) -> SVector { self.inverse_transform_vector(v) } } // TODO: we need to implement an SVD for this. // // impl AffineTransformation> for Transform // where T: RealField, // C: SubTCategoryOf, // DefaultAllocator: Allocator, U1>, DimNameSum, U1>> { // type PreRotation = Rotation; // type NonUniformScaling = OVector; // type PostRotation = Rotation; // type Translation = Translation; // // #[inline] // fn decompose(&self) -> (Self::Translation, Self::PostRotation, Self::NonUniformScaling, Self::PreRotation) { // unimplemented!() // } // }