/* * This file provides: * * NOTE: Work in progress https://github.com/dimforge/nalgebra/issues/487 * * (Dual Quaternion) * * Index * IndexMut * * (Assignment Operators) * * DualQuaternion × Scalar * DualQuaternion × DualQuaternion * DualQuaternion + DualQuaternion * DualQuaternion - DualQuaternion * * --- * * References: * Multiplication: * - https://cs.gmu.edu/~jmlien/teaching/cs451/uploads/Main/dual-quaternion.pdf */ use crate::{DualQuaternion, SimdRealField}; use std::mem; use std::ops::{Add, Index, IndexMut, Mul, Sub}; impl AsRef<[N; 8]> for DualQuaternion { #[inline] fn as_ref(&self) -> &[N; 8] { unsafe { mem::transmute(self) } } } impl AsMut<[N; 8]> for DualQuaternion { #[inline] fn as_mut(&mut self) -> &mut [N; 8] { unsafe { mem::transmute(self) } } } impl Index for DualQuaternion { type Output = N; #[inline] fn index(&self, i: usize) -> &Self::Output { &self.as_ref()[i] } } impl IndexMut for DualQuaternion { #[inline] fn index_mut(&mut self, i: usize) -> &mut N { &mut self.as_mut()[i] } } impl Mul> for DualQuaternion where N::Element: SimdRealField, { type Output = DualQuaternion; fn mul(self, rhs: Self) -> Self::Output { Self::from_real_and_dual( self.real * rhs.real, self.real * rhs.dual + self.dual * rhs.real, ) } } impl Mul for DualQuaternion where N::Element: SimdRealField, { type Output = DualQuaternion; fn mul(self, rhs: N) -> Self::Output { Self::from_real_and_dual(self.real * rhs, self.dual * rhs) } } impl Add> for DualQuaternion where N::Element: SimdRealField, { type Output = DualQuaternion; fn add(self, rhs: DualQuaternion) -> Self::Output { Self::from_real_and_dual(self.real + rhs.real, self.dual + rhs.dual) } } impl Sub> for DualQuaternion where N::Element: SimdRealField, { type Output = DualQuaternion; fn sub(self, rhs: DualQuaternion) -> Self::Output { Self::from_real_and_dual(self.real - rhs.real, self.dual - rhs.dual) } }