2016-12-05 05:44:42 +08:00
|
|
|
|
/*
|
|
|
|
|
*
|
|
|
|
|
* This provides the following operator overladings:
|
|
|
|
|
*
|
|
|
|
|
* Index<(usize, usize)>
|
|
|
|
|
*
|
2017-08-03 01:37:44 +08:00
|
|
|
|
* Rotation × Rotation
|
|
|
|
|
* Rotation ÷ Rotation
|
|
|
|
|
* Rotation × Matrix
|
|
|
|
|
* Matrix × Rotation
|
|
|
|
|
* Matrix ÷ Rotation
|
|
|
|
|
* Rotation × Point
|
2018-09-25 03:31:54 +08:00
|
|
|
|
* Rotation × Unit<Vector>
|
2016-12-05 05:44:42 +08:00
|
|
|
|
*
|
|
|
|
|
*
|
2017-08-03 01:37:44 +08:00
|
|
|
|
* Rotation ×= Rotation
|
|
|
|
|
* Matrix ×= Rotation
|
2016-12-05 05:44:42 +08:00
|
|
|
|
*/
|
|
|
|
|
|
2018-02-02 19:26:35 +08:00
|
|
|
|
use num::{One, Zero};
|
2018-10-22 13:00:10 +08:00
|
|
|
|
use std::ops::{Div, DivAssign, Index, Mul, MulAssign};
|
2016-12-05 05:44:42 +08:00
|
|
|
|
|
2020-03-21 19:16:46 +08:00
|
|
|
|
use simba::scalar::{ClosedAdd, ClosedMul};
|
2016-12-05 05:44:42 +08:00
|
|
|
|
|
2019-03-23 21:29:07 +08:00
|
|
|
|
use crate::base::allocator::Allocator;
|
|
|
|
|
use crate::base::constraint::{AreMultipliable, ShapeConstraint};
|
2021-04-08 17:53:01 +08:00
|
|
|
|
use crate::base::dimension::{Dim, U1};
|
2019-03-23 21:29:07 +08:00
|
|
|
|
use crate::base::storage::Storage;
|
2021-04-08 17:53:01 +08:00
|
|
|
|
use crate::base::{
|
2021-04-11 17:00:38 +08:00
|
|
|
|
Const, DefaultAllocator, Matrix, OMatrix, SMatrix, SVector, Scalar, Unit, Vector,
|
2021-04-08 17:53:01 +08:00
|
|
|
|
};
|
2016-12-05 05:44:42 +08:00
|
|
|
|
|
2019-03-23 21:29:07 +08:00
|
|
|
|
use crate::geometry::{Point, Rotation};
|
2016-12-05 05:44:42 +08:00
|
|
|
|
|
2021-04-11 17:00:38 +08:00
|
|
|
|
impl<T: Scalar, const D: usize> Index<(usize, usize)> for Rotation<T, D> {
|
|
|
|
|
type Output = T;
|
2016-12-05 05:44:42 +08:00
|
|
|
|
|
|
|
|
|
#[inline]
|
2021-04-11 17:00:38 +08:00
|
|
|
|
fn index(&self, row_col: (usize, usize)) -> &T {
|
2016-12-05 05:44:42 +08:00
|
|
|
|
self.matrix().index(row_col)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-03 01:37:44 +08:00
|
|
|
|
// Rotation × Rotation
|
2016-12-05 05:44:42 +08:00
|
|
|
|
md_impl_all!(
|
|
|
|
|
Mul, mul;
|
2021-04-08 17:53:01 +08:00
|
|
|
|
(Const<D>, Const<D>), (Const<D>, Const<D>)
|
|
|
|
|
const D;
|
|
|
|
|
for;
|
|
|
|
|
where;
|
2021-04-11 17:00:38 +08:00
|
|
|
|
self: Rotation<T, D>, right: Rotation<T, D>, Output = Rotation<T, D>;
|
2018-12-10 04:16:06 +08:00
|
|
|
|
[val val] => Rotation::from_matrix_unchecked(self.into_inner() * right.into_inner());
|
|
|
|
|
[ref val] => Rotation::from_matrix_unchecked(self.matrix() * right.into_inner());
|
|
|
|
|
[val ref] => Rotation::from_matrix_unchecked(self.into_inner() * right.matrix());
|
2017-08-03 01:37:44 +08:00
|
|
|
|
[ref ref] => Rotation::from_matrix_unchecked(self.matrix() * right.matrix());
|
2016-12-05 05:44:42 +08:00
|
|
|
|
);
|
|
|
|
|
|
2017-08-03 01:37:44 +08:00
|
|
|
|
// Rotation ÷ Rotation
|
2020-11-15 23:57:49 +08:00
|
|
|
|
// TODO: instead of calling inverse explicitly, could we just add a `mul_tr` or `mul_inv` method?
|
2016-12-05 05:44:42 +08:00
|
|
|
|
md_impl_all!(
|
|
|
|
|
Div, div;
|
2021-04-08 17:53:01 +08:00
|
|
|
|
(Const<D>, Const<D>), (Const<D>, Const<D>)
|
|
|
|
|
const D;
|
|
|
|
|
for;
|
|
|
|
|
where;
|
2021-04-11 17:00:38 +08:00
|
|
|
|
self: Rotation<T, D>, right: Rotation<T, D>, Output = Rotation<T, D>;
|
2020-10-26 01:23:24 +08:00
|
|
|
|
[val val] => #[allow(clippy::suspicious_arithmetic_impl)] { self * right.inverse() };
|
|
|
|
|
[ref val] => #[allow(clippy::suspicious_arithmetic_impl)] { self * right.inverse() };
|
|
|
|
|
[val ref] => #[allow(clippy::suspicious_arithmetic_impl)] { self * right.inverse() };
|
|
|
|
|
[ref ref] => #[allow(clippy::suspicious_arithmetic_impl)] { self * right.inverse() };
|
2016-12-05 05:44:42 +08:00
|
|
|
|
);
|
|
|
|
|
|
2017-08-03 01:37:44 +08:00
|
|
|
|
// Rotation × Matrix
|
2016-12-05 05:44:42 +08:00
|
|
|
|
md_impl_all!(
|
|
|
|
|
Mul, mul;
|
2021-04-08 17:53:01 +08:00
|
|
|
|
(Const<D1>, Const<D1>), (R2, C2)
|
|
|
|
|
const D1;
|
|
|
|
|
for R2, C2, SB;
|
2021-04-11 17:00:38 +08:00
|
|
|
|
where R2: Dim, C2: Dim, SB: Storage<T, R2, C2>,
|
|
|
|
|
DefaultAllocator: Allocator<T, Const<D1>, C2>,
|
2021-04-08 17:53:01 +08:00
|
|
|
|
ShapeConstraint: AreMultipliable<Const<D1>, Const<D1>, R2, C2>;
|
2021-04-11 17:00:38 +08:00
|
|
|
|
self: Rotation<T, D1>, right: Matrix<T, R2, C2, SB>, Output = OMatrix<T, Const<D1>, C2>;
|
2018-12-10 04:16:06 +08:00
|
|
|
|
[val val] => self.into_inner() * right;
|
2016-12-05 05:44:42 +08:00
|
|
|
|
[ref val] => self.matrix() * right;
|
2018-12-10 04:16:06 +08:00
|
|
|
|
[val ref] => self.into_inner() * right;
|
2016-12-05 05:44:42 +08:00
|
|
|
|
[ref ref] => self.matrix() * right;
|
|
|
|
|
);
|
|
|
|
|
|
2017-08-03 01:37:44 +08:00
|
|
|
|
// Matrix × Rotation
|
2016-12-05 05:44:42 +08:00
|
|
|
|
md_impl_all!(
|
|
|
|
|
Mul, mul;
|
2021-04-08 17:53:01 +08:00
|
|
|
|
(R1, C1), (Const<D2>, Const<D2>)
|
|
|
|
|
const D2;
|
|
|
|
|
for R1, C1, SA;
|
2021-04-11 17:00:38 +08:00
|
|
|
|
where R1: Dim, C1: Dim, SA: Storage<T, R1, C1>,
|
|
|
|
|
DefaultAllocator: Allocator<T, R1, Const<D2>>,
|
2021-04-08 17:53:01 +08:00
|
|
|
|
ShapeConstraint: AreMultipliable<R1, C1, Const<D2>, Const<D2>>;
|
2021-04-11 17:00:38 +08:00
|
|
|
|
self: Matrix<T, R1, C1, SA>, right: Rotation<T, D2>, Output = OMatrix<T, R1, Const<D2>>;
|
2018-12-10 04:16:06 +08:00
|
|
|
|
[val val] => self * right.into_inner();
|
|
|
|
|
[ref val] => self * right.into_inner();
|
2016-12-05 05:44:42 +08:00
|
|
|
|
[val ref] => self * right.matrix();
|
|
|
|
|
[ref ref] => self * right.matrix();
|
|
|
|
|
);
|
|
|
|
|
|
2017-08-03 01:37:44 +08:00
|
|
|
|
// Matrix ÷ Rotation
|
2016-12-05 05:44:42 +08:00
|
|
|
|
md_impl_all!(
|
|
|
|
|
Div, div;
|
2021-04-08 17:53:01 +08:00
|
|
|
|
(R1, C1), (Const<D2>, Const<D2>)
|
|
|
|
|
const D2;
|
|
|
|
|
for R1, C1, SA;
|
2021-04-11 17:00:38 +08:00
|
|
|
|
where R1: Dim, C1: Dim, SA: Storage<T, R1, C1>,
|
|
|
|
|
DefaultAllocator: Allocator<T, R1, Const<D2>>,
|
2021-04-08 17:53:01 +08:00
|
|
|
|
ShapeConstraint: AreMultipliable<R1, C1, Const<D2>, Const<D2>>;
|
2021-04-11 17:00:38 +08:00
|
|
|
|
self: Matrix<T, R1, C1, SA>, right: Rotation<T, D2>, Output = OMatrix<T, R1, Const<D2>>;
|
2020-10-26 01:23:24 +08:00
|
|
|
|
[val val] => #[allow(clippy::suspicious_arithmetic_impl)] { self * right.inverse() };
|
|
|
|
|
[ref val] => #[allow(clippy::suspicious_arithmetic_impl)] { self * right.inverse() };
|
|
|
|
|
[val ref] => #[allow(clippy::suspicious_arithmetic_impl)] { self * right.inverse() };
|
|
|
|
|
[ref ref] => #[allow(clippy::suspicious_arithmetic_impl)] { self * right.inverse() };
|
2016-12-05 05:44:42 +08:00
|
|
|
|
);
|
|
|
|
|
|
2017-08-03 01:37:44 +08:00
|
|
|
|
// Rotation × Point
|
2020-11-15 23:57:49 +08:00
|
|
|
|
// TODO: we don't handle properly non-zero origins here. Do we want this to be the intended
|
2016-12-05 05:44:42 +08:00
|
|
|
|
// behavior?
|
|
|
|
|
md_impl_all!(
|
|
|
|
|
Mul, mul;
|
2021-04-08 17:53:01 +08:00
|
|
|
|
(Const<D>, Const<D>), (Const<D>, U1)
|
|
|
|
|
const D;
|
|
|
|
|
for;
|
|
|
|
|
where ShapeConstraint: AreMultipliable<Const<D>, Const<D>, Const<D>, U1>;
|
2021-04-11 17:00:38 +08:00
|
|
|
|
self: Rotation<T, D>, right: Point<T, D>, Output = Point<T, D>;
|
2018-12-10 04:16:06 +08:00
|
|
|
|
[val val] => self.into_inner() * right;
|
2016-12-05 05:44:42 +08:00
|
|
|
|
[ref val] => self.matrix() * right;
|
2018-12-10 04:16:06 +08:00
|
|
|
|
[val ref] => self.into_inner() * right;
|
2016-12-05 05:44:42 +08:00
|
|
|
|
[ref ref] => self.matrix() * right;
|
|
|
|
|
);
|
|
|
|
|
|
2018-09-25 03:31:54 +08:00
|
|
|
|
// Rotation × Unit<Vector>
|
|
|
|
|
md_impl_all!(
|
|
|
|
|
Mul, mul;
|
2021-04-08 17:53:01 +08:00
|
|
|
|
(Const<D>, Const<D>), (Const<D>, U1)
|
|
|
|
|
const D;
|
|
|
|
|
for S;
|
2021-04-11 17:00:38 +08:00
|
|
|
|
where S: Storage<T, Const<D>>,
|
2021-04-08 17:53:01 +08:00
|
|
|
|
ShapeConstraint: AreMultipliable<Const<D>, Const<D>, Const<D>, U1>;
|
2021-04-11 17:00:38 +08:00
|
|
|
|
self: Rotation<T, D>, right: Unit<Vector<T, Const<D>, S>>, Output = Unit<SVector<T, D>>;
|
2018-12-10 04:16:06 +08:00
|
|
|
|
[val val] => Unit::new_unchecked(self.into_inner() * right.into_inner());
|
2018-12-10 04:08:14 +08:00
|
|
|
|
[ref val] => Unit::new_unchecked(self.matrix() * right.into_inner());
|
2018-12-10 04:16:06 +08:00
|
|
|
|
[val ref] => Unit::new_unchecked(self.into_inner() * right.as_ref());
|
2018-09-25 03:31:54 +08:00
|
|
|
|
[ref ref] => Unit::new_unchecked(self.matrix() * right.as_ref());
|
|
|
|
|
);
|
|
|
|
|
|
2017-08-03 01:37:44 +08:00
|
|
|
|
// Rotation ×= Rotation
|
2020-11-15 23:57:49 +08:00
|
|
|
|
// TODO: try not to call `inverse()` explicitly.
|
2016-12-05 05:44:42 +08:00
|
|
|
|
|
|
|
|
|
md_assign_impl_all!(
|
|
|
|
|
MulAssign, mul_assign;
|
2021-04-08 17:53:01 +08:00
|
|
|
|
(Const<D>, Const<D>), (Const<D>, Const<D>)
|
|
|
|
|
const D; for; where;
|
2021-04-11 17:00:38 +08:00
|
|
|
|
self: Rotation<T, D>, right: Rotation<T, D>;
|
2018-12-10 04:16:06 +08:00
|
|
|
|
[val] => self.matrix_mut_unchecked().mul_assign(right.into_inner());
|
2018-11-03 20:35:56 +08:00
|
|
|
|
[ref] => self.matrix_mut_unchecked().mul_assign(right.matrix());
|
2016-12-05 05:44:42 +08:00
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
md_assign_impl_all!(
|
|
|
|
|
DivAssign, div_assign;
|
2021-04-08 17:53:01 +08:00
|
|
|
|
(Const<D>, Const<D>), (Const<D>, Const<D>)
|
|
|
|
|
const D; for; where;
|
2021-04-11 17:00:38 +08:00
|
|
|
|
self: Rotation<T, D>, right: Rotation<T, D>;
|
2018-12-10 04:16:06 +08:00
|
|
|
|
[val] => self.matrix_mut_unchecked().mul_assign(right.inverse().into_inner());
|
2018-11-03 20:35:56 +08:00
|
|
|
|
[ref] => self.matrix_mut_unchecked().mul_assign(right.inverse().matrix());
|
2016-12-05 05:44:42 +08:00
|
|
|
|
);
|
|
|
|
|
|
2017-08-03 01:37:44 +08:00
|
|
|
|
// Matrix *= Rotation
|
2020-11-15 23:57:49 +08:00
|
|
|
|
// TODO: try not to call `inverse()` explicitly.
|
|
|
|
|
// TODO: this shares the same limitations as for the current impl. of MulAssign for matrices.
|
2016-12-05 05:44:42 +08:00
|
|
|
|
// (In particular the number of matrix column must be equal to the number of rotation columns,
|
|
|
|
|
// i.e., equal to the rotation dimension.
|
|
|
|
|
|
|
|
|
|
md_assign_impl_all!(
|
|
|
|
|
MulAssign, mul_assign;
|
2021-04-08 17:53:01 +08:00
|
|
|
|
(Const<R1>, Const<C1>), (Const<C1>, Const<C1>)
|
|
|
|
|
const R1, C1; for; where;
|
2021-04-11 17:00:38 +08:00
|
|
|
|
self: SMatrix<T, R1, C1>, right: Rotation<T, C1>;
|
2018-12-10 04:16:06 +08:00
|
|
|
|
[val] => self.mul_assign(right.into_inner());
|
2016-12-05 05:44:42 +08:00
|
|
|
|
[ref] => self.mul_assign(right.matrix());
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
md_assign_impl_all!(
|
|
|
|
|
DivAssign, div_assign;
|
2021-04-08 17:53:01 +08:00
|
|
|
|
(Const<R1>, Const<C1>), (Const<C1>, Const<C1>)
|
|
|
|
|
const R1, C1; for; where;
|
2021-04-11 17:00:38 +08:00
|
|
|
|
self: SMatrix<T, R1, C1>, right: Rotation<T, C1>;
|
2018-12-10 04:16:06 +08:00
|
|
|
|
[val] => self.mul_assign(right.inverse().into_inner());
|
2016-12-05 05:44:42 +08:00
|
|
|
|
[ref] => self.mul_assign(right.inverse().matrix());
|
|
|
|
|
);
|