use coloctree::*;
use rand::prelude::*;
use rand::seq::SliceRandom;
fn main() {
let mut octree_root = OctreeNode::new(
Color { r: 0, g: 0, b: 0 },
Color {
r: 255,
g: 255,
b: 255,
},
);
let mut rng = rand::rng();
let mut every_color: Vec<Color> = Vec::new();
let max_number_of_color = 255 * 255 * 255;
for r in 0..=255 {
for g in 0..=255 {
for b in 0..=255 {
every_color.push(Color { r, g, b });
}
}
}
let every_color = every_color;
let mut colors_to_add = every_color.clone();
colors_to_add.shuffle(&mut rng);
for percent in 0..25 {
for _ in 0..(max_number_of_color / 25) {
octree_root.insert(colors_to_add.pop().unwrap())
}
let nb_colors_to_search = 25 * 10;
let mut colors_to_search = every_color
.iter()
.choose_multiple(&mut rng, nb_colors_to_search);
colors_to_search.shuffle(&mut rng);
let mut error_count = 0;
for color in &colors_to_search {
let nearest = octree_root.find_nearest_neighbor(color).unwrap();
let real_nearest = octree_root._find_nearest_neighbor_slow(color).unwrap();
if nearest.distance_squared(color) > real_nearest.distance_squared(color) {
error_count += 1;
} else if nearest.distance_squared(color) > real_nearest.distance_squared(color) {
panic!("Error in reverse !!!")
}
}
println!(
"Octree filled@ {}%: / Error rate: {:.}% ({})",
4 * (percent + 1),
error_count * 100 / nb_colors_to_search,
error_count
);
}
}