Crate fast_poisson[−][src]
Generate a Poisson disk distribution.
This is an implementation of Bridson’s “Fast Poisson Disk Sampling” algorithm. At present, however, this library only implements it for 2 dimensions.
Examples
To generate a simple Poisson disk pattern in the range (0, 1] for each of the x and y dimensions:
use fast_poisson::Poisson; let points = Poisson::new().iter();
To fill a box, specify the width and height:
use fast_poisson::Poisson; let poisson = Poisson { width: 100.0, height: 100.0, radius: 5.0, ..Default::default() }; let points = poisson.iter();
Caution: If you specify a box size much larger than 1x1, you should specify a radius as well. Otherwise the resulting distribution may have far more points than you are prepared to handle, and may take longer to generate than expected.
Because iter
returns an iterator, you have access to the full power of Rust
iterator methods to further manipulate the results:
use fast_poisson::Poisson; struct Point { x: f64, y: f64, } // Map the Poisson disk tuples to our `Point` struct let points = Poisson::new().iter().map(|(x, y)| Point { x, y });
Additionally, the iterator is lazily evaluated, meaning that points are only generated as needed:
use fast_poisson::Poisson; // Only 5 points from the distribution are actually generated! let points = Poisson::new().iter().take(5);
You can even use Poisson
directly within a for
loop!
use fast_poisson::Poisson; for point in Poisson::new() { println!("X: {}; Y: {}", point.0, point.1); }
Structs
Poisson | Builder for a Poisson disk distribution |
PoissonIter | An iterator over the points in the Poisson disk distribution |