Skip to content
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