add new operators

This commit is contained in:
Terence 2021-01-28 19:27:40 -05:00
parent ecda74f6b2
commit ac92e68486
2 changed files with 222 additions and 65 deletions

View File

@ -242,6 +242,66 @@ dual_quaternion_op_impl!(
self: DualQuaternion<N>, rhs: DualQuaternion<N>, Output = DualQuaternion<N>; self: DualQuaternion<N>, rhs: DualQuaternion<N>, Output = DualQuaternion<N>;
&self * &rhs; ); &self * &rhs; );
// DualQuaternion × UnitDualQuaternion
dual_quaternion_op_impl!(
Mul, mul;
(U4, U1), (U4, U1);
self: &'a DualQuaternion<N>, rhs: &'b UnitDualQuaternion<N>, Output = DualQuaternion<N>;
self * rhs.dual_quaternion();
'a, 'b);
dual_quaternion_op_impl!(
Mul, mul;
(U4, U1), (U4, U1);
self: &'a DualQuaternion<N>, rhs: UnitDualQuaternion<N>, Output = DualQuaternion<N>;
self * rhs.dual_quaternion();
'a);
dual_quaternion_op_impl!(
Mul, mul;
(U4, U1), (U4, U1);
self: DualQuaternion<N>, rhs: &'b UnitDualQuaternion<N>, Output = DualQuaternion<N>;
self * rhs.dual_quaternion();
'b);
dual_quaternion_op_impl!(
Mul, mul;
(U4, U1), (U4, U1);
self: DualQuaternion<N>, rhs: UnitDualQuaternion<N>, Output = DualQuaternion<N>;
self * rhs.dual_quaternion(););
// DualQuaternion ÷ UnitDualQuaternion
dual_quaternion_op_impl!(
Div, div;
(U4, U1), (U4, U1);
self: &'a DualQuaternion<N>, rhs: &'b UnitDualQuaternion<N>, Output = DualQuaternion<N>;
#[allow(clippy::suspicious_arithmetic_impl)]
{ self * rhs.inverse().dual_quaternion() };
'a, 'b);
dual_quaternion_op_impl!(
Div, div;
(U4, U1), (U4, U1);
self: &'a DualQuaternion<N>, rhs: UnitDualQuaternion<N>, Output = DualQuaternion<N>;
#[allow(clippy::suspicious_arithmetic_impl)]
{ self * rhs.inverse().dual_quaternion() };
'a);
dual_quaternion_op_impl!(
Div, div;
(U4, U1), (U4, U1);
self: DualQuaternion<N>, rhs: &'b UnitDualQuaternion<N>, Output = DualQuaternion<N>;
#[allow(clippy::suspicious_arithmetic_impl)]
{ self * rhs.inverse().dual_quaternion() };
'b);
dual_quaternion_op_impl!(
Div, div;
(U4, U1), (U4, U1);
self: DualQuaternion<N>, rhs: UnitDualQuaternion<N>, Output = DualQuaternion<N>;
#[allow(clippy::suspicious_arithmetic_impl)]
{ self * rhs.inverse().dual_quaternion() };);
// UnitDualQuaternion × UnitDualQuaternion // UnitDualQuaternion × UnitDualQuaternion
dual_quaternion_op_impl!( dual_quaternion_op_impl!(
Mul, mul; Mul, mul;
@ -298,6 +358,38 @@ dual_quaternion_op_impl!(
self: UnitDualQuaternion<N>, rhs: UnitDualQuaternion<N>, Output = UnitDualQuaternion<N>; self: UnitDualQuaternion<N>, rhs: UnitDualQuaternion<N>, Output = UnitDualQuaternion<N>;
&self / &rhs; ); &self / &rhs; );
// UnitDualQuaternion × DualQuaternion
dual_quaternion_op_impl!(
Mul, mul;
(U4, U1), (U4, U1);
self: &'a UnitDualQuaternion<N>, rhs: &'b DualQuaternion<N>,
Output = DualQuaternion<N> => U1, U4;
self.dual_quaternion() * rhs;
'a, 'b);
dual_quaternion_op_impl!(
Mul, mul;
(U4, U1), (U4, U1);
self: &'a UnitDualQuaternion<N>, rhs: DualQuaternion<N>,
Output = DualQuaternion<N> => U3, U3;
self.dual_quaternion() * rhs;
'a);
dual_quaternion_op_impl!(
Mul, mul;
(U4, U1), (U4, U1);
self: UnitDualQuaternion<N>, rhs: &'b DualQuaternion<N>,
Output = DualQuaternion<N> => U3, U3;
self.dual_quaternion() * rhs;
'b);
dual_quaternion_op_impl!(
Mul, mul;
(U4, U1), (U4, U1);
self: UnitDualQuaternion<N>, rhs: DualQuaternion<N>,
Output = DualQuaternion<N> => U3, U3;
self.dual_quaternion() * rhs;);
// UnitDualQuaternion × UnitQuaternion // UnitDualQuaternion × UnitQuaternion
dual_quaternion_op_impl!( dual_quaternion_op_impl!(
Mul, mul; Mul, mul;
@ -917,8 +1009,44 @@ dual_quaternion_op_impl!(
MulAssign, mul_assign; MulAssign, mul_assign;
(U4, U1), (U4, U1); (U4, U1), (U4, U1);
self: DualQuaternion<N>, rhs: DualQuaternion<N>; self: DualQuaternion<N>, rhs: DualQuaternion<N>;
*self *= &rhs;);
// DualQuaternion ×= UnitDualQuaternion
dual_quaternion_op_impl!(
MulAssign, mul_assign;
(U4, U1), (U4, U1);
self: DualQuaternion<N>, rhs: &'b UnitDualQuaternion<N>;
{
let res = &*self * rhs;
self.real.coords.copy_from(&res.real.coords);
self.dual.coords.copy_from(&res.dual.coords);
};
'b);
dual_quaternion_op_impl!(
MulAssign, mul_assign;
(U4, U1), (U4, U1);
self: DualQuaternion<N>, rhs: UnitDualQuaternion<N>;
*self *= &rhs; ); *self *= &rhs; );
// DualQuaternion ÷= UnitDualQuaternion
dual_quaternion_op_impl!(
DivAssign, div_assign;
(U4, U1), (U4, U1);
self: DualQuaternion<N>, rhs: &'b UnitDualQuaternion<N>;
{
let res = &*self / rhs;
self.real.coords.copy_from(&res.real.coords);
self.dual.coords.copy_from(&res.dual.coords);
};
'b);
dual_quaternion_op_impl!(
DivAssign, div_assign;
(U4, U1), (U4, U1);
self: DualQuaternion<N>, rhs: UnitDualQuaternion<N>;
*self /= &rhs; );
// UnitDualQuaternion ×= UnitDualQuaternion // UnitDualQuaternion ×= UnitDualQuaternion
dual_quaternion_op_impl!( dual_quaternion_op_impl!(
MulAssign, mul_assign; MulAssign, mul_assign;

View File

@ -1,7 +1,7 @@
#![cfg(feature = "arbitrary")] #![cfg(feature = "arbitrary")]
#![allow(non_snake_case)] #![allow(non_snake_case)]
use na::{Isometry3, Point3, Translation3, UnitDualQuaternion, UnitQuaternion, Vector3}; use na::{DualQuaternion, Isometry3, Point3, Translation3, UnitDualQuaternion, UnitQuaternion, Vector3};
quickcheck!( quickcheck!(
fn isometry_equivalence(iso: Isometry3<f64>, p: Point3<f64>, v: Vector3<f64>) -> bool { fn isometry_equivalence(iso: Isometry3<f64>, p: Point3<f64>, v: Vector3<f64>) -> bool {
@ -68,61 +68,86 @@ quickcheck!(
#[cfg_attr(rustfmt, rustfmt_skip)] #[cfg_attr(rustfmt, rustfmt_skip)]
fn all_op_exist( fn all_op_exist(
dq: UnitDualQuaternion<f64>, dq: DualQuaternion<f64>,
udq: UnitDualQuaternion<f64>,
uq: UnitQuaternion<f64>, uq: UnitQuaternion<f64>,
s: f64,
t: Translation3<f64>, t: Translation3<f64>,
v: Vector3<f64>, v: Vector3<f64>,
p: Point3<f64> p: Point3<f64>
) -> bool { ) -> bool {
let iMi = dq * dq; let dqMs: DualQuaternion<_> = dq * s;
let iMuq = dq * uq;
let iDi = dq / dq;
let iDuq = dq / uq;
let iMp = dq * p; let dqMdq: DualQuaternion<_> = dq * dq;
let iMv = dq * v; let dqMudq: DualQuaternion<_> = dq * udq;
let udqMdq: DualQuaternion<_> = udq * dq;
let iMt = dq * t; let iMi: UnitDualQuaternion<_> = udq * udq;
let tMi = t * dq; let iMuq: UnitDualQuaternion<_> = udq * uq;
let iDi: UnitDualQuaternion<_> = udq / udq;
let iDuq: UnitDualQuaternion<_> = udq / uq;
let tMuq = t * uq; let iMp: Point3<_> = udq * p;
let iMv: Vector3<_> = udq * v;
let uqMi = uq * dq; let iMt: UnitDualQuaternion<_> = udq * t;
let uqDi = uq / dq; let tMi: UnitDualQuaternion<_> = t * udq;
let uqMt = uq * t; let uqMi: UnitDualQuaternion<_> = uq * udq;
let uqDi: UnitDualQuaternion<_> = uq / udq;
let mut iMt1 = dq; let mut dqMs1 = dq;
let mut iMt2 = dq;
let mut iMi1 = dq; let mut dqMdq1 = dq;
let mut iMi2 = dq; let mut dqMdq2 = dq;
let mut iMuq1 = dq; let mut dqMudq1 = dq;
let mut iMuq2 = dq; let mut dqMudq2 = dq;
let mut iDi1 = dq; let mut iMt1 = udq;
let mut iDi2 = dq; let mut iMt2 = udq;
let mut iDuq1 = dq; let mut iMi1 = udq;
let mut iDuq2 = dq; let mut iMi2 = udq;
let mut iMuq1 = udq;
let mut iMuq2 = udq;
let mut iDi1 = udq;
let mut iDi2 = udq;
let mut iDuq1 = udq;
let mut iDuq2 = udq;
dqMs1 *= s;
dqMdq1 *= dq;
dqMdq2 *= &dq;
dqMudq1 *= udq;
dqMudq2 *= &udq;
iMt1 *= t; iMt1 *= t;
iMt2 *= &t; iMt2 *= &t;
iMi1 *= dq; iMi1 *= udq;
iMi2 *= &dq; iMi2 *= &udq;
iMuq1 *= uq; iMuq1 *= uq;
iMuq2 *= &uq; iMuq2 *= &uq;
iDi1 /= dq; iDi1 /= udq;
iDi2 /= &dq; iDi2 /= &udq;
iDuq1 /= uq; iDuq1 /= uq;
iDuq2 /= &uq; iDuq2 /= &uq;
iMt == iMt1 dqMs == dqMs1
&& dqMdq == dqMdq1
&& dqMdq == dqMdq2
&& dqMudq == dqMudq1
&& dqMudq == dqMudq2
&& iMt == iMt1
&& iMt == iMt2 && iMt == iMt2
&& iMi == iMi1 && iMi == iMi1
&& iMi == iMi2 && iMi == iMi2
@ -132,41 +157,45 @@ quickcheck!(
&& iDi == iDi2 && iDi == iDi2
&& iDuq == iDuq1 && iDuq == iDuq1
&& iDuq == iDuq2 && iDuq == iDuq2
&& iMi == &dq * &dq && dqMs == &dq * s
&& iMi == dq * &dq && dqMdq == &dq * &dq
&& iMi == &dq * dq && dqMdq == dq * &dq
&& iMuq == &dq * &uq && dqMdq == &dq * dq
&& iMuq == dq * &uq && dqMudq == &dq * &udq
&& iMuq == &dq * uq && dqMudq == dq * &udq
&& iDi == &dq / &dq && dqMudq == &dq * udq
&& iDi == dq / &dq && udqMdq == &udq * &dq
&& iDi == &dq / dq && udqMdq == udq * &dq
&& iDuq == &dq / &uq && udqMdq == &udq * dq
&& iDuq == dq / &uq && iMi == &udq * &udq
&& iDuq == &dq / uq && iMi == udq * &udq
&& iMp == &dq * &p && iMi == &udq * udq
&& iMp == dq * &p && iMuq == &udq * &uq
&& iMp == &dq * p && iMuq == udq * &uq
&& iMv == &dq * &v && iMuq == &udq * uq
&& iMv == dq * &v && iDi == &udq / &udq
&& iMv == &dq * v && iDi == udq / &udq
&& iMt == &dq * &t && iDi == &udq / udq
&& iMt == dq * &t && iDuq == &udq / &uq
&& iMt == &dq * t && iDuq == udq / &uq
&& tMi == &t * &dq && iDuq == &udq / uq
&& tMi == t * &dq && iMp == &udq * &p
&& tMi == &t * dq && iMp == udq * &p
&& tMuq == &t * &uq && iMp == &udq * p
&& tMuq == t * &uq && iMv == &udq * &v
&& tMuq == &t * uq && iMv == udq * &v
&& uqMi == &uq * &dq && iMv == &udq * v
&& uqMi == uq * &dq && iMt == &udq * &t
&& uqMi == &uq * dq && iMt == udq * &t
&& uqDi == &uq / &dq && iMt == &udq * t
&& uqDi == uq / &dq && tMi == &t * &udq
&& uqDi == &uq / dq && tMi == t * &udq
&& uqMt == &uq * &t && tMi == &t * udq
&& uqMt == uq * &t && uqMi == &uq * &udq
&& uqMt == &uq * t && uqMi == uq * &udq
&& uqMi == &uq * udq
&& uqDi == &uq / &udq
&& uqDi == uq / &udq
&& uqDi == &uq / udq
} }
); );