diff options
| author | Freya Murphy <freya@freyacat.org> | 2025-10-23 22:45:03 -0400 |
|---|---|---|
| committer | Freya Murphy <freya@freyacat.org> | 2025-10-23 22:45:03 -0400 |
| commit | 444a2ca59f38b784b50a05076f3bf7ac99596b11 (patch) | |
| tree | 39da2acf26187ccbc90b20843e6e8c09765ec6e6 /dungeon | |
| parent | dungon: supress wfc clippy warnings (for now) (diff) | |
| download | DungeonCrawl-444a2ca59f38b784b50a05076f3bf7ac99596b11.tar.gz DungeonCrawl-444a2ca59f38b784b50a05076f3bf7ac99596b11.tar.bz2 DungeonCrawl-444a2ca59f38b784b50a05076f3bf7ac99596b11.zip | |
dungeon: add x,y getters for Pos and FPos
Diffstat (limited to 'dungeon')
| -rw-r--r-- | dungeon/src/pos.rs | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/dungeon/src/pos.rs b/dungeon/src/pos.rs index 27d9b8f..e2d449c 100644 --- a/dungeon/src/pos.rs +++ b/dungeon/src/pos.rs @@ -117,6 +117,36 @@ impl Pos { (self.0, self.1) } + /// Returns the x component of `Pos` + /// + /// # Examples + /// + /// ``` + /// use dungeon::Pos; + /// + /// let pos = Pos::new(5,7).unwrap(); + /// assert_eq!(pos.x(), 5); + /// ``` + #[must_use] + pub const fn x(&self) -> u16 { + self.0 + } + + /// Returns the y component of `Pos` + /// + /// # Examples + /// + /// ``` + /// use dungeon::Pos; + /// + /// let pos = Pos::new(5,7).unwrap(); + /// assert_eq!(pos.y(), 7); + /// ``` + #[must_use] + pub const fn y(&self) -> u16 { + self.1 + } + /// Converts the x and y positions into an index of a continous list. /// /// # Examples @@ -329,6 +359,36 @@ impl FPos { (self.0, self.1) } + /// Returns the x component of `FPos` + /// + /// # Examples + /// + /// ``` + /// use dungeon::FPos; + /// + /// let fpos = FPos::new(5.0,7.2); + /// assert_eq!(fpos.x(), 5.0); + /// ``` + #[must_use] + pub const fn x(&self) -> f32 { + self.0 + } + + /// Returns the y component of `FPos` + /// + /// # Examples + /// + /// ``` + /// use dungeon::FPos; + /// + /// let fpos = FPos::new(5.0,7.2); + /// assert_eq!(fpos.y(), 7.2); + /// ``` + #[must_use] + pub const fn y(&self) -> f32 { + self.1 + } + /// Steps `FPos` a given floating amount in the `Direction` `dir`. /// /// Returns `None` if the floating position wraps. |