diff --git a/Cargo.lock b/Cargo.lock index dcdff07..21ae8a9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -42,9 +42,9 @@ checksum = "c08606f8c3cbf4ce6ec8e28fb0014a2c086708fe954eaa885384a6165172e7e8" [[package]] name = "base64" -version = "0.13.1" +version = "0.22.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8" +checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" [[package]] name = "bitflags" @@ -52,6 +52,15 @@ version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" +[[package]] +name = "bitflags" +version = "2.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "812e12b5285cc515a9c72a5c1d3b6d46a19dac5acfef5265968c166106e31dd3" +dependencies = [ + "serde_core", +] + [[package]] name = "bumpalo" version = "3.19.0" @@ -109,7 +118,7 @@ version = "3.2.25" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4ea181bf566f71cb9a5d17a59e1871af638180a18fb0035c92ae62b705207123" dependencies = [ - "bitflags", + "bitflags 1.3.2", "clap_lex 0.2.4", "indexmap 1.9.3", "textwrap", @@ -284,9 +293,15 @@ checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f" [[package]] name = "fixedbitset" -version = "0.4.2" +version = "0.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d674e81391d1e1ab681a28d99df07927c6d4aa5b027d7da16ba32d1d21ecd99" + +[[package]] +name = "foldhash" +version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ce7134b9999ecaf8bcd65542e436736ef32ddca1b3e06094cb6ec5755203b80" +checksum = "d9c4f5dac5e15c24eb999c26181a6ca40b39fe946cbe4c263c7209467bc83af2" [[package]] name = "fxhash" @@ -349,15 +364,16 @@ dependencies = [ [[package]] name = "grid_util" -version = "0.1.1" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b7f09fe015ff50963bc5b9810f73e54d69c8770b1986f3c8c475ba04a347662" +checksum = "f35c4ef4777c538df2f8e60bcd88b05dba97568b1459d062f441c55ca3b7efa4" dependencies = [ "num_enum", "rand 0.8.5", "rand_derive2", "ron", "serde", + "smallvec", "strum", "strum_macros", ] @@ -379,6 +395,15 @@ version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" +[[package]] +name = "hashbrown" +version = "0.15.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9229cfe53dfd69f0609a49f65461bd93001ea1ef889cd5529dd176593f5338a1" +dependencies = [ + "foldhash", +] + [[package]] name = "hashbrown" version = "0.16.0" @@ -387,12 +412,9 @@ checksum = "5419bdc4f6a9207fbeba6d11b604d481addf78ecd10c11ad51e76c2f6482748d" [[package]] name = "heck" -version = "0.3.3" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d621efb26863f0e9924c6ac577e8275e5e6b77455db64ffa6c65c904e9e132c" -dependencies = [ - "unicode-segmentation", -] +checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" [[package]] name = "hermit-abi" @@ -492,23 +514,24 @@ dependencies = [ [[package]] name = "num_enum" -version = "0.5.11" +version = "0.7.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1f646caf906c20226733ed5b1374287eb97e3c2a5c227ce668c1f2ce20ae57c9" +checksum = "b1207a7e20ad57b847bbddc6776b968420d38292bbfe2089accff5e19e82454c" dependencies = [ "num_enum_derive", + "rustversion", ] [[package]] name = "num_enum_derive" -version = "0.5.11" +version = "0.7.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dcbff9bc912032c62bf65ef1d5aea88983b420f4f839db1e9b0c281a25c9c799" +checksum = "ff32365de1b6743cb203b710788263c44a03de03802daf96092f2da4fe6ba4d7" dependencies = [ "proc-macro-crate", "proc-macro2", "quote", - "syn 1.0.109", + "syn", ] [[package]] @@ -531,12 +554,14 @@ checksum = "e2355d85b9a3786f481747ced0e0ff2ba35213a1f9bd406ed906554d7af805a1" [[package]] name = "petgraph" -version = "0.6.5" +version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b4c5cc86750666a3ed20bdaf5ca2a0344f9c67674cae0515bec2da16fbaa47db" +checksum = "8701b58ea97060d5e5b155d383a69952a60943f0e6dfe30b04c287beb0b27455" dependencies = [ "fixedbitset", + "hashbrown 0.15.5", "indexmap 2.12.0", + "serde", ] [[package]] @@ -578,11 +603,10 @@ dependencies = [ [[package]] name = "proc-macro-crate" -version = "1.3.1" +version = "3.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f4c021e1093a56626774e81216a4ce732a735e5bad4868a03f3ed65ca0c3919" +checksum = "219cb19e96be00ab2e37d6e299658a0cfa83e52429179969b0f0121b4ac46983" dependencies = [ - "once_cell", "toml_edit", ] @@ -602,7 +626,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "79528bef70da112116feb5ecb6b64f1394e5360660d6474a760789ea07885501" dependencies = [ "proc-macro2", - "syn 2.0.109", + "syn", ] [[package]] @@ -688,7 +712,7 @@ dependencies = [ "proc-macro2", "proc_macro2_helper", "quote", - "syn 2.0.109", + "syn", ] [[package]] @@ -742,13 +766,15 @@ checksum = "7a2d987857b319362043e95f5353c0535c1f58eec5336fdfcf626430af7def58" [[package]] name = "ron" -version = "0.6.6" +version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "86018df177b1beef6c7c8ef949969c4f7cb9a9344181b92486b23c79995bdaa4" +checksum = "db09040cc89e461f1a265139777a2bde7f8d8c67c4936f700c63ce3e2904d468" dependencies = [ "base64", - "bitflags", + "bitflags 2.10.0", "serde", + "serde_derive", + "unicode-ident", ] [[package]] @@ -799,7 +825,7 @@ checksum = "d540f220d3187173da220f885ab66608367b6574e925011a9353e4badda91d79" dependencies = [ "proc-macro2", "quote", - "syn 2.0.109", + "syn", ] [[package]] @@ -823,31 +849,20 @@ checksum = "67b1b7a3b5fe4f1376887184045fcf45c69e92af734b7aaddc05fb777b6fbd03" [[package]] name = "strum" -version = "0.20.0" +version = "0.27.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7318c509b5ba57f18533982607f24070a55d353e90d4cae30c467cdb2ad5ac5c" +checksum = "af23d6f6c1a224baef9d3f61e287d2761385a5b88fdab4eb4c6f11aeb54c4bcf" [[package]] name = "strum_macros" -version = "0.20.1" +version = "0.27.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee8bc6b87a5112aeeab1f4a9f7ab634fe6cbefc4850006df31267f4cfb9e3149" +checksum = "7695ce3845ea4b33927c055a39dc438a45b059f7c1b3d91d38d10355fb8cbca7" dependencies = [ "heck", "proc-macro2", "quote", - "syn 1.0.109", -] - -[[package]] -name = "syn" -version = "1.0.109" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", + "syn", ] [[package]] @@ -879,32 +894,39 @@ dependencies = [ [[package]] name = "toml_datetime" -version = "0.6.11" +version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "22cddaf88f4fbc13c51aebbf5f8eceb5c7c5a9da2ac40a13519eb5b0a0e8f11c" +checksum = "f2cdb639ebbc97961c51720f858597f7f24c4fc295327923af55b74c3c724533" +dependencies = [ + "serde_core", +] [[package]] name = "toml_edit" -version = "0.19.15" +version = "0.23.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b5bb770da30e5cbfde35a2d7b9b8a2c4b8ef89548a7a6aeab5c9a576e3e7421" +checksum = "6485ef6d0d9b5d0ec17244ff7eb05310113c3f316f2d14200d4de56b3cb98f8d" dependencies = [ "indexmap 2.12.0", "toml_datetime", + "toml_parser", "winnow", ] [[package]] -name = "unicode-ident" -version = "1.0.22" +name = "toml_parser" +version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9312f7c4f6ff9069b165498234ce8be658059c6728633667c526e27dc2cf1df5" +checksum = "c0cbe268d35bdb4bb5a56a2de88d0ad0eb70af5384a99d648cd4b3d04039800e" +dependencies = [ + "winnow", +] [[package]] -name = "unicode-segmentation" -version = "1.12.0" +name = "unicode-ident" +version = "1.0.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6ccf251212114b54433ec949fd6a7841275f9ada20dddd2f29e9ceea4501493" +checksum = "9312f7c4f6ff9069b165498234ce8be658059c6728633667c526e27dc2cf1df5" [[package]] name = "walkdir" @@ -963,7 +985,7 @@ dependencies = [ "bumpalo", "proc-macro2", "quote", - "syn 2.0.109", + "syn", "wasm-bindgen-shared", ] @@ -1034,9 +1056,9 @@ dependencies = [ [[package]] name = "winnow" -version = "0.5.40" +version = "0.7.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f593a95398737aeed53e489c785df13f3618e41dbcd6718c6addbf1395aa6876" +checksum = "21a0236b59786fed61e2a80582dd500fe61f18b5dca67a4a067d0bc9039339cf" dependencies = [ "memchr", ] @@ -1064,5 +1086,5 @@ checksum = "88d2b8d9c68ad2b9e4340d7832716a4d21a22a1154777ad56ea55c51a9cf3831" dependencies = [ "proc-macro2", "quote", - "syn 2.0.109", + "syn", ] diff --git a/Cargo.toml b/Cargo.toml index 399e0b3..e99b9fb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,11 +12,11 @@ readme = "README.md" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -petgraph = "0.6" +petgraph = "0.8" indexmap = "2.3" fxhash = "0.2" num-traits = "0.2" -grid_util = "0.1" +grid_util = { version = "0.2", features = ["smallvec"]} log = "0.4" smallvec = "1.13.2" diff --git a/benches/comparison_bench.rs b/benches/comparison_bench.rs index 58ef88e..df9dd35 100644 --- a/benches/comparison_bench.rs +++ b/benches/comparison_bench.rs @@ -1,7 +1,8 @@ -use criterion::{black_box, criterion_group, criterion_main, Criterion}; +use criterion::{criterion_group, criterion_main, Criterion}; use grid_pathfinding::PathingGrid; use grid_pathfinding_benchmark::*; -use grid_util::grid::Grid; +use grid_util::grid::ValueGrid; +use std::hint::black_box; fn dao_bench(c: &mut Criterion) { for (allow_diag, pruning) in [(true, false), (true, true)] { diff --git a/benches/single_bench.rs b/benches/single_bench.rs index 08f8ca8..60c27b3 100644 --- a/benches/single_bench.rs +++ b/benches/single_bench.rs @@ -1,7 +1,8 @@ -use criterion::{black_box, criterion_group, criterion_main, Criterion}; +use criterion::{criterion_group, criterion_main, Criterion}; use grid_pathfinding::PathingGrid; use grid_pathfinding_benchmark::*; -use grid_util::grid::Grid; +use grid_util::grid::ValueGrid; +use std::hint::black_box; fn dao_bench_single(c: &mut Criterion) { for (allow_diag, pruning) in [(true, false)] { diff --git a/examples/benchmark_runner.rs b/examples/benchmark_runner.rs index 85f9d76..2f22aa2 100644 --- a/examples/benchmark_runner.rs +++ b/examples/benchmark_runner.rs @@ -1,6 +1,6 @@ use grid_pathfinding::PathingGrid; use grid_pathfinding_benchmark::*; -use grid_util::grid::Grid; +use grid_util::grid::ValueGrid; use grid_util::point::Point; use std::time::{Duration, Instant}; diff --git a/examples/heuristic_factor.rs b/examples/heuristic_factor.rs index 730c7a5..a5f918f 100644 --- a/examples/heuristic_factor.rs +++ b/examples/heuristic_factor.rs @@ -1,5 +1,5 @@ use grid_pathfinding::PathingGrid; -use grid_util::grid::Grid; +use grid_util::grid::ValueGrid; use grid_util::point::Point; use grid_util::Rect; @@ -10,10 +10,10 @@ fn main() { const N: i32 = 30; let mut pathing_grid: PathingGrid = PathingGrid::new(N as usize, N as usize, true); pathing_grid.heuristic_factor = 1.3; - pathing_grid.set_rectangle(&Rect::new(1, 1, N - 2, N - 2), false); - pathing_grid.set_rectangle(&Rect::new(8, 8, 8, 8), true); - pathing_grid.set_rectangle(&Rect::new(0, 3, 6, 6), true); - pathing_grid.set_rectangle(&Rect::new(10, 0, 6, 6), true); + pathing_grid.set_rect(Rect::new(1, 1, N - 2, N - 2), false); + pathing_grid.set_rect(Rect::new(8, 8, 8, 8), true); + pathing_grid.set_rect(Rect::new(0, 3, 6, 6), true); + pathing_grid.set_rect(Rect::new(10, 0, 6, 6), true); pathing_grid.generate_components(); println!("{}", pathing_grid); let start = Point::new(1, 1); diff --git a/examples/multiple_goals.rs b/examples/multiple_goals.rs index 3c105d1..a467c14 100644 --- a/examples/multiple_goals.rs +++ b/examples/multiple_goals.rs @@ -1,5 +1,5 @@ use grid_pathfinding::PathingGrid; -use grid_util::grid::Grid; +use grid_util::grid::ValueGrid; use grid_util::point::Point; // In this example a path is found to one of two goals on a 3x3 grid with shape diff --git a/examples/paths_and_waypoints.rs b/examples/paths_and_waypoints.rs index 8162b9c..21f5c72 100644 --- a/examples/paths_and_waypoints.rs +++ b/examples/paths_and_waypoints.rs @@ -1,5 +1,5 @@ use grid_pathfinding::{waypoints_to_path, PathingGrid}; -use grid_util::grid::Grid; +use grid_util::grid::ValueGrid; use grid_util::point::Point; // This example illustrates the difference between waypoints and paths. diff --git a/examples/simple_4.rs b/examples/simple_4.rs index b7b8278..e3da7c2 100644 --- a/examples/simple_4.rs +++ b/examples/simple_4.rs @@ -1,5 +1,5 @@ use grid_pathfinding::PathingGrid; -use grid_util::grid::Grid; +use grid_util::grid::ValueGrid; use grid_util::point::Point; // In this example a path is found on a 3x3 grid with shape diff --git a/examples/simple_8.rs b/examples/simple_8.rs index 614ee63..0654deb 100644 --- a/examples/simple_8.rs +++ b/examples/simple_8.rs @@ -1,5 +1,5 @@ use grid_pathfinding::PathingGrid; -use grid_util::grid::Grid; +use grid_util::grid::ValueGrid; use grid_util::point::Point; // In this example a path is found on a 3x3 grid with shape diff --git a/grid_pathfinding_benchmark/Cargo.toml b/grid_pathfinding_benchmark/Cargo.toml index de99d32..1a13c14 100644 --- a/grid_pathfinding_benchmark/Cargo.toml +++ b/grid_pathfinding_benchmark/Cargo.toml @@ -12,7 +12,7 @@ readme = "README.md" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -grid_util = "0.1.1" +grid_util = "0.2" criterion = { version = "0.4", features = ["html_reports"] } csv = "1.3.0" serde = "1.0.204" diff --git a/grid_pathfinding_benchmark/src/lib.rs b/grid_pathfinding_benchmark/src/lib.rs index 942a496..a1e318a 100644 --- a/grid_pathfinding_benchmark/src/lib.rs +++ b/grid_pathfinding_benchmark/src/lib.rs @@ -1,5 +1,5 @@ use csv::ReaderBuilder; -use grid_util::grid::Grid; +use grid_util::grid::ValueGrid; use grid_util::point::Point; use grid_util::BoolGrid; use serde::Deserialize; @@ -69,10 +69,10 @@ fn load_benchmark(name: &str) -> (BoolGrid, Vec<(Point, Point)>) { let offset = 4; let mut bool_grid: BoolGrid = BoolGrid::new(w, h, false); - for y in 0..bool_grid.height() { - for x in 0..bool_grid.width() { + for y in 0..bool_grid.height() as i32 { + for x in 0..bool_grid.width() as i32 { // Not sure why x, y have to be swapped here... - let tile_val = lines[offset + x].as_bytes()[y]; + let tile_val = lines[offset + x as usize].as_bytes()[y as usize]; let val = ![b'.', b'G'].contains(&tile_val); bool_grid.set(x, y, val); } diff --git a/src/lib.rs b/src/lib.rs index c626244..f21c5cf 100755 --- a/src/lib.rs +++ b/src/lib.rs @@ -11,7 +11,7 @@ mod astar_jps; use astar_jps::AstarContext; use core::fmt; use grid_util::direction::Direction; -use grid_util::grid::{BoolGrid, Grid, SimpleGrid}; +use grid_util::grid::{BoolGrid, SimpleValueGrid, ValueGrid}; use grid_util::point::Point; use petgraph::unionfind::UnionFind; use smallvec::SmallVec; @@ -64,8 +64,8 @@ pub fn waypoints_to_path(waypoints: Vec) -> Vec { #[derive(Clone, Debug)] pub struct PathingGrid { pub grid: BoolGrid, - pub jump_point: SimpleGrid, - pub neighbours: SimpleGrid, + pub neighbours: SimpleValueGrid, + pub jump_point: SimpleValueGrid, pub components: UnionFind, pub components_dirty: bool, pub heuristic_factor: f32, @@ -78,8 +78,8 @@ impl Default for PathingGrid { fn default() -> PathingGrid { let mut grid = PathingGrid { grid: BoolGrid::default(), - jump_point: SimpleGrid::default(), - neighbours: SimpleGrid::default(), + neighbours: SimpleValueGrid::default(), + jump_point: SimpleValueGrid::default(), components: UnionFind::new(0), components_dirty: false, improved_pruning: true, @@ -92,11 +92,11 @@ impl Default for PathingGrid { } } impl PathingGrid { - fn neighborhood_points(&self, point: &Point) -> Vec { + fn neighborhood_points(&self, point: &Point) -> SmallVec<[Point; 8]> { if self.allow_diagonal_move { - point.moore_neighborhood() + point.moore_neighborhood_smallvec() } else { - point.neumann_neighborhood() + point.neumann_neighborhood_smallvec() } } fn neighborhood_points_and_cost( @@ -124,10 +124,10 @@ impl PathingGrid { } } fn can_move_to(&self, pos: Point) -> bool { - self.in_bounds(pos.x, pos.y) && !self.grid.get(pos.x as usize, pos.y as usize) + self.point_in_bounds(pos) && !self.grid.get_point(pos) } fn in_bounds(&self, x: i32, y: i32) -> bool { - x >= 0 && y >= 0 && self.grid.index_in_bounds(x as usize, y as usize) + self.grid.index_in_bounds(x, y) } /// The neighbour indexing used here corresponds to that used in [grid_util::Direction]. fn indexed_neighbor(&self, node: &Point, index: i32) -> bool { @@ -496,9 +496,9 @@ impl PathingGrid { } pub fn update_all_neighbours(&mut self) { - for x in 0..self.width() { - for y in 0..self.height() { - self.update_neighbours(x as i32, y as i32, self.get(x, y)); + for x in 0..self.width() as i32 { + for y in 0..self.height() as i32 { + self.update_neighbours(x, y, self.get(x, y)); } } } @@ -545,11 +545,11 @@ impl PathingGrid { let h = self.grid.height; self.components = UnionFind::new(w * h); self.components_dirty = false; - for x in 0..w { - for y in 0..h { + for x in 0..w as i32 { + for y in 0..h as i32 { if !self.grid.get(x, y) { - let parent_ix = self.grid.get_ix(x, y); - let point = Point::new(x as i32, y as i32); + let point = Point::new(x, y); + let parent_ix = self.grid.get_ix_point(&point); if self.allow_diagonal_move { vec![ @@ -570,7 +570,7 @@ impl PathingGrid { .into_iter() .filter(|p| self.grid.point_in_bounds(*p) && !self.grid.get_point(*p)) .for_each(|p| { - let ix = self.grid.get_ix(p.x as usize, p.y as usize); + let ix = self.grid.get_ix_point(&p); self.components.union(parent_ix, ix); }); } @@ -581,15 +581,15 @@ impl PathingGrid { impl fmt::Display for PathingGrid { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { writeln!(f, "Grid:")?; - for y in 0..self.grid.height { - let values = (0..self.grid.width) + for y in 0..self.grid.height as i32 { + let values = (0..self.grid.width as i32) .map(|x| self.grid.get(x, y) as i32) .collect::>(); writeln!(f, "{:?}", values)?; } writeln!(f, "\nNeighbours:")?; - for y in 0..self.neighbours.height { - let values = (0..self.neighbours.width) + for y in 0..self.neighbours.height as i32 { + let values = (0..self.neighbours.width as i32) .map(|x| self.neighbours.get(x, y) as i32) .collect::>(); writeln!(f, "{:?}", values)?; @@ -598,12 +598,12 @@ impl fmt::Display for PathingGrid { } } -impl Grid for PathingGrid { +impl ValueGrid for PathingGrid { fn new(width: usize, height: usize, default_value: bool) -> Self { let mut base_grid = PathingGrid { grid: BoolGrid::new(width, height, default_value), - jump_point: SimpleGrid::new(width, height, 0b00000000), - neighbours: SimpleGrid::new(width, height, 0b11111111), + jump_point: SimpleValueGrid::new(width, height, 0b00000000), + neighbours: SimpleValueGrid::new(width, height, 0b11111111), components: UnionFind::new(width * height), components_dirty: false, improved_pruning: true, @@ -614,21 +614,20 @@ impl Grid for PathingGrid { base_grid.initialize(); base_grid } - fn get(&self, x: usize, y: usize) -> bool { + fn get(&self, x: i32, y: i32) -> bool { self.grid.get(x, y) } /// Updates a position on the grid. Joins newly connected components and flags the components /// as dirty if components are (potentially) broken apart into multiple. - fn set(&mut self, x: usize, y: usize, blocked: bool) { - let p = Point::new(x as i32, y as i32); + fn set(&mut self, x: i32, y: i32, blocked: bool) { + let p = Point::new(x, y); if self.grid.get(x, y) != blocked && blocked { self.components_dirty = true; } else { - let p_ix = self.grid.get_ix(x, y); + let p_ix = self.grid.compute_ix(x, y); for p in self.neighborhood_points(&p) { if self.can_move_to(p) { - self.components - .union(p_ix, self.grid.get_ix(p.x as usize, p.y as usize)); + self.components.union(p_ix, self.grid.get_ix_point(&p)); } } } @@ -772,10 +771,10 @@ mod tests { [(false, false, 15), (true, false, 10), (true, true, 10)] { let mut pathing_grid: PathingGrid = PathingGrid::new(10, 10, false); - pathing_grid.set_rectangle(&Rect::new(1, 1, 2, 2), true); - pathing_grid.set_rectangle(&Rect::new(5, 0, 2, 2), true); - pathing_grid.set_rectangle(&Rect::new(0, 5, 2, 2), true); - pathing_grid.set_rectangle(&Rect::new(8, 8, 2, 2), true); + pathing_grid.set_rect(Rect::new(1, 1, 1, 1), true); + pathing_grid.set_rect(Rect::new(5, 0, 1, 1), true); + pathing_grid.set_rect(Rect::new(0, 5, 1, 1), true); + pathing_grid.set_rect(Rect::new(8, 8, 1, 1), true); // pathing_grid.improved_pruning = false; pathing_grid.allow_diagonal_move = allow_diag; pathing_grid.improved_pruning = pruning; @@ -794,10 +793,10 @@ mod tests { [(false, false, 11), (true, false, 7), (true, true, 5)] { let mut pathing_grid: PathingGrid = PathingGrid::new(10, 10, false); - pathing_grid.set_rectangle(&Rect::new(1, 1, 2, 2), true); - pathing_grid.set_rectangle(&Rect::new(5, 0, 2, 2), true); - pathing_grid.set_rectangle(&Rect::new(0, 5, 2, 2), true); - pathing_grid.set_rectangle(&Rect::new(8, 8, 2, 2), true); + pathing_grid.set_rect(Rect::new(1, 1, 1, 1), true); + pathing_grid.set_rect(Rect::new(5, 0, 1, 1), true); + pathing_grid.set_rect(Rect::new(0, 5, 1, 1), true); + pathing_grid.set_rect(Rect::new(8, 8, 1, 1), true); // pathing_grid.improved_pruning = false; pathing_grid.allow_diagonal_move = allow_diag; pathing_grid.improved_pruning = pruning; diff --git a/tests/fuzz_test.rs b/tests/fuzz_test.rs index ebd6d4d..af997db 100644 --- a/tests/fuzz_test.rs +++ b/tests/fuzz_test.rs @@ -8,8 +8,8 @@ fn random_grid(n: usize, rng: &mut StdRng, diagonal: bool, improved_pruning: boo let mut pathing_grid: PathingGrid = PathingGrid::new(n, n, false); pathing_grid.allow_diagonal_move = diagonal; pathing_grid.improved_pruning = improved_pruning; - for x in 0..pathing_grid.width() { - for y in 0..pathing_grid.height() { + for x in 0..pathing_grid.width() as i32 { + for y in 0..pathing_grid.height() as i32 { pathing_grid.set(x, y, rng.gen_bool(0.4)) } } @@ -19,9 +19,9 @@ fn random_grid(n: usize, rng: &mut StdRng, diagonal: bool, improved_pruning: boo fn visualize_grid(grid: &PathingGrid, start: &Point, end: &Point) { let grid = &grid.grid; - for y in (0..grid.height).rev() { - for x in 0..grid.width { - let p = Point::new(x as i32, y as i32); + for y in (0..grid.height as i32).rev() { + for x in 0..grid.width as i32 { + let p = Point::new(x, y); if *start == p { print!("S"); } else if *end == p {