/* * * This provides the following operator overladings: * * Index<(usize, usize)> * * Rotation × Rotation * Rotation ÷ Rotation * Rotation × Matrix * Matrix × Rotation * Matrix ÷ Rotation * Rotation × Point * Rotation × Unit * * * Rotation ×= Rotation * Matrix ×= Rotation */ use num::{One, Zero}; use std::ops::{Div, DivAssign, Index, Mul, MulAssign}; use alga::general::{ClosedAdd, ClosedMul}; use base::allocator::Allocator; use base::constraint::{AreMultipliable, ShapeConstraint}; use base::dimension::{Dim, DimName, U1}; use base::storage::Storage; use base::{DefaultAllocator, Matrix, MatrixMN, Scalar, Unit, Vector, VectorN}; use geometry::{Point, Rotation}; impl Index<(usize, usize)> for Rotation where DefaultAllocator: Allocator { type Output = N; #[inline] fn index(&self, row_col: (usize, usize)) -> &N { self.matrix().index(row_col) } } // Rotation × Rotation md_impl_all!( Mul, mul; (D, D), (D, D) for D: DimName; self: Rotation, right: Rotation, Output = Rotation; [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()); ); // Rotation ÷ Rotation // FIXME: instead of calling inverse explicitly, could we just add a `mul_tr` or `mul_inv` method? md_impl_all!( Div, div; (D, D), (D, D) for D: DimName; self: Rotation, right: Rotation, Output = Rotation; [val val] => self * right.inverse(); [ref val] => self * right.inverse(); [val ref] => self * right.inverse(); [ref ref] => self * right.inverse(); ); // Rotation × Matrix md_impl_all!( Mul, mul; (D1, D1), (R2, C2) for D1: DimName, R2: Dim, C2: Dim, SB: Storage where DefaultAllocator: Allocator where ShapeConstraint: AreMultipliable; self: Rotation, right: Matrix, Output = MatrixMN; [val val] => self.unwrap() * right; [ref val] => self.matrix() * right; [val ref] => self.unwrap() * right; [ref ref] => self.matrix() * right; ); // Matrix × Rotation md_impl_all!( Mul, mul; (R1, C1), (D2, D2) for R1: Dim, C1: Dim, D2: DimName, SA: Storage where DefaultAllocator: Allocator where ShapeConstraint: AreMultipliable; self: Matrix, right: Rotation, Output = MatrixMN; [val val] => self * right.unwrap(); [ref val] => self * right.unwrap(); [val ref] => self * right.matrix(); [ref ref] => self * right.matrix(); ); // Matrix ÷ Rotation md_impl_all!( Div, div; (R1, C1), (D2, D2) for R1: Dim, C1: Dim, D2: DimName, SA: Storage where DefaultAllocator: Allocator where ShapeConstraint: AreMultipliable; self: Matrix, right: Rotation, Output = MatrixMN; [val val] => self * right.inverse(); [ref val] => self * right.inverse(); [val ref] => self * right.inverse(); [ref ref] => self * right.inverse(); ); // Rotation × Point // 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 where DefaultAllocator: Allocator where ShapeConstraint: AreMultipliable; self: Rotation, right: Point, Output = Point; [val val] => self.unwrap() * right; [ref val] => self.matrix() * right; [val ref] => self.unwrap() * right; [ref ref] => self.matrix() * right; ); // Rotation × Unit md_impl_all!( Mul, mul; (D, D), (D, U1) for D: DimName, S: Storage where DefaultAllocator: Allocator where ShapeConstraint: AreMultipliable; self: Rotation, right: Unit>, Output = Unit>; [val val] => Unit::new_unchecked(self.unwrap() * right.unwrap()); [ref val] => Unit::new_unchecked(self.matrix() * right.unwrap()); [val ref] => Unit::new_unchecked(self.unwrap() * right.as_ref()); [ref ref] => Unit::new_unchecked(self.matrix() * right.as_ref()); ); // Rotation ×= Rotation // FIXME: try not to call `inverse()` explicitly. md_assign_impl_all!( MulAssign, mul_assign; (D, D), (D, D) for D: DimName; self: Rotation, right: Rotation; [val] => self.matrix_mut_unchecked().mul_assign(right.unwrap()); [ref] => self.matrix_mut_unchecked().mul_assign(right.matrix()); ); md_assign_impl_all!( DivAssign, div_assign; (D, D), (D, D) for D: DimName; self: Rotation, right: Rotation; [val] => self.matrix_mut_unchecked().mul_assign(right.inverse().unwrap()); [ref] => self.matrix_mut_unchecked().mul_assign(right.inverse().matrix()); ); // Matrix *= Rotation // 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; self: MatrixMN, right: Rotation; [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; self: MatrixMN, right: Rotation; [val] => self.mul_assign(right.inverse().unwrap()); [ref] => self.mul_assign(right.inverse().matrix()); );