poisson2d 0.1.0

Poisson disk sampling generator.
Documentation
use glam::Vec2;
use poisson2d::Type;
use rand::{rngs::SmallRng, Rng, SeedableRng};
use rand_distr::StandardNormal;

use crate::helper::When::*;

mod helper;

#[test]
fn multiple_too_close_invalid() {
    let samples = 100;
    let relative_radius = 0.8;
    let prefiller = |radius| {
        let mut last = None;
        let mut rand = SmallRng::from_seed([
            1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
        ]);
        move |v| {
            if let Some(_) = v {
                if last == v {
                    None
                } else {
                    last = v;
                    let vec = sphere_uniform_point(&mut rand);
                    v.map(|v| v + vec * rand.gen::<f32>() * radius)
                }
            } else {
                None
            }
        }
    };
    // TODO: At 10 the test suddenly takes forever and takes all of the memory resulting into getting killed by oom killer
    helper::test_with_samples_prefilled(
        samples,
        relative_radius,
        5,
        Type::Normal,
        prefiller,
        Never,
    );
}

pub fn sphere_uniform_point<R: Rng>(rng: &mut R) -> Vec2 {
    let mut result = Vec2::zero();
    for c in 0..2 {
        result[c] = rng.sample(StandardNormal);
    }
    result.normalize()
}