From 1e091769279592dac834536872d8c45733c9c73a Mon Sep 17 00:00:00 2001 From: Shane Madden Date: Sat, 17 Aug 2024 23:15:29 -0600 Subject: [PATCH] Use `u8` for `RoomXY` ranges (#526) --- CHANGELOG.md | 6 ++++++ src/local/room_xy/game_math.rs | 6 +++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ffd58da2..f4afec1e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,12 @@ Unreleased ========== +### Breaking: + +- Change return type of `RoomXY::get_range_to` and input type of `RoomXY::in_range_to` to u8 + +### Additions: + - Make `RoomName::from_packed` and `RoomName::packed_repr` public 0.21.3 (2024-08-14) diff --git a/src/local/room_xy/game_math.rs b/src/local/room_xy/game_math.rs index 46abcf1d..df19d2a4 100644 --- a/src/local/room_xy/game_math.rs +++ b/src/local/room_xy/game_math.rs @@ -58,9 +58,9 @@ impl RoomXY { /// ``` #[doc(alias = "distance")] #[inline] - pub fn get_range_to(self, target: RoomXY) -> u32 { + pub fn get_range_to(self, target: RoomXY) -> u8 { let (dx, dy) = self - target; - dx.abs().max(dy.abs()) as u32 + dx.unsigned_abs().max(dy.unsigned_abs()) } /// Checks whether this position is in the given range of another position. @@ -96,7 +96,7 @@ impl RoomXY { /// ``` #[doc(alias = "distance")] #[inline] - pub fn in_range_to(self, target: RoomXY, range: u32) -> bool { + pub fn in_range_to(self, target: RoomXY, range: u8) -> bool { self.get_range_to(target) <= range }