summaryrefslogtreecommitdiff
path: root/src/location.rs
blob: 4a98ef62a32cf1bb3ad2a5cd9b14d92247da20a3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
use std::cmp;

pub struct Location {
    pub x : i32, 
    pub y : i32
}

impl Copy for Location {}
impl Clone for Location {
    fn clone(&self) -> Location {
        *self
    }
}

impl cmp::PartialEq for Location {
    fn eq(&self, rhs : &Location) -> bool {
        if self.x == rhs.x && self.y == rhs.y {
            true
        }
        else {
            false
        }
    }
}

impl Location {
    pub fn up(self) -> Location {
        Location{ x : self.x, y : self.y + 1 }
    }
    pub fn upleft(self) -> Location {
        Location{ x : self.x - 1, y : self.y + 1 }
    }
    pub fn upright(self) -> Location {
        Location{ x : self.x + 1, y : self.y + 1 }
    }
    pub fn down(self) -> Location {
        Location{ x : self.x, y : self.y - 1 }
    }
    pub fn downleft(self) -> Location {
        Location{ x : self.x - 1, y : self.y - 1 }
    }
    pub fn downright(self) -> Location {
        Location{ x : self.x + 1, y : self.y - 1 }
    }
    pub fn right(self) -> Location {
        Location{ x : self.x + 1, y : self.y }
    }
    pub fn left(self) -> Location {
        Location{ x : self.x - 1, y : self.y }
    }
}