From e8dacfd2c093616caa8f6071e456d9f92a39ffb2 Mon Sep 17 00:00:00 2001 From: ShenMian Date: Wed, 10 Apr 2024 15:49:18 +0800 Subject: [PATCH] refactor: rename 'pos' to 'position' --- src/level.rs | 2 +- src/map.rs | 21 +++++++++++++++------ src/path_finding.rs | 2 +- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/level.rs b/src/level.rs index 1c6f220..5a7f77b 100644 --- a/src/level.rs +++ b/src/level.rs @@ -122,7 +122,7 @@ impl Level { /// Returns the reachable area for the player. pub fn player_reachable_area(&self) -> HashSet> { - reachable_area(self.player_position(), |pos| self.can_move(pos)) + reachable_area(self.player_position(), |position| self.can_move(position)) } /// Loads levels from XSB format string. diff --git a/src/map.rs b/src/map.rs index d6de1ce..3315771 100644 --- a/src/map.rs +++ b/src/map.rs @@ -242,8 +242,16 @@ impl Map { self.dimensions = clamped_map.dimensions; self.player_position -= offset; - self.box_positions = self.box_positions.iter().map(|pos| pos - offset).collect(); - self.goal_positions = self.goal_positions.iter().map(|pos| pos - offset).collect(); + self.box_positions = self + .box_positions + .iter() + .map(|position| position - offset) + .collect(); + self.goal_positions = self + .goal_positions + .iter() + .map(|position| position - offset) + .collect(); } /// Returns tiles at the specified position or `None` if out of bounds. @@ -394,7 +402,7 @@ impl Map { for position in self .box_positions .iter() - .filter(|pos| !self[**pos].intersects(Tiles::Floor)) + .filter(|position| !self[**position].intersects(Tiles::Floor)) .cloned() .collect::>() { @@ -430,7 +438,8 @@ impl Map { /// Normalizes the position of the player on the map. fn normalize_player_position(&mut self) { - let player_reachable_area = reachable_area(self.player_position, |pos| self.can_move(pos)); + let player_reachable_area = + reachable_area(self.player_position, |position| self.can_move(position)); self.set_player_position(normalized_area(&player_reachable_area).unwrap()); } @@ -454,12 +463,12 @@ impl Map { self.box_positions = self .box_positions .iter() - .map(|pos| operation(*pos)) + .map(|position| operation(*position)) .collect(); self.goal_positions = self .goal_positions .iter() - .map(|pos| operation(*pos)) + .map(|position| operation(*position)) .collect(); } diff --git a/src/path_finding.rs b/src/path_finding.rs index fd9dfa6..fa6a278 100644 --- a/src/path_finding.rs +++ b/src/path_finding.rs @@ -103,7 +103,7 @@ pub fn player_move_path(map: &Map, to: Vector2) -> Option> { /// Converts a position path into a direction path. fn convert_path_from_points_to_directions(path: Vec>) -> Vec { path.windows(2) - .map(|pos| Direction::try_from(pos[1] - pos[0]).unwrap()) + .map(|position| Direction::try_from(position[1] - position[0]).unwrap()) .collect() }