summaryrefslogtreecommitdiff
path: root/dungeon/src/pos.rs
diff options
context:
space:
mode:
Diffstat (limited to 'dungeon/src/pos.rs')
-rw-r--r--dungeon/src/pos.rs6
1 files changed, 6 insertions, 0 deletions
diff --git a/dungeon/src/pos.rs b/dungeon/src/pos.rs
index d31ba95..ac2d6d0 100644
--- a/dungeon/src/pos.rs
+++ b/dungeon/src/pos.rs
@@ -314,6 +314,7 @@ impl Pos {
Self(x, y)
}
+ /// Returns the manhattan distance between `self` and `other`
pub fn manhattan(self, other: Self) -> u16 {
let abs_diff = Self::abs_diff(self, other);
abs_diff.0 + abs_diff.1
@@ -343,6 +344,11 @@ impl Pos {
self.0 == 0 || self.0 == MAP_SIZE - 1 || self.1 == 0 || self.1 == MAP_SIZE - 1
}
+ /// Returns the cardinal neighbors of this positions
+ pub fn neighbors(&self) -> impl Iterator<Item = Self> {
+ Direction::values().filter_map(|dir| self.step(dir))
+ }
+
/// Returns an iterator over all possible `Pos`
pub fn values() -> impl Iterator<Item = Self> {
(0..MAP_SIZE).flat_map(|y| (0..MAP_SIZE).filter_map(move |x| Self::new(x, y)))