summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--dungeon/src/pos.rs60
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.