use aabb::prelude::*;
use std::time::Instant;
const NUM_POINTS: usize = 1_000_000;
const NUM_QUERIES: usize = 10_000;
fn main() {
println!("Building spatial index with {} random points...", NUM_POINTS);
let mut tree = AABB::with_capacity(NUM_POINTS);
let mut rng = 12345u64; for _ in 0..NUM_POINTS {
rng = rng.wrapping_mul(6364136223846793005).wrapping_add(1442695040888963407);
let x = ((rng >> 32) as f64 / u32::MAX as f64) * 1000.0;
rng = rng.wrapping_mul(6364136223846793005).wrapping_add(1442695040888963407);
let y = ((rng >> 32) as f64 / u32::MAX as f64) * 1000.0;
tree.add_point(x, y);
}
let build_start = Instant::now();
tree.build();
let build_duration = build_start.elapsed();
let mut results = Vec::new();
let query_start = Instant::now();
for _ in 0..NUM_QUERIES {
rng = rng.wrapping_mul(6364136223846793005).wrapping_add(1442695040888963407);
let center_x = ((rng >> 32) as f64 / u32::MAX as f64) * 1000.0;
rng = rng.wrapping_mul(6364136223846793005).wrapping_add(1442695040888963407);
let center_y = ((rng >> 32) as f64 / u32::MAX as f64) * 1000.0;
let radius = 5.0; tree.query_circle_points(center_x, center_y, radius, &mut results);
}
let query_duration = query_start.elapsed();
println!("Index built in {:.2}ms", build_duration.as_secs_f64() * 1000.0);
println!("Completed {} queries in {:.2}ms ({:.2}µs per query)",
NUM_QUERIES,
query_duration.as_secs_f64() * 1000.0,
query_duration.as_secs_f64() * 1_000_000.0 / NUM_QUERIES as f64
);
}