Skip to content

Commit

Permalink
chore: fix clippy errors
Browse files Browse the repository at this point in the history
  • Loading branch information
CalliEve committed Jun 28, 2024
1 parent ce8a0f2 commit 7a9a5bb
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
6 changes: 3 additions & 3 deletions src/algorithm/a_star.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ struct AStarState {

impl AStarState {
/// Get the path that led to this state.
fn to_path(self) -> Vec<GridNode> {
fn to_path(&self) -> Vec<GridNode> {
let mut path = Vec::new();

let mut current = Box::new(self);
let mut current = Box::new(self.clone());
while let Some(state) = current.parent {
path.push(state.node);
current = state;
Expand Down Expand Up @@ -97,7 +97,7 @@ pub fn run_a_star(from: GridNode, to: GridNode) -> Vec<GridNode> {
for neighbor in node.get_neighbors() {
let next = AStarState {
path_length: path_length + 1,
cost: path_length as f64 + neighbor.diagonal_distance_to(to),
cost: f64::from(path_length) + neighbor.diagonal_distance_to(to),
node: neighbor,
parent: Some(Box::new(current.clone())),
};
Expand Down
10 changes: 5 additions & 5 deletions src/models/grid_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ impl GridNode {
}

/// Get the diagonal distance to a target node.
pub fn diagonal_distance_to(&self, target: GridNode) -> f64 {
let dx = (self.0 - target.0).abs() as f64;
let dy = (self.1 - target.1).abs() as f64;
pub fn diagonal_distance_to(self, target: GridNode) -> f64 {
let dx = (self.0 - target.0).abs();
let dy = (self.1 - target.1).abs();

(dx + dy) - (2f64.sqrt() - 2.0) * dx.min(dy)
f64::from(dx + dy) - (2f64.sqrt() - 2.0) * f64::from(dx.min(dy))
}

/// Get a list of all the neighbors of this grid node.
pub fn get_neighbors(&self) -> Vec<GridNode> {
pub fn get_neighbors(self) -> Vec<GridNode> {
vec![
Self(self.0 - 1, self.1 - 1),
Self(self.0, self.1 - 1),
Expand Down

0 comments on commit 7a9a5bb

Please sign in to comment.