summaryrefslogtreecommitdiff
path: root/src/math.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/math.rs')
-rw-r--r--src/math.rs20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/math.rs b/src/math.rs
index ce9d885..da06622 100644
--- a/src/math.rs
+++ b/src/math.rs
@@ -131,4 +131,24 @@ impl Point {
(dx == 1 && dy == 0)
}
+
+ pub fn is_on_lattice(&self, lattice_size: u16) -> bool {
+ (self.x + self.y) % lattice_size == 0
+ }
+}
+
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ #[test]
+ fn point_on_lattice_works() {
+ assert_eq!(true, Point::new(0,0).is_on_lattice(4));
+ assert_eq!(true, Point::new(4,0).is_on_lattice(4));
+ assert_eq!(true, Point::new(0,4).is_on_lattice(4));
+ assert_eq!(true, Point::new(4,4).is_on_lattice(4));
+ assert_eq!(true, Point::new(1,3).is_on_lattice(4));
+ assert_eq!(true, Point::new(3,1).is_on_lattice(4));
+ }
}