Skip to content

Commit

Permalink
Added AddAssign method on Point2D
Browse files Browse the repository at this point in the history
  • Loading branch information
eloycoto committed May 17, 2017
1 parent 2e146e2 commit d9a5d7a
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/point.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use size::TypedSize2D;
use num::*;
use num_traits::{Float, NumCast};
use std::fmt;
use std::ops::{Add, Neg, Mul, Sub, Div};
use std::ops::{Add, Neg, Mul, Sub, Div, AddAssign};
use std::marker::PhantomData;

define_matrix! {
Expand Down Expand Up @@ -129,6 +129,12 @@ impl<T: Copy + Add<T, Output=T>, U> Add for TypedPoint2D<T, U> {
}
}

impl<T: Copy + Add<T, Output=T>, U> AddAssign for TypedPoint2D<T, U> {
fn add_assign(&mut self, other: TypedPoint2D<T, U>){
*self = *self + other
}
}

impl<T: Copy + Add<T, Output=T>, U> Add<TypedSize2D<T, U>> for TypedPoint2D<T, U> {
type Output = TypedPoint2D<T, U>;
fn add(self, other: TypedSize2D<T, U>) -> TypedPoint2D<T, U> {
Expand Down Expand Up @@ -888,6 +894,14 @@ mod typedpoint2d {
assert_eq!(result, Point2DMm::new(4.0, 6.0));
}

#[test]
pub fn test_add_assign() {
let mut p1 = Point2DMm::new(1.0, 2.0);
p1 += Point2DMm::new(3.0, 4.0);

assert_eq!(p1, Point2DMm::new(4.0, 6.0));
}

#[test]
pub fn test_scalar_mul() {
let p1 = Point2DMm::new(1.0, 2.0);
Expand Down

0 comments on commit d9a5d7a

Please sign in to comment.