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
|
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 std::ops::{Div, DivAssign, Index, Mul, MulAssign};
|
|
|
|
|
use num::{One, Zero};
|
2016-12-05 05:44:42 +08:00
|
|
|
|
|
2018-02-02 19:26:35 +08:00
|
|
|
|
use alga::general::{ClosedAdd, ClosedMul};
|
2016-12-05 05:44:42 +08:00
|
|
|
|
|
2018-05-19 23:15:15 +08:00
|
|
|
|
use base::{DefaultAllocator, Matrix, MatrixMN, Scalar};
|
|
|
|
|
use base::dimension::{Dim, DimName, U1};
|
|
|
|
|
use base::constraint::{AreMultipliable, ShapeConstraint};
|
|
|
|
|
use base::storage::Storage;
|
|
|
|
|
use base::allocator::Allocator;
|
2016-12-05 05:44:42 +08:00
|
|
|
|
|
2017-08-03 01:37:44 +08:00
|
|
|
|
use geometry::{Point, Rotation};
|
2016-12-05 05:44:42 +08:00
|
|
|
|
|
2017-08-03 01:37:44 +08:00
|
|
|
|
impl<N: Scalar, D: DimName> Index<(usize, usize)> for Rotation<N, D>
|
2018-02-02 19:26:35 +08:00
|
|
|
|
where
|
|
|
|
|
DefaultAllocator: Allocator<N, D, D>,
|
|
|
|
|
{
|
2016-12-05 05:44:42 +08:00
|
|
|
|
type Output = N;
|
|
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
|
fn index(&self, row_col: (usize, usize)) -> &N {
|
|
|
|
|
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;
|
|
|
|
|
(D, D), (D, D) for D: DimName;
|
2017-08-03 01:37:44 +08:00
|
|
|
|
self: Rotation<N, D>, right: Rotation<N, D>, Output = Rotation<N, D>;
|
|
|
|
|
[val val] => Rotation::from_matrix_unchecked(self.unwrap() * right.unwrap());
|
|
|
|
|
[ref val] => Rotation::from_matrix_unchecked(self.matrix() * right.unwrap());
|
|
|
|
|
[val ref] => Rotation::from_matrix_unchecked(self.unwrap() * right.matrix());
|
|
|
|
|
[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
|
2016-12-05 05:44:42 +08:00
|
|
|
|
// FIXME: instead of calling inverse explicitely, could we just add a `mul_tr` or `mul_inv` method?
|
|
|
|
|
md_impl_all!(
|
|
|
|
|
Div, div;
|
|
|
|
|
(D, D), (D, D) for D: DimName;
|
2017-08-03 01:37:44 +08:00
|
|
|
|
self: Rotation<N, D>, right: Rotation<N, D>, Output = Rotation<N, D>;
|
2016-12-05 05:44:42 +08:00
|
|
|
|
[val val] => self * right.inverse();
|
|
|
|
|
[ref val] => self * right.inverse();
|
|
|
|
|
[val ref] => self * right.inverse();
|
|
|
|
|
[ref ref] => self * right.inverse();
|
|
|
|
|
);
|
|
|
|
|
|
2017-08-03 01:37:44 +08:00
|
|
|
|
// Rotation × Matrix
|
2016-12-05 05:44:42 +08:00
|
|
|
|
md_impl_all!(
|
|
|
|
|
Mul, mul;
|
2017-08-03 01:37:44 +08:00
|
|
|
|
(D1, D1), (R2, C2) for D1: DimName, R2: Dim, C2: Dim, SB: Storage<N, R2, C2>
|
|
|
|
|
where DefaultAllocator: Allocator<N, D1, C2>
|
2016-12-05 05:44:42 +08:00
|
|
|
|
where ShapeConstraint: AreMultipliable<D1, D1, R2, C2>;
|
2017-08-03 01:37:44 +08:00
|
|
|
|
self: Rotation<N, D1>, right: Matrix<N, R2, C2, SB>, Output = MatrixMN<N, D1, C2>;
|
2016-12-05 05:44:42 +08:00
|
|
|
|
[val val] => self.unwrap() * right;
|
|
|
|
|
[ref val] => self.matrix() * right;
|
|
|
|
|
[val ref] => self.unwrap() * right;
|
|
|
|
|
[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;
|
2017-08-03 01:37:44 +08:00
|
|
|
|
(R1, C1), (D2, D2) for R1: Dim, C1: Dim, D2: DimName, SA: Storage<N, R1, C1>
|
|
|
|
|
where DefaultAllocator: Allocator<N, R1, D2>
|
|
|
|
|
where ShapeConstraint: AreMultipliable<R1, C1, D2, D2>;
|
|
|
|
|
self: Matrix<N, R1, C1, SA>, right: Rotation<N, D2>, Output = MatrixMN<N, R1, D2>;
|
2016-12-05 05:44:42 +08:00
|
|
|
|
[val val] => self * right.unwrap();
|
|
|
|
|
[ref val] => self * right.unwrap();
|
|
|
|
|
[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;
|
2017-08-03 01:37:44 +08:00
|
|
|
|
(R1, C1), (D2, D2) for R1: Dim, C1: Dim, D2: DimName, SA: Storage<N, R1, C1>
|
|
|
|
|
where DefaultAllocator: Allocator<N, R1, D2>
|
2016-12-05 05:44:42 +08:00
|
|
|
|
where ShapeConstraint: AreMultipliable<R1, C1, D2, D2>;
|
2017-08-03 01:37:44 +08:00
|
|
|
|
self: Matrix<N, R1, C1, SA>, right: Rotation<N, D2>, Output = MatrixMN<N, R1, D2>;
|
2016-12-05 05:44:42 +08:00
|
|
|
|
[val val] => self * right.inverse();
|
|
|
|
|
[ref val] => self * right.inverse();
|
|
|
|
|
[val ref] => self * right.inverse();
|
|
|
|
|
[ref ref] => self * right.inverse();
|
|
|
|
|
);
|
|
|
|
|
|
2017-08-03 01:37:44 +08:00
|
|
|
|
// Rotation × Point
|
2016-12-05 05:44:42 +08:00
|
|
|
|
// FIXME: we don't handle properly non-zero origins here. Do we want this to be the intended
|
|
|
|
|
// behavior?
|
|
|
|
|
md_impl_all!(
|
|
|
|
|
Mul, mul;
|
|
|
|
|
(D, D), (D, U1) for D: DimName
|
2017-08-03 01:37:44 +08:00
|
|
|
|
where DefaultAllocator: Allocator<N, D>
|
|
|
|
|
where ShapeConstraint: AreMultipliable<D, D, D, U1>;
|
|
|
|
|
self: Rotation<N, D>, right: Point<N, D>, Output = Point<N, D>;
|
2016-12-05 05:44:42 +08:00
|
|
|
|
[val val] => self.unwrap() * right;
|
|
|
|
|
[ref val] => self.matrix() * right;
|
|
|
|
|
[val ref] => self.unwrap() * right;
|
|
|
|
|
[ref ref] => self.matrix() * right;
|
|
|
|
|
);
|
|
|
|
|
|
2017-08-03 01:37:44 +08:00
|
|
|
|
// Rotation ×= Rotation
|
2016-12-05 05:44:42 +08:00
|
|
|
|
// FIXME: try not to call `inverse()` explicitly.
|
|
|
|
|
|
|
|
|
|
md_assign_impl_all!(
|
|
|
|
|
MulAssign, mul_assign;
|
|
|
|
|
(D, D), (D, D) for D: DimName;
|
2017-08-03 01:37:44 +08:00
|
|
|
|
self: Rotation<N, D>, right: Rotation<N, D>;
|
2016-12-05 05:44:42 +08:00
|
|
|
|
[val] => unsafe { self.matrix_mut().mul_assign(right.unwrap()) };
|
|
|
|
|
[ref] => unsafe { self.matrix_mut().mul_assign(right.matrix()) };
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
md_assign_impl_all!(
|
|
|
|
|
DivAssign, div_assign;
|
|
|
|
|
(D, D), (D, D) for D: DimName;
|
2017-08-03 01:37:44 +08:00
|
|
|
|
self: Rotation<N, D>, right: Rotation<N, D>;
|
2016-12-05 05:44:42 +08:00
|
|
|
|
[val] => unsafe { self.matrix_mut().mul_assign(right.inverse().unwrap()) };
|
|
|
|
|
[ref] => unsafe { self.matrix_mut().mul_assign(right.inverse().matrix()) };
|
|
|
|
|
);
|
|
|
|
|
|
2017-08-03 01:37:44 +08:00
|
|
|
|
// Matrix *= Rotation
|
2016-12-05 05:44:42 +08:00
|
|
|
|
// FIXME: try not to call `inverse()` explicitly.
|
|
|
|
|
// FIXME: this shares the same limitations as for the current impl. of MulAssign for matrices.
|
|
|
|
|
// (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;
|
|
|
|
|
(R1, C1), (C1, C1) for R1: DimName, C1: DimName;
|
2017-08-03 01:37:44 +08:00
|
|
|
|
self: MatrixMN<N, R1, C1>, right: Rotation<N, C1>;
|
2016-12-05 05:44:42 +08:00
|
|
|
|
[val] => self.mul_assign(right.unwrap());
|
|
|
|
|
[ref] => self.mul_assign(right.matrix());
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
md_assign_impl_all!(
|
|
|
|
|
DivAssign, div_assign;
|
|
|
|
|
(R1, C1), (C1, C1) for R1: DimName, C1: DimName;
|
2017-08-03 01:37:44 +08:00
|
|
|
|
self: MatrixMN<N, R1, C1>, right: Rotation<N, C1>;
|
2016-12-05 05:44:42 +08:00
|
|
|
|
[val] => self.mul_assign(right.inverse().unwrap());
|
|
|
|
|
[ref] => self.mul_assign(right.inverse().matrix());
|
|
|
|
|
);
|