Skip to content

Added AddAssign method on Point2D #192

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 18, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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