coloctree 0.1.0

An octree implementation for RGB Color to create all RGB images.
Documentation
use coloctree::*;
use rand::prelude::*;
use rand::seq::SliceRandom;

/* BUG: Test Resulst

Octree filled@ 4%: / Error rate: 28%
Octree filled@ 8%: / Error rate: 21%
Octree filled@ 12%: / Error rate: 19%
Octree filled@ 16%: / Error rate: 20%
Octree filled@ 20%: / Error rate: 14%
Octree filled@ 24%: / Error rate: 11%
Octree filled@ 28%: / Error rate: 14%
Octree filled@ 32%: / Error rate: 15%
Octree filled@ 36%: / Error rate: 13%
Octree filled@ 40%: / Error rate: 9%
Octree filled@ 44%: / Error rate: 8%
Octree filled@ 48%: / Error rate: 6%
Octree filled@ 52%: / Error rate: 5%
Octree filled@ 56%: / Error rate: 2%
Octree filled@ 60%: / Error rate: 2%
Octree filled@ 64%: / Error rate: 4%
Octree filled@ 68%: / Error rate: 1%
Octree filled@ 72%: / Error rate: 0%
Octree filled@ 76%: / Error rate: 0%
Octree filled@ 80%: / Error rate: 0%
Octree filled@ 84%: / Error rate: 0%
Octree filled@ 88%: / Error rate: 0%
Octree filled@ 92%: / Error rate: 0%
Octree filled@ 96%: / Error rate: 0%
Octree filled@ 100%: / Error rate: 0%

// FIX:


*/

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);

    // Add 4% of color in the octree at each iteration
    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
        );
    }
}