summaryrefslogtreecommitdiff
path: root/dungeon/src/pos.rs
diff options
context:
space:
mode:
authorFreya Murphy <freya@freyacat.org>2025-11-08 17:25:14 -0500
committerFreya Murphy <freya@freyacat.org>2025-11-08 17:25:45 -0500
commit881dfce05e07ac55d973988da08fc1670e1cd5ea (patch)
tree0f972d7e46c92f6496e90db27f231d4e3f3b18f1 /dungeon/src/pos.rs
parentgraphics: refactor debug ui (diff)
downloadDungeonCrawl-881dfce05e07ac55d973988da08fc1670e1cd5ea.tar.gz
DungeonCrawl-881dfce05e07ac55d973988da08fc1670e1cd5ea.tar.bz2
DungeonCrawl-881dfce05e07ac55d973988da08fc1670e1cd5ea.zip
dungeon: refactor astar to not be generic
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)))