diff --git a/Cargo.lock b/Cargo.lock index 5d997ae..fb4299b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -357,8 +357,10 @@ dependencies = [ "bevy", "criterion", "dirs", + "glam 0.31.0", "include_dir", "ordered-float", + "rand", "rusqlite", "rusqlite_migration", "steel-core", @@ -985,7 +987,7 @@ dependencies = [ "arrayvec 0.7.6", "bevy_reflect", "derive_more", - "glam", + "glam 0.30.10", "itertools 0.14.0", "libm", "rand", @@ -1159,7 +1161,7 @@ dependencies = [ "downcast-rs 2.0.2", "erased-serde", "foldhash 0.2.0", - "glam", + "glam 0.30.10", "indexmap 2.13.0", "inventory", "petgraph", @@ -1219,7 +1221,7 @@ dependencies = [ "downcast-rs 2.0.2", "encase", "fixedbitset", - "glam", + "glam 0.30.10", "image", "indexmap 2.13.0", "js-sys", @@ -2874,6 +2876,15 @@ dependencies = [ "serde_core", ] +[[package]] +name = "glam" +version = "0.31.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "74a4d85559e2637d3d839438b5b3d75c31e655276f9544d72475c36b92fabbed" +dependencies = [ + "libm", +] + [[package]] name = "glob" version = "0.3.3" @@ -3073,7 +3084,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "29a164ceff4500f2a72b1d21beaa8aa8ad83aec2b641844c659b190cb3ea2e0b" dependencies = [ "constgebra", - "glam", + "glam 0.30.10", "tinyvec", ] diff --git a/Cargo.toml b/Cargo.toml index d0e6be4..9a36109 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,6 +7,7 @@ edition = "2024" bevy = { version = "0.18", default-features = false, features = ["2d"] } criterion = { version = "0.8.1", default-features = false, features = ["cargo_bench_support", "rayon"] } dirs = "6.0.0" +glam = { version = "0.31.0", default-features = false, features = ["libm"] } include_dir = "0.7.4" ordered-float = "5.1.0" rusqlite = { version = "0.37", default-features = false, features = ["bundled", "blob", "functions", "jiff"] } @@ -27,3 +28,6 @@ inherits = "release" [[bench]] name = "main" harness = false + +[dev-dependencies] +rand = "0.9.2" diff --git a/benches/main.rs b/benches/main.rs index a2cb141..2e191ec 100644 --- a/benches/main.rs +++ b/benches/main.rs @@ -1,6 +1,6 @@ use criterion::criterion_main; -mod bench_insert_bulk; +//mod bench_insert_bulk; mod bench_range_search; -criterion_main!(bench_insert_bulk::benches, bench_range_search::benches,); +criterion_main!(bench_range_search::benches,); diff --git a/src/spindex.rs b/src/spindex.rs index ab37f5b..a2a6145 100644 --- a/src/spindex.rs +++ b/src/spindex.rs @@ -105,15 +105,11 @@ impl RStarTree { pub fn range_search(&self, query_point: &Point, radius: f32) -> Vec<&Point> { let query_bbox = Aabb2d::new(query_point.point, Vec2::splat(radius)); - let r2 = radius * radius; + let r2 = radius.powi(2); let candidates = self.range_search_bbox(&query_bbox); candidates .into_iter() - .filter(|&other| { - ((query_point.point.x - other.point.x) + (query_point.point.y - other.point.y)) - .powi(2) - <= r2 - }) + .filter(|&other| query_point.point.distance_squared(other.point) <= r2) .collect() }