summaryrefslogtreecommitdiff
path: root/src/engine/geometry.rs
blob: a946bf9b8533edd8769ef2d5e1632302c2b4329f (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
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct Point {
    pub x: u8,
    pub y: u8
}

impl Point {
    pub fn new(x: u8, y: u8) -> Point {
        Point { x, y }
    }
    pub fn move_left(&self) -> Option<Point> {
        self.x.checked_sub(1).map(|x| Point {
            x: x,
            ..*self
        })
    }
    pub fn move_right(&self, size: &Point) -> Option<Point> {
        if self.x + 1 >= size.x {
            None
        } else {
            Some(Point {
                x: self.x + 1,
                ..*self
            })
        }
    }
}