Skip to content

Commit

Permalink
cargo fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
DrInfy committed Nov 15, 2020
1 parent 366d2b4 commit aaf42ac
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 30 deletions.
8 changes: 3 additions & 5 deletions benches/common.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use std::io::{BufReader, BufRead};
use std::fs::File;
use sc2pathlib::path_find;

use std::fs::File;
use std::io::{BufRead, BufReader};

fn rot90(vec: Vec<Vec<usize>>) -> Vec<Vec<usize>> {
let len = vec[0].len();
Expand All @@ -19,7 +18,6 @@ fn rot90(vec: Vec<Vec<usize>>) -> Vec<Vec<usize>> {
new_arr
}


fn read_vec_from_file(file_path: &str) -> Vec<Vec<usize>> {
let f = BufReader::new(File::open(file_path).unwrap());
let mut arr = Vec::<Vec<usize>>::new();
Expand All @@ -38,4 +36,4 @@ fn read_vec_from_file(file_path: &str) -> Vec<Vec<usize>> {
pub fn get_pathfind(file: &str) -> path_find::PathFind {
let map = read_vec_from_file(file);
path_find::PathFind::new_internal(map)
}
}
26 changes: 13 additions & 13 deletions benches/path_benchmark.rs
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
use criterion::{black_box, criterion_group, criterion_main, Criterion};
use common::get_pathfind;
use criterion::{black_box, criterion_group, criterion_main, Criterion};
mod common;

fn bench_astar_automaton(c: &mut Criterion) {
let path_find = get_pathfind("tests/AutomatonLE.txt");
c.bench_function("find_path_automaton", |b| {
b.iter(|| {
path_find.find_path((32, 51), (150, 118), Some(0));
})
});
b.iter(|| {
path_find.find_path((32, 51), (150, 118), Some(0));
})
});
}

fn bench_astar_4x4(c: &mut Criterion) {
let path_find = get_pathfind("tests/maze4x4.txt");
// Run bench
c.bench_function("find_path_4x4", |b| {
b.iter(|| {
path_find.find_path((0, 0), (0, 2), Some(0));
})
});
b.iter(|| {
path_find.find_path((0, 0), (0, 2), Some(0));
})
});
}


fn bench_astar_10x10(c: &mut Criterion) {
let path_find = get_pathfind("tests/empty10x10.txt");
// Run bench
c.bench_function("find_path_10x10", |b| {
b.iter(|| {
path_find.find_path((0, 0), (8, 9), Some(0));
})});
b.iter(|| {
path_find.find_path((0, 0), (8, 9), Some(0));
})
});
}

criterion_group!(benches, bench_astar_automaton, bench_astar_4x4, bench_astar_10x10);
Expand Down
4 changes: 2 additions & 2 deletions src/mapping/influence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ impl Map {
min: f32,
max: f32) {
let mult = 1.0 / pos::MULTF32;
let mult2 = 1.0 / (max - min) ;
let mult2 = 1.0 / (max - min);
let value = influence as usize;
let mult_min = min * pos::MULTF32;
let mult_max = max * pos::MULTF32;
Expand Down Expand Up @@ -130,7 +130,7 @@ impl Map {
let value_fading = (influence * (1.0 - (d * mult - min) * mult2)) as usize;
for mapping in maps.iter_mut() {
let old_val = mapping.map[x][y];
if old_val > 0 && value_fading > 0{
if old_val > 0 && value_fading > 0 {
mapping.map[x][y] = old_val + value_fading;
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/path_find/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ impl PathFind {
let rect = rectangle::Rectangle::init_from_center2(position, rect_size, self.width, self.height);

for x in rect.x..rect.x_end {
for y in rect.y..rect.y_end {
for y in rect.y..rect.y_end {
if (octile_distance(position, (x, y)) as f32) < mult_distance {
self.map[x][y] += value;
}
Expand Down Expand Up @@ -674,7 +674,6 @@ impl PathFind {
}
}


if current_distance < distance + 4.0 {
let best_influence = self.map[(best_target.0).0 as usize][(best_target.0).1 as usize];
//let mut best_distance_from_target = octile_distance_f64(best_target.0, target_int);
Expand Down
10 changes: 4 additions & 6 deletions tests/common.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use std::io::{BufReader, BufRead};
use std::fs::File;
use sc2pathlib::path_find;
use sc2pathlib::mapping::map::Map;

use sc2pathlib::path_find;
use std::fs::File;
use std::io::{BufRead, BufReader};

fn rot90(vec: Vec<Vec<usize>>) -> Vec<Vec<usize>> {
let len = vec[0].len();
Expand All @@ -20,7 +19,6 @@ fn rot90(vec: Vec<Vec<usize>>) -> Vec<Vec<usize>> {
new_arr
}


pub fn read_vec_from_file(file_path: &str) -> Vec<Vec<usize>> {
let f = BufReader::new(File::open(file_path).unwrap());
let mut arr = Vec::<Vec<usize>>::new();
Expand Down Expand Up @@ -48,4 +46,4 @@ pub fn get_choke_map() -> Map {

let map = Map::new(grid, grid2, grid3, 2, 2, 38, 38);
return map;
}
}
3 changes: 1 addition & 2 deletions tests/test_pathfinding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ fn test_find_path_automaton_le() {
assert_eq!(distance, 147.1656);
}


#[test]
fn test_find_path_4x4() {
let path_find = get_pathfind("tests/maze4x4.txt");
Expand All @@ -25,4 +24,4 @@ fn test_find_path_10x10() {
let r = path_find.find_path((0, 0), (8, 9), Some(0));
let (_, distance) = r;
assert_eq!(distance, 12.3136);
}
}

0 comments on commit aaf42ac

Please sign in to comment.