From d9a5d7a578b4f1d01a91f295cd43e3c503b41cb0 Mon Sep 17 00:00:00 2001 From: Eloy Coto Date: Wed, 17 May 2017 18:51:21 +0100 Subject: [PATCH] Added AddAssign method on Point2D --- src/point.rs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/point.rs b/src/point.rs index 8e6986a4..4503c56a 100644 --- a/src/point.rs +++ b/src/point.rs @@ -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! { @@ -129,6 +129,12 @@ impl, U> Add for TypedPoint2D { } } +impl, U> AddAssign for TypedPoint2D { + fn add_assign(&mut self, other: TypedPoint2D){ + *self = *self + other + } +} + impl, U> Add> for TypedPoint2D { type Output = TypedPoint2D; fn add(self, other: TypedSize2D) -> TypedPoint2D { @@ -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);