From aaf42acb0fbfc1ea540cc06c17734108a2657c14 Mon Sep 17 00:00:00 2001 From: DrInfy Date: Mon, 16 Nov 2020 00:25:35 +0200 Subject: [PATCH] cargo fmt --- benches/common.rs | 8 +++----- benches/path_benchmark.rs | 26 +++++++++++++------------- src/mapping/influence.rs | 4 ++-- src/path_find/mod.rs | 3 +-- tests/common.rs | 10 ++++------ tests/test_pathfinding.rs | 3 +-- 6 files changed, 24 insertions(+), 30 deletions(-) diff --git a/benches/common.rs b/benches/common.rs index 4f6047b..64fdeb2 100644 --- a/benches/common.rs +++ b/benches/common.rs @@ -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> { let len = vec[0].len(); @@ -19,7 +18,6 @@ fn rot90(vec: Vec>) -> Vec> { new_arr } - fn read_vec_from_file(file_path: &str) -> Vec> { let f = BufReader::new(File::open(file_path).unwrap()); let mut arr = Vec::>::new(); @@ -38,4 +36,4 @@ fn read_vec_from_file(file_path: &str) -> Vec> { pub fn get_pathfind(file: &str) -> path_find::PathFind { let map = read_vec_from_file(file); path_find::PathFind::new_internal(map) -} \ No newline at end of file +} diff --git a/benches/path_benchmark.rs b/benches/path_benchmark.rs index 10ea820..3b97c01 100644 --- a/benches/path_benchmark.rs +++ b/benches/path_benchmark.rs @@ -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); diff --git a/src/mapping/influence.rs b/src/mapping/influence.rs index 305cb7e..6ba8f53 100644 --- a/src/mapping/influence.rs +++ b/src/mapping/influence.rs @@ -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; @@ -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; } } diff --git a/src/path_find/mod.rs b/src/path_find/mod.rs index f69254e..8d74e39 100644 --- a/src/path_find/mod.rs +++ b/src/path_find/mod.rs @@ -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; } @@ -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); diff --git a/tests/common.rs b/tests/common.rs index 9830793..a0d46d0 100644 --- a/tests/common.rs +++ b/tests/common.rs @@ -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> { let len = vec[0].len(); @@ -20,7 +19,6 @@ fn rot90(vec: Vec>) -> Vec> { new_arr } - pub fn read_vec_from_file(file_path: &str) -> Vec> { let f = BufReader::new(File::open(file_path).unwrap()); let mut arr = Vec::>::new(); @@ -48,4 +46,4 @@ pub fn get_choke_map() -> Map { let map = Map::new(grid, grid2, grid3, 2, 2, 38, 38); return map; -} \ No newline at end of file +} diff --git a/tests/test_pathfinding.rs b/tests/test_pathfinding.rs index 0e5132d..7223e88 100644 --- a/tests/test_pathfinding.rs +++ b/tests/test_pathfinding.rs @@ -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"); @@ -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); -} \ No newline at end of file +}