Skip to content

Commit

Permalink
Dual quat add/subtract
Browse files Browse the repository at this point in the history
  • Loading branch information
chinedufn committed Dec 17, 2020
1 parent 0498ee9 commit cbab6de
Showing 1 changed file with 33 additions and 1 deletion.
34 changes: 33 additions & 1 deletion src/geometry/dual_quaternion_ops.rs
Expand Up @@ -7,6 +7,8 @@
*
* DualQuaternion × Scalar
* DualQuaternion × DualQuaternion
* DualQuaternion + DualQuaternion
* DualQuaternion - DualQuaternion
*
* ---
*
Expand All @@ -18,7 +20,7 @@
use crate::base::allocator::Allocator;
use crate::{DefaultAllocator, DualQuaternion, Scalar, SimdRealField, U1, U4};
use simba::simd::SimdValue;
use std::ops::Mul;
use std::ops::{Add, Mul, Sub};

impl<N: Scalar + SimdValue + SimdRealField> Mul<DualQuaternion<N>> for DualQuaternion<N>
where
Expand Down Expand Up @@ -49,3 +51,33 @@ where
}
}
}

impl<N: Scalar + SimdValue + SimdRealField> Add<DualQuaternion<N>> for DualQuaternion<N>
where
N::Element: Scalar + SimdValue + SimdRealField,
DefaultAllocator: Allocator<N, U4, U1> + Allocator<N, U4, U1>,
{
type Output = DualQuaternion<N>;

fn add(self, rhs: DualQuaternion<N>) -> Self::Output {
Self {
rot: self.rot + rhs.rot,
trans: self.trans + rhs.trans,
}
}
}

impl<N: Scalar + SimdValue + SimdRealField> Sub<DualQuaternion<N>> for DualQuaternion<N>
where
N::Element: Scalar + SimdValue + SimdRealField,
DefaultAllocator: Allocator<N, U4, U1> + Allocator<N, U4, U1>,
{
type Output = DualQuaternion<N>;

fn sub(self, rhs: DualQuaternion<N>) -> Self::Output {
Self {
rot: self.rot - rhs.rot,
trans: self.trans - rhs.trans,
}
}
}

0 comments on commit cbab6de

Please sign in to comment.