Merge pull request #426 from Osspial/point_ops

Add vector subtraction for all points
This commit is contained in:
Brendan Zabarauskas 2017-10-23 23:11:41 +11:00 committed by GitHub
commit 43a6b2be8c
2 changed files with 7 additions and 0 deletions

View file

@ -222,9 +222,15 @@ macro_rules! impl_point {
impl_operator!(<S: BaseNum> Add<$VectorN<S> > for $PointN<S> { impl_operator!(<S: BaseNum> Add<$VectorN<S> > for $PointN<S> {
fn add(lhs, rhs) -> $PointN<S> { $PointN::new($(lhs.$field + rhs.$field),+) } fn add(lhs, rhs) -> $PointN<S> { $PointN::new($(lhs.$field + rhs.$field),+) }
}); });
impl_operator!(<S: BaseNum> Sub<$VectorN<S>> for $PointN<S> {
fn sub(lhs, rhs) -> $PointN<S> { $PointN::new($(lhs.$field - rhs.$field),+) }
});
impl_assignment_operator!(<S: BaseNum> AddAssign<$VectorN<S> > for $PointN<S> { impl_assignment_operator!(<S: BaseNum> AddAssign<$VectorN<S> > for $PointN<S> {
fn add_assign(&mut self, vector) { $(self.$field += vector.$field);+ } fn add_assign(&mut self, vector) { $(self.$field += vector.$field);+ }
}); });
impl_assignment_operator!(<S: BaseNum> SubAssign<$VectorN<S>> for $PointN<S> {
fn sub_assign(&mut self, vector) { $(self.$field -= vector.$field);+ }
});
impl_operator!(<S: BaseNum> Sub<$PointN<S> > for $PointN<S> { impl_operator!(<S: BaseNum> Sub<$PointN<S> > for $PointN<S> {
fn sub(lhs, rhs) -> $VectorN<S> { $VectorN::new($(lhs.$field - rhs.$field),+) } fn sub(lhs, rhs) -> $VectorN<S> { $VectorN::new($(lhs.$field - rhs.$field),+) }

View file

@ -319,6 +319,7 @@ pub trait EuclideanSpace: Copy + Clone where
Self: Array<Element = <Self as EuclideanSpace>::Scalar>, Self: Array<Element = <Self as EuclideanSpace>::Scalar>,
Self: Add<<Self as EuclideanSpace>::Diff, Output = Self>, Self: Add<<Self as EuclideanSpace>::Diff, Output = Self>,
Self: Sub<<Self as EuclideanSpace>::Diff, Output = Self>,
Self: Sub<Self, Output = <Self as EuclideanSpace>::Diff>, Self: Sub<Self, Output = <Self as EuclideanSpace>::Diff>,
Self: Mul<<Self as EuclideanSpace>::Scalar, Output = Self>, Self: Mul<<Self as EuclideanSpace>::Scalar, Output = Self>,