| 1 |
use alga::general::{ |
| 2 |
AbstractGroup, AbstractLoop, AbstractMagma, AbstractMonoid, AbstractQuasigroup, |
| 3 |
AbstractSemigroup, Id, Identity, Multiplicative, RealField, TwoSidedInverse, |
| 4 |
}; |
| 5 |
use alga::linear::{ |
| 6 |
self, AffineTransformation, DirectIsometry, Isometry, OrthogonalTransformation, |
| 7 |
ProjectiveTransformation, Similarity, Transformation, |
| 8 |
}; |
| 9 |
|
| 10 |
use crate::base::SVector; |
| 11 |
use crate::geometry::{Point, Rotation}; |
| 12 |
|
| 13 |
/* |
| 14 |
* |
| 15 |
* Algebraic structures. |
| 16 |
* |
| 17 |
*/ |
| 18 |
impl<T: RealField + simba::scalar::RealField, const D: usize> Identity<Multiplicative> |
| 19 |
for Rotation<T, D> |
| 20 |
{ |
| 21 |
#[inline] |
| 22 |
fn identity() -> Self { |
| 23 |
Self::identity() |
| 24 |
} |
| 25 |
} |
| 26 |
|
| 27 |
impl<T: RealField + simba::scalar::RealField, const D: usize> TwoSidedInverse<Multiplicative> |
| 28 |
for Rotation<T, D> |
| 29 |
{ |
| 30 |
#[inline] |
| 31 |
fn two_sided_inverse(&self) -> Self { |
| 32 |
self.transpose() |
| 33 |
} |
| 34 |
|
| 35 |
#[inline] |
| 36 |
fn two_sided_inverse_mut(&mut self) { |
| 37 |
self.transpose_mut() |
| 38 |
} |
| 39 |
} |
| 40 |
|
| 41 |
impl<T: RealField + simba::scalar::RealField, const D: usize> AbstractMagma<Multiplicative> |
| 42 |
for Rotation<T, D> |
| 43 |
{ |
| 44 |
#[inline] |
| 45 |
fn operate(&self, rhs: &Self) -> Self { |
| 46 |
self * rhs |
| 47 |
} |
| 48 |
} |
| 49 |
|
| 50 |
macro_rules! impl_multiplicative_structures( |
| 51 |
($($marker: ident<$operator: ident>),* $(,)*) => {$( |
| 52 |
impl<T: RealField + simba::scalar::RealField, const D: usize> $marker<$operator> for Rotation<T, D> |
| 53 |
{ } |
| 54 |
)*} |
| 55 |
); |
| 56 |
|
| 57 |
impl_multiplicative_structures!( |
| 58 |
AbstractSemigroup<Multiplicative>, |
| 59 |
AbstractMonoid<Multiplicative>, |
| 60 |
AbstractQuasigroup<Multiplicative>, |
| 61 |
AbstractLoop<Multiplicative>, |
| 62 |
AbstractGroup<Multiplicative> |
| 63 |
); |
| 64 |
|
| 65 |
/* |
| 66 |
* |
| 67 |
* Transformation groups. |
| 68 |
* |
| 69 |
*/ |
| 70 |
impl<T: RealField + simba::scalar::RealField, const D: usize> Transformation<Point<T, D>> |
| 71 |
for Rotation<T, D> |
| 72 |
{ |
| 73 |
#[inline] |
| 74 |
fn transform_point(&self, pt: &Point<T, D>) -> Point<T, D> { |
| 75 |
self.transform_point(pt) |
| 76 |
} |
| 77 |
|
| 78 |
#[inline] |
| 79 |
fn transform_vector(&self, v: &SVector<T, D>) -> SVector<T, D> { |
| 80 |
self.transform_vector(v) |
| 81 |
} |
| 82 |
} |
| 83 |
|
| 84 |
impl<T: RealField + simba::scalar::RealField, const D: usize> ProjectiveTransformation<Point<T, D>> |
| 85 |
for Rotation<T, D> |
| 86 |
{ |
| 87 |
#[inline] |
| 88 |
fn inverse_transform_point(&self, pt: &Point<T, D>) -> Point<T, D> { |
| 89 |
self.inverse_transform_point(pt) |
| 90 |
} |
| 91 |
|
| 92 |
#[inline] |
| 93 |
fn inverse_transform_vector(&self, v: &SVector<T, D>) -> SVector<T, D> { |
| 94 |
self.inverse_transform_vector(v) |
| 95 |
} |
| 96 |
} |
| 97 |
|
| 98 |
impl<T: RealField + simba::scalar::RealField, const D: usize> AffineTransformation<Point<T, D>> |
| 99 |
for Rotation<T, D> |
| 100 |
{ |
| 101 |
type Rotation = Self; |
| 102 |
type NonUniformScaling = Id; |
| 103 |
type Translation = Id; |
| 104 |
|
| 105 |
#[inline] |
| 106 |
fn decompose(&self) -> (Id, Self, Id, Self) { |
| 107 |
(Id::new(), *self, Id::new(), Self::identity()) |
| 108 |
} |
| 109 |
|
| 110 |
#[inline] |
| 111 |
fn append_translation(&self, _: &Self::Translation) -> Self { |
| 112 |
*self |
| 113 |
} |
| 114 |
|
| 115 |
#[inline] |
| 116 |
fn prepend_translation(&self, _: &Self::Translation) -> Self { |
| 117 |
*self |
| 118 |
} |
| 119 |
|
| 120 |
#[inline] |
| 121 |
fn append_rotation(&self, r: &Self::Rotation) -> Self { |
| 122 |
r * self |
| 123 |
} |
| 124 |
|
| 125 |
#[inline] |
| 126 |
fn prepend_rotation(&self, r: &Self::Rotation) -> Self { |
| 127 |
self * r |
| 128 |
} |
| 129 |
|
| 130 |
#[inline] |
| 131 |
fn append_scaling(&self, _: &Self::NonUniformScaling) -> Self { |
| 132 |
*self |
| 133 |
} |
| 134 |
|
| 135 |
#[inline] |
| 136 |
fn prepend_scaling(&self, _: &Self::NonUniformScaling) -> Self { |
| 137 |
*self |
| 138 |
} |
| 139 |
} |
| 140 |
|
| 141 |
impl<T: RealField + simba::scalar::RealField, const D: usize> Similarity<Point<T, D>> |
| 142 |
for Rotation<T, D> |
| 143 |
{ |
| 144 |
type Scaling = Id; |
| 145 |
|
| 146 |
#[inline] |
| 147 |
fn translation(&self) -> Id { |
| 148 |
Id::new() |
| 149 |
} |
| 150 |
|
| 151 |
#[inline] |
| 152 |
fn rotation(&self) -> Self { |
| 153 |
*self |
| 154 |
} |
| 155 |
|
| 156 |
#[inline] |
| 157 |
fn scaling(&self) -> Id { |
| 158 |
Id::new() |
| 159 |
} |
| 160 |
} |
| 161 |
|
| 162 |
macro_rules! marker_impl( |
| 163 |
($($Trait: ident),*) => {$( |
| 164 |
impl<T: RealField + simba::scalar::RealField, const D: usize> $Trait<Point<T, D>> for Rotation<T, D> |
| 165 |
{ } |
| 166 |
)*} |
| 167 |
); |
| 168 |
|
| 169 |
marker_impl!(Isometry, DirectIsometry, OrthogonalTransformation); |
| 170 |
|
| 171 |
/// Subgroups of the n-dimensional rotation group `SO(n)`. |
| 172 |
impl<T: RealField + simba::scalar::RealField, const D: usize> linear::Rotation<Point<T, D>> |
| 173 |
for Rotation<T, D> |
| 174 |
{ |
| 175 |
#[inline] |
| 176 |
fn powf(&self, _: T) -> Option<Self> { |
| 177 |
// XXX: Add the general case. |
| 178 |
// XXX: Use specialization for 2D and 3D. |
| 179 |
unimplemented!() |
| 180 |
} |
| 181 |
|
| 182 |
#[inline] |
| 183 |
fn rotation_between(_: &SVector<T, D>, _: &SVector<T, D>) -> Option<Self> { |
| 184 |
// XXX: Add the general case. |
| 185 |
// XXX: Use specialization for 2D and 3D. |
| 186 |
unimplemented!() |
| 187 |
} |
| 188 |
|
| 189 |
#[inline] |
| 190 |
fn scaled_rotation_between(_: &SVector<T, D>, _: &SVector<T, D>, _: T) -> Option<Self> { |
| 191 |
// XXX: Add the general case. |
| 192 |
// XXX: Use specialization for 2D and 3D. |
| 193 |
unimplemented!() |
| 194 |
} |
| 195 |
} |
| 196 |
|
| 197 |
/* |
| 198 |
impl<T: RealField + simba::scalar::RealField> Matrix for Rotation<T> { |
| 199 |
type Field = T; |
| 200 |
type Row = Matrix<T>; |
| 201 |
type Column = Matrix<T>; |
| 202 |
type Transpose = Self; |
| 203 |
|
| 204 |
#[inline] |
| 205 |
fn nrows(&self) -> usize { |
| 206 |
self.submatrix.nrows() |
| 207 |
} |
| 208 |
|
| 209 |
#[inline] |
| 210 |
fn ncolumns(&self) -> usize { |
| 211 |
self.submatrix.ncolumns() |
| 212 |
} |
| 213 |
|
| 214 |
#[inline] |
| 215 |
fn row(&self, i: usize) -> Self::Row { |
| 216 |
self.submatrix.row(i) |
| 217 |
} |
| 218 |
|
| 219 |
#[inline] |
| 220 |
fn column(&self, i: usize) -> Self::Column { |
| 221 |
self.submatrix.column(i) |
| 222 |
} |
| 223 |
|
| 224 |
#[inline] |
| 225 |
fn get(&self, i: usize, j: usize) -> Self::Field { |
| 226 |
self.submatrix[(i, j)] |
| 227 |
} |
| 228 |
|
| 229 |
#[inline] |
| 230 |
unsafe fn get_unchecked(&self, i: usize, j: usize) -> Self::Field { |
| 231 |
self.submatrix.at_fast(i, j) |
| 232 |
} |
| 233 |
|
| 234 |
#[inline] |
| 235 |
fn transpose(&self) -> Self::Transpose { |
| 236 |
Rotation::from_matrix_unchecked(self.submatrix.transpose()) |
| 237 |
} |
| 238 |
} |
| 239 |
|
| 240 |
impl<T: RealField + simba::scalar::RealField> SquareMatrix for Rotation<T> { |
| 241 |
type Vector = Matrix<T>; |
| 242 |
|
| 243 |
#[inline] |
| 244 |
fn diagonal(&self) -> Self::Coordinates { |
| 245 |
self.submatrix.diagonal() |
| 246 |
} |
| 247 |
|
| 248 |
#[inline] |
| 249 |
fn determinant(&self) -> Self::Field { |
| 250 |
crate::one() |
| 251 |
} |
| 252 |
|
| 253 |
#[inline] |
| 254 |
fn try_inverse(&self) -> Option<Self> { |
| 255 |
Some(::transpose(self)) |
| 256 |
} |
| 257 |
|
| 258 |
#[inline] |
| 259 |
fn try_inverse_mut(&mut self) -> bool { |
| 260 |
self.transpose_mut(); |
| 261 |
true |
| 262 |
} |
| 263 |
|
| 264 |
#[inline] |
| 265 |
fn transpose_mut(&mut self) { |
| 266 |
self.submatrix.transpose_mut() |
| 267 |
} |
| 268 |
} |
| 269 |
|
| 270 |
impl<T: RealField + simba::scalar::RealField> InversibleSquareMatrix for Rotation<T> { } |
| 271 |
*/ |