/* * * 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 simba::scalar::{ClosedAdd, ClosedMul}; use crate::base::allocator::Allocator; use crate::base::constraint::{AreMultipliable, ShapeConstraint}; use crate::base::dimension::{Dim, U1}; use crate::base::storage::Storage; use crate::base::{ CMatrixMN, CVectorN, Const, DefaultAllocator, Matrix, MatrixMN, Scalar, Unit, Vector, }; use crate::geometry::{Point, Rotation}; impl Index<(usize, usize)> for Rotation { type Output = N; #[inline] fn index(&self, row_col: (usize, usize)) -> &N { self.matrix().index(row_col) } } // Rotation × Rotation md_impl_all!( Mul, mul; (Const, Const), (Const, Const) const D; for; where; self: Rotation, right: Rotation, Output = Rotation; [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()); [ref ref] => Rotation::from_matrix_unchecked(self.matrix() * right.matrix()); ); // Rotation ÷ Rotation // TODO: instead of calling inverse explicitly, could we just add a `mul_tr` or `mul_inv` method? md_impl_all!( Div, div; (Const, Const), (Const, Const) const D; for; where; self: Rotation, right: Rotation, Output = Rotation; [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() }; ); // Rotation × Matrix md_impl_all!( Mul, mul; (Const, Const), (R2, C2) const D1; for R2, C2, SB; where R2: Dim, C2: Dim, SB: Storage, DefaultAllocator: Allocator, C2>, ShapeConstraint: AreMultipliable, Const, R2, C2>; self: Rotation, right: Matrix, Output = MatrixMN, C2>; [val val] => self.into_inner() * right; [ref val] => self.matrix() * right; [val ref] => self.into_inner() * right; [ref ref] => self.matrix() * right; ); // Matrix × Rotation md_impl_all!( Mul, mul; (R1, C1), (Const, Const) const D2; for R1, C1, SA; where R1: Dim, C1: Dim, SA: Storage, DefaultAllocator: Allocator>, ShapeConstraint: AreMultipliable, Const>; self: Matrix, right: Rotation, Output = MatrixMN>; [val val] => self * right.into_inner(); [ref val] => self * right.into_inner(); [val ref] => self * right.matrix(); [ref ref] => self * right.matrix(); ); // Matrix ÷ Rotation md_impl_all!( Div, div; (R1, C1), (Const, Const) const D2; for R1, C1, SA; where R1: Dim, C1: Dim, SA: Storage, DefaultAllocator: Allocator>, ShapeConstraint: AreMultipliable, Const>; self: Matrix, right: Rotation, Output = MatrixMN>; [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() }; ); // Rotation × Point // TODO: we don't handle properly non-zero origins here. Do we want this to be the intended // behavior? md_impl_all!( Mul, mul; (Const, Const), (Const, U1) const D; for; where ShapeConstraint: AreMultipliable, Const, Const, U1>; self: Rotation, right: Point, Output = Point; [val val] => self.into_inner() * right; [ref val] => self.matrix() * right; [val ref] => self.into_inner() * right; [ref ref] => self.matrix() * right; ); // Rotation × Unit md_impl_all!( Mul, mul; (Const, Const), (Const, U1) const D; for S; where S: Storage>, ShapeConstraint: AreMultipliable, Const, Const, U1>; self: Rotation, right: Unit, S>>, Output = Unit>; [val val] => Unit::new_unchecked(self.into_inner() * right.into_inner()); [ref val] => Unit::new_unchecked(self.matrix() * right.into_inner()); [val ref] => Unit::new_unchecked(self.into_inner() * right.as_ref()); [ref ref] => Unit::new_unchecked(self.matrix() * right.as_ref()); ); // Rotation ×= Rotation // TODO: try not to call `inverse()` explicitly. md_assign_impl_all!( MulAssign, mul_assign; (Const, Const), (Const, Const) const D; for; where; self: Rotation, right: Rotation; [val] => self.matrix_mut_unchecked().mul_assign(right.into_inner()); [ref] => self.matrix_mut_unchecked().mul_assign(right.matrix()); ); md_assign_impl_all!( DivAssign, div_assign; (Const, Const), (Const, Const) const D; for; where; self: Rotation, right: Rotation; [val] => self.matrix_mut_unchecked().mul_assign(right.inverse().into_inner()); [ref] => self.matrix_mut_unchecked().mul_assign(right.inverse().matrix()); ); // Matrix *= Rotation // TODO: try not to call `inverse()` explicitly. // TODO: 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; (Const, Const), (Const, Const) const R1, C1; for; where; self: CMatrixMN, right: Rotation; [val] => self.mul_assign(right.into_inner()); [ref] => self.mul_assign(right.matrix()); ); md_assign_impl_all!( DivAssign, div_assign; (Const, Const), (Const, Const) const R1, C1; for; where; self: CMatrixMN, right: Rotation; [val] => self.mul_assign(right.inverse().into_inner()); [ref] => self.mul_assign(right.inverse().matrix()); );