use comfy::*;
use comfy_core::spatial_hash::*;
fn main() {
let mut spatial = SpatialHash::new();
loop {
let now = Instant::now();
for _ in 0..1000 {
let vec = vec2(random() * 20.0, random() * 20.0);
spatial.add_shape(
Shape::Circle(CircleShape {
center: vec,
radius: random() * 2.0,
}),
UserData { entity_type: 0, entity: None },
);
}
let mut total = 0;
for cell in spatial.inner.iter() {
total += cell.1.len();
}
let mut count = 0;
for _ in 0..1000 {
let vec = vec2(random() * 20.0, random() * 20.0);
let result = spatial.query(SpatialQuery::ShapeQuery(
Shape::Circle(CircleShape { center: vec, radius: 2.0 }),
));
count += result.count(); }
println!(
"Count: {} ... {}us ... cells: {} ... average per cell: {}",
count,
now.elapsed().as_micros(),
spatial.inner.len(),
total / usize::max(spatial.inner.len(), 1)
);
spatial.clear();
}
}