Skip to content

Commit

Permalink
refactor: rename 'pos' to 'position'
Browse files Browse the repository at this point in the history
  • Loading branch information
ShenMian committed Apr 10, 2024
1 parent b4dcf9a commit e8dacfd
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/level.rs
Expand Up @@ -122,7 +122,7 @@ impl Level {

/// Returns the reachable area for the player.
pub fn player_reachable_area(&self) -> HashSet<Vector2<i32>> {
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.
Expand Down
21 changes: 15 additions & 6 deletions src/map.rs
Expand Up @@ -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.
Expand Down Expand Up @@ -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::<HashSet<_>>()
{
Expand Down Expand Up @@ -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());
}

Expand All @@ -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();
}

Expand Down
2 changes: 1 addition & 1 deletion src/path_finding.rs
Expand Up @@ -103,7 +103,7 @@ pub fn player_move_path(map: &Map, to: Vector2<i32>) -> Option<Vec<Direction>> {
/// Converts a position path into a direction path.
fn convert_path_from_points_to_directions(path: Vec<Vector2<i32>>) -> Vec<Direction> {
path.windows(2)
.map(|pos| Direction::try_from(pos[1] - pos[0]).unwrap())
.map(|position| Direction::try_from(position[1] - position[0]).unwrap())
.collect()
}

Expand Down

0 comments on commit e8dacfd

Please sign in to comment.