1 // Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
11 #![feature(associated_types)]
22 impl ops::Add for Point {
25 fn add(self, other: Point) -> Point {
26 Point {x: self.x + other.x, y: self.y + other.y}
30 impl ops::Sub for Point {
33 fn sub(self, other: Point) -> Point {
34 Point {x: self.x - other.x, y: self.y - other.y}
38 impl ops::Neg<Point> for Point {
39 fn neg(self) -> Point {
40 Point {x: -self.x, y: -self.y}
44 impl ops::Not<Point> for Point {
45 fn not(self) -> Point {
46 Point {x: !self.x, y: !self.y }
50 impl ops::Index<bool,int> for Point {
51 fn index(&self, x: &bool) -> &int {
60 impl cmp::PartialEq for Point {
61 fn eq(&self, other: &Point) -> bool {
62 (*self).x == (*other).x && (*self).y == (*other).y
64 fn ne(&self, other: &Point) -> bool { !(*self).eq(other) }
68 let mut p = Point {x: 10, y: 20};
69 p = p + Point {x: 101, y: 102};
70 p = p - Point {x: 100, y: 100};
71 assert_eq!(p + Point {x: 5, y: 5}, Point {x: 16, y: 27});
72 assert_eq!(-p, Point {x: -11, y: -22});
73 assert_eq!(p[true], 11);
74 assert_eq!(p[false], 22);
77 assert_eq!(q.x, !(p.x));
78 assert_eq!(q.y, !(p.y));