| 1 |
use alga::general::{ |
| 2 |
AbstractGroup, AbstractLoop, AbstractMagma, AbstractMonoid, AbstractQuasigroup, |
| 3 |
AbstractSemigroup, Id, Identity, Multiplicative, RealField, TwoSidedInverse, |
| 4 |
}; |
| 5 |
use alga::linear::Isometry as AlgaIsometry; |
| 6 |
use alga::linear::{ |
| 7 |
AffineTransformation, DirectIsometry, ProjectiveTransformation, Rotation, Similarity, |
| 8 |
Transformation, |
| 9 |
}; |
| 10 |
|
| 11 |
use crate::base::SVector; |
| 12 |
|
| 13 |
use crate::geometry::{AbstractRotation, Isometry, Point, Translation}; |
| 14 |
|
| 15 |
/* |
| 16 |
* |
| 17 |
* Algebraic structures. |
| 18 |
* |
| 19 |
*/ |
| 20 |
impl<T: RealField + simba::scalar::RealField, R, const D: usize> Identity<Multiplicative> |
| 21 |
for Isometry<T, R, D> |
| 22 |
where |
| 23 |
R: Rotation<Point<T, D>> + AbstractRotation<T, D>, |
| 24 |
{ |
| 25 |
#[inline] |
| 26 |
fn identity() -> Self { |
| 27 |
Self::identity() |
| 28 |
} |
| 29 |
} |
| 30 |
|
| 31 |
impl<T: RealField + simba::scalar::RealField, R, const D: usize> TwoSidedInverse<Multiplicative> |
| 32 |
for Isometry<T, R, D> |
| 33 |
where |
| 34 |
R: Rotation<Point<T, D>> + AbstractRotation<T, D>, |
| 35 |
{ |
| 36 |
#[inline] |
| 37 |
fn two_sided_inverse(&self) -> Self { |
| 38 |
self.inverse() |
| 39 |
} |
| 40 |
|
| 41 |
#[inline] |
| 42 |
fn two_sided_inverse_mut(&mut self) { |
| 43 |
self.inverse_mut() |
| 44 |
} |
| 45 |
} |
| 46 |
|
| 47 |
impl<T: RealField + simba::scalar::RealField, R, const D: usize> AbstractMagma<Multiplicative> |
| 48 |
for Isometry<T, R, D> |
| 49 |
where |
| 50 |
R: Rotation<Point<T, D>> + AbstractRotation<T, D>, |
| 51 |
{ |
| 52 |
#[inline] |
| 53 |
fn operate(&self, rhs: &Self) -> Self { |
| 54 |
self * rhs |
| 55 |
} |
| 56 |
} |
| 57 |
|
| 58 |
macro_rules! impl_multiplicative_structures( |
| 59 |
($($marker: ident<$operator: ident>),* $(,)*) => {$( |
| 60 |
impl<T: RealField + simba::scalar::RealField, R, const D: usize> $marker<$operator> for Isometry<T, R, D> |
| 61 |
where R: Rotation<Point<T, D>> + AbstractRotation<T, D> { } |
| 62 |
)*} |
| 63 |
); |
| 64 |
|
| 65 |
impl_multiplicative_structures!( |
| 66 |
AbstractSemigroup<Multiplicative>, |
| 67 |
AbstractMonoid<Multiplicative>, |
| 68 |
AbstractQuasigroup<Multiplicative>, |
| 69 |
AbstractLoop<Multiplicative>, |
| 70 |
AbstractGroup<Multiplicative> |
| 71 |
); |
| 72 |
|
| 73 |
/* |
| 74 |
* |
| 75 |
* Transformation groups. |
| 76 |
* |
| 77 |
*/ |
| 78 |
impl<T: RealField + simba::scalar::RealField, R, const D: usize> Transformation<Point<T, D>> |
| 79 |
for Isometry<T, R, D> |
| 80 |
where |
| 81 |
R: Rotation<Point<T, D>> + AbstractRotation<T, D>, |
| 82 |
{ |
| 83 |
#[inline] |
| 84 |
fn transform_point(&self, pt: &Point<T, D>) -> Point<T, D> { |
| 85 |
self.transform_point(pt) |
| 86 |
} |
| 87 |
|
| 88 |
#[inline] |
| 89 |
fn transform_vector(&self, v: &SVector<T, D>) -> SVector<T, D> { |
| 90 |
self.transform_vector(v) |
| 91 |
} |
| 92 |
} |
| 93 |
|
| 94 |
impl<T: RealField + simba::scalar::RealField, R, const D: usize> |
| 95 |
ProjectiveTransformation<Point<T, D>> for Isometry<T, R, D> |
| 96 |
where |
| 97 |
R: Rotation<Point<T, D>> + AbstractRotation<T, D>, |
| 98 |
{ |
| 99 |
#[inline] |
| 100 |
fn inverse_transform_point(&self, pt: &Point<T, D>) -> Point<T, D> { |
| 101 |
self.inverse_transform_point(pt) |
| 102 |
} |
| 103 |
|
| 104 |
#[inline] |
| 105 |
fn inverse_transform_vector(&self, v: &SVector<T, D>) -> SVector<T, D> { |
| 106 |
self.inverse_transform_vector(v) |
| 107 |
} |
| 108 |
} |
| 109 |
|
| 110 |
impl<T: RealField + simba::scalar::RealField, R, const D: usize> AffineTransformation<Point<T, D>> |
| 111 |
for Isometry<T, R, D> |
| 112 |
where |
| 113 |
R: Rotation<Point<T, D>> + AbstractRotation<T, D>, |
| 114 |
{ |
| 115 |
type Rotation = R; |
| 116 |
type NonUniformScaling = Id; |
| 117 |
type Translation = Translation<T, D>; |
| 118 |
|
| 119 |
#[inline] |
| 120 |
fn decompose(&self) -> (Self::Translation, R, Id, R) { |
| 121 |
( |
| 122 |
self.translation, |
| 123 |
self.rotation.clone(), |
| 124 |
Id::new(), |
| 125 |
<R as AbstractRotation<T, D>>::identity(), |
| 126 |
) |
| 127 |
} |
| 128 |
|
| 129 |
#[inline] |
| 130 |
fn append_translation(&self, t: &Self::Translation) -> Self { |
| 131 |
t * self |
| 132 |
} |
| 133 |
|
| 134 |
#[inline] |
| 135 |
fn prepend_translation(&self, t: &Self::Translation) -> Self { |
| 136 |
self * t |
| 137 |
} |
| 138 |
|
| 139 |
#[inline] |
| 140 |
fn append_rotation(&self, r: &Self::Rotation) -> Self { |
| 141 |
let shift = Transformation::transform_vector(r, &self.translation.vector); |
| 142 |
Isometry::from_parts(Translation::from(shift), r.clone() * self.rotation.clone()) |
| 143 |
} |
| 144 |
|
| 145 |
#[inline] |
| 146 |
fn prepend_rotation(&self, r: &Self::Rotation) -> Self { |
| 147 |
Isometry::from_parts(self.translation, self.rotation.prepend_rotation(r)) |
| 148 |
} |
| 149 |
|
| 150 |
#[inline] |
| 151 |
fn append_scaling(&self, _: &Self::NonUniformScaling) -> Self { |
| 152 |
self.clone() |
| 153 |
} |
| 154 |
|
| 155 |
#[inline] |
| 156 |
fn prepend_scaling(&self, _: &Self::NonUniformScaling) -> Self { |
| 157 |
self.clone() |
| 158 |
} |
| 159 |
|
| 160 |
#[inline] |
| 161 |
fn append_rotation_wrt_point(&self, r: &Self::Rotation, p: &Point<T, D>) -> Option<Self> { |
| 162 |
let mut res = self.clone(); |
| 163 |
res.append_rotation_wrt_point_mut(r, p); |
| 164 |
Some(res) |
| 165 |
} |
| 166 |
} |
| 167 |
|
| 168 |
impl<T: RealField + simba::scalar::RealField, R, const D: usize> Similarity<Point<T, D>> |
| 169 |
for Isometry<T, R, D> |
| 170 |
where |
| 171 |
R: Rotation<Point<T, D>> + AbstractRotation<T, D>, |
| 172 |
{ |
| 173 |
type Scaling = Id; |
| 174 |
|
| 175 |
#[inline] |
| 176 |
fn translation(&self) -> Translation<T, D> { |
| 177 |
self.translation |
| 178 |
} |
| 179 |
|
| 180 |
#[inline] |
| 181 |
fn rotation(&self) -> R { |
| 182 |
self.rotation.clone() |
| 183 |
} |
| 184 |
|
| 185 |
#[inline] |
| 186 |
fn scaling(&self) -> Id { |
| 187 |
Id::new() |
| 188 |
} |
| 189 |
} |
| 190 |
|
| 191 |
macro_rules! marker_impl( |
| 192 |
($($Trait: ident),*) => {$( |
| 193 |
impl<T: RealField + simba::scalar::RealField, R, const D: usize> $Trait<Point<T, D>> for Isometry<T, R, D> |
| 194 |
where R: Rotation<Point<T, D>> + AbstractRotation<T, D> { } |
| 195 |
)*} |
| 196 |
); |
| 197 |
|
| 198 |
marker_impl!(AlgaIsometry, DirectIsometry); |