summaryrefslogtreecommitdiff
path: root/src/engine/geometry.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/engine/geometry.rs')
-rw-r--r--src/engine/geometry.rs24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/engine/geometry.rs b/src/engine/geometry.rs
new file mode 100644
index 0000000..f2a2522
--- /dev/null
+++ b/src/engine/geometry.rs
@@ -0,0 +1,24 @@
+#[derive(Debug, Clone, Copy, PartialEq, Eq)]
+pub struct Point {
+ pub x: u8,
+ pub y: u8
+}
+
+impl Point {
+ 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
+ })
+ }
+ }
+}