| 1 |
use alga::general::{ |
| 2 |
AbstractGroup, AbstractLoop, AbstractMagma, AbstractMonoid, AbstractQuasigroup, |
| 3 |
AbstractSemigroup, Identity, Multiplicative, RealField, TwoSidedInverse, |
| 4 |
}; |
| 5 |
use alga::linear::{ProjectiveTransformation, Transformation}; |
| 6 |
|
| 7 |
use crate::base::allocator::Allocator; |
| 8 |
use crate::base::dimension::{DimNameAdd, DimNameSum, U1}; |
| 9 |
use crate::base::{Const, DefaultAllocator, SVector}; |
| 10 |
|
| 11 |
use crate::geometry::{Point, SubTCategoryOf, TCategory, TProjective, Transform}; |
| 12 |
|
| 13 |
/* |
| 14 |
* |
| 15 |
* Algebraic structures. |
| 16 |
* |
| 17 |
*/ |
| 18 |
impl<T: RealField + simba::scalar::RealField, C, const D: usize> Identity<Multiplicative> |
| 19 |
for Transform<T, C, D> |
| 20 |
where |
| 21 |
Const<D>: DimNameAdd<U1>, |
| 22 |
C: TCategory, |
| 23 |
DefaultAllocator: Allocator<DimNameSum<Const<D>, U1>, DimNameSum<Const<D>, U1>>, |
| 24 |
{ |
| 25 |
#[inline] |
| 26 |
fn identity() -> Self { |
| 27 |
Self::identity() |
| 28 |
} |
| 29 |
} |
| 30 |
|
| 31 |
impl<T: RealField + simba::scalar::RealField, C, const D: usize> TwoSidedInverse<Multiplicative> |
| 32 |
for Transform<T, C, D> |
| 33 |
where |
| 34 |
Const<D>: DimNameAdd<U1>, |
| 35 |
C: SubTCategoryOf<TProjective>, |
| 36 |
DefaultAllocator: Allocator<DimNameSum<Const<D>, U1>, DimNameSum<Const<D>, U1>>, |
| 37 |
{ |
| 38 |
#[inline] |
| 39 |
fn two_sided_inverse(&self) -> Self { |
| 40 |
self.clone().inverse() |
| 41 |
} |
| 42 |
|
| 43 |
#[inline] |
| 44 |
fn two_sided_inverse_mut(&mut self) { |
| 45 |
self.inverse_mut() |
| 46 |
} |
| 47 |
} |
| 48 |
|
| 49 |
impl<T: RealField + simba::scalar::RealField, C, const D: usize> AbstractMagma<Multiplicative> |
| 50 |
for Transform<T, C, D> |
| 51 |
where |
| 52 |
Const<D>: DimNameAdd<U1>, |
| 53 |
C: TCategory, |
| 54 |
DefaultAllocator: Allocator<DimNameSum<Const<D>, U1>, DimNameSum<Const<D>, U1>>, |
| 55 |
{ |
| 56 |
#[inline] |
| 57 |
fn operate(&self, rhs: &Self) -> Self { |
| 58 |
self * rhs |
| 59 |
} |
| 60 |
} |
| 61 |
|
| 62 |
macro_rules! impl_multiplicative_structures( |
| 63 |
($($marker: ident<$operator: ident>),* $(,)*) => {$( |
| 64 |
impl<T: RealField + simba::scalar::RealField, C, const D: usize> $marker<$operator> for Transform<T, C, D> |
| 65 |
where |
| 66 |
Const<D>: DimNameAdd<U1>, |
| 67 |
C: TCategory, |
| 68 |
DefaultAllocator: Allocator<DimNameSum<Const<D>, U1>, DimNameSum<Const<D>, U1>> { } |
| 69 |
)*} |
| 70 |
); |
| 71 |
|
| 72 |
macro_rules! impl_inversible_multiplicative_structures( |
| 73 |
($($marker: ident<$operator: ident>),* $(,)*) => {$( |
| 74 |
impl<T: RealField + simba::scalar::RealField, C, const D: usize> $marker<$operator> for Transform<T, C, D> |
| 75 |
where |
| 76 |
Const<D>: DimNameAdd<U1>, |
| 77 |
C: SubTCategoryOf<TProjective>, |
| 78 |
DefaultAllocator: Allocator<DimNameSum<Const<D>, U1>, DimNameSum<Const<D>, U1>> { } |
| 79 |
)*} |
| 80 |
); |
| 81 |
|
| 82 |
impl_multiplicative_structures!( |
| 83 |
AbstractSemigroup<Multiplicative>, |
| 84 |
AbstractMonoid<Multiplicative>, |
| 85 |
); |
| 86 |
|
| 87 |
impl_inversible_multiplicative_structures!( |
| 88 |
AbstractQuasigroup<Multiplicative>, |
| 89 |
AbstractLoop<Multiplicative>, |
| 90 |
AbstractGroup<Multiplicative> |
| 91 |
); |
| 92 |
|
| 93 |
/* |
| 94 |
* |
| 95 |
* Transformation groups. |
| 96 |
* |
| 97 |
*/ |
| 98 |
impl<T, C, const D: usize> Transformation<Point<T, D>> for Transform<T, C, D> |
| 99 |
where |
| 100 |
Const<D>: DimNameAdd<U1>, |
| 101 |
T: RealField + simba::scalar::RealField, |
| 102 |
C: TCategory, |
| 103 |
DefaultAllocator: Allocator<DimNameSum<Const<D>, U1>, DimNameSum<Const<D>, U1>> |
| 104 |
+ Allocator<DimNameSum<Const<D>, U1>>, |
| 105 |
{ |
| 106 |
#[inline] |
| 107 |
fn transform_point(&self, pt: &Point<T, D>) -> Point<T, D> { |
| 108 |
self.transform_point(pt) |
| 109 |
} |
| 110 |
|
| 111 |
#[inline] |
| 112 |
fn transform_vector(&self, v: &SVector<T, D>) -> SVector<T, D> { |
| 113 |
self.transform_vector(v) |
| 114 |
} |
| 115 |
} |
| 116 |
|
| 117 |
impl<T, C, const D: usize> ProjectiveTransformation<Point<T, D>> for Transform<T, C, D> |
| 118 |
where |
| 119 |
Const<D>: DimNameAdd<U1>, |
| 120 |
T: RealField + simba::scalar::RealField, |
| 121 |
C: SubTCategoryOf<TProjective>, |
| 122 |
DefaultAllocator: Allocator<DimNameSum<Const<D>, U1>, DimNameSum<Const<D>, U1>> |
| 123 |
+ Allocator<DimNameSum<Const<D>, U1>>, |
| 124 |
{ |
| 125 |
#[inline] |
| 126 |
fn inverse_transform_point(&self, pt: &Point<T, D>) -> Point<T, D> { |
| 127 |
self.inverse_transform_point(pt) |
| 128 |
} |
| 129 |
|
| 130 |
#[inline] |
| 131 |
fn inverse_transform_vector(&self, v: &SVector<T, D>) -> SVector<T, D> { |
| 132 |
self.inverse_transform_vector(v) |
| 133 |
} |
| 134 |
} |
| 135 |
|
| 136 |
// TODO: we need to implement an SVD for this. |
| 137 |
// |
| 138 |
// impl<T, C, const D: usize> AffineTransformation<Point<T, D>> for Transform<T, C, D> |
| 139 |
// where T: RealField, |
| 140 |
// C: SubTCategoryOf<TAffine>, |
| 141 |
// DefaultAllocator: Allocator<DimNameSum<Const<D>, U1>, DimNameSum<Const<D>, U1>> { |
| 142 |
// type PreRotation = Rotation<T, D>; |
| 143 |
// type NonUniformScaling = OVector<T, D>; |
| 144 |
// type PostRotation = Rotation<T, D>; |
| 145 |
// type Translation = Translation<T, D>; |
| 146 |
// |
| 147 |
// #[inline] |
| 148 |
// fn decompose(&self) -> (Self::Translation, Self::PostRotation, Self::NonUniformScaling, Self::PreRotation) { |
| 149 |
// unimplemented!() |
| 150 |
// } |
| 151 |
// } |