Skip to content

Instantly share code, notes, and snippets.

@calvinmetcalf
Last active December 22, 2015 07:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save calvinmetcalf/6438895 to your computer and use it in GitHub Desktop.
Save calvinmetcalf/6438895 to your computer and use it in GitHub Desktop.
//for example
//if pointA = Point {x:1.5,y:2.0}
//and pointB = Point {x:3.5,y:3.0}
impl Sub<Point, Point> for Point {
#[inline]
fn sub( &self, other: &Point ) -> Point { Point { x:self.x-other.x, y:self.y-other.y } }
}
//pointB - pointA = Point {x:2.0,y:1.0}
impl Add<Point, Point> for Point {
#[inline]
fn add( &self, other: &Point ) -> Point { Point { x:self.x+other.x, y:self.y+other.y } }
}
//pointA + pointB = Point {x:5.0,y:5.0}
impl Mul<Point, Point> for Point {
#[inline]
fn mul( &self, other: &Point ) -> Point { Point { x:self.x*other.x, y:self.y*other.y } }
}
//pointA * pointB = Point {x:5.25,y:6.0}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment