Struct fast_poisson::Poisson [−][src]
pub struct Poisson<const N: usize> { /* fields omitted */ }
Poisson disk distribution in N dimensions
Distributions can be generated for any non-negative number of dimensions, although performance depends upon the volume of the space: for higher-order dimensions you may need to increase the radius to achieve the desired level of performance.
Equality
Poisson
implements PartialEq
but not Eq
, because without a specified seed the output of
even the same object will be different. That is, the equality of two Poisson
s is based not on
whether or not they were built with the same parameters, but rather on whether or not they will
produce the same results once the distribution is generated.
Implementations
impl<const N: usize> Poisson<N>
[src]
impl<const N: usize> Poisson<N>
[src]#[must_use]pub fn new() -> Self
[src]
#[must_use]pub fn new() -> Self
[src]Create a new Poisson disk distribution
By default, Poisson
will sample each dimension from the semi-open range [0.0, 1.0), using
a radius of 0.1 around each point, and up to 30 random samples around each; the resulting
output will be non-deterministic, meaning it will be different each time.
See Poisson::with_dimensions
to change the range and radius, Poisson::with_samples
to change the number of random samples for each point, and Poisson::with_seed
to produce
repeatable results.
pub fn with_dimensions(
&mut self,
dimensions: [f64; N],
radius: f64
) -> &mut Self
[src]
pub fn with_dimensions(
&mut self,
dimensions: [f64; N],
radius: f64
) -> &mut Self
[src]Specify the space to be filled and the radius around each point
To generate a 2-dimensional distribution in a 5×5 square, with no points closer than 1:
let mut points = Poisson2D::new().with_dimensions([5.0, 5.0], 1.0).iter(); assert!(points.all(|p| p[0] >= 0.0 && p[0] < 5.0 && p[1] >= 0.0 && p[1] < 5.0));
To generate a 3-dimensional distribution in a 3×3×5 prism, with no points closer than 0.75:
let mut points = Poisson3D::new().with_dimensions([3.0, 3.0, 5.0], 0.75).iter(); assert!(points.all(|p| { p[0] >= 0.0 && p[0] < 3.0 && p[1] >= 0.0 && p[1] < 3.0 && p[2] >= 0.0 && p[2] < 5.0 }));
pub fn with_seed(&mut self, seed: u64) -> &Self
[src]
pub fn with_seed(&mut self, seed: u64) -> &Self
[src]Specify the PRNG seed for this distribution
If no seed is specified then the internal PRNG will be seeded from entropy, providing non-deterministic and non-repeatable results.
let points = Poisson2D::new().with_seed(0xBADBEEF).iter();
pub fn with_samples(&mut self, samples: u32) -> &Self
[src]
pub fn with_samples(&mut self, samples: u32) -> &Self
[src]Specify the maximum samples to generate around each point
Note that this is not specifying the number of samples in the resulting distribution, but rather sets the maximum number of attempts to find a new, valid point around an existing point for each iteration of the algorithm.
A higher number may result in better space filling, but may also slow down generation.
let points = Poisson3D::new().with_samples(40).iter();
#[must_use]pub fn iter(&self) -> Iter<N>ⓘ
[src]
#[must_use]pub fn iter(&self) -> Iter<N>ⓘ
[src]Returns an iterator over the points in this distribution
let points = Poisson3D::new(); for point in points.iter() { println!("{:?}", point); }
pub fn generate(&self) -> Vec<Point<N>>
[src]
pub fn generate(&self) -> Vec<Point<N>>
[src]Generate the points in this Poisson distribution, collected into a Vec
.
Note that this method does not consume the Poisson
, so you can call it multiple times
to generate multiple Vec
s; if you have specified a seed, each one will be identical,
whereas they will each be unique if you have not (see Poisson::with_seed
).
let mut poisson = Poisson2D::new(); let points1 = poisson.generate(); let points2 = poisson.generate(); // These are not identical because no seed was specified assert!(points1.iter().zip(points2.iter()).any(|(a, b)| a != b)); poisson.with_seed(1337); let points3 = poisson.generate(); let points4 = poisson.generate(); // These are identical because a seed was specified assert!(points3.iter().zip(points4.iter()).all(|(a, b)| a == b));
pub fn to_vec<T>(&self) -> Vec<T> where
T: From<[f64; N]>,
[src]
pub fn to_vec<T>(&self) -> Vec<T> where
T: From<[f64; N]>,
[src]Generate the points in the Poisson distribution, as a Vec<T>
.
This is a shortcut to translating the arrays normally generated into arbitrary types,
with the precondition that the type T
must implement the From
trait. This is otherwise
identical to the generate
method.
struct Point { x: f64, y: f64, } impl From<[f64; 2]> for Point { fn from(point: [f64; 2]) -> Point { Point { x: point[0], y: point[1], } } } let points: Vec<Point> = Poisson2D::new().to_vec();
Trait Implementations
impl<const N: usize> IntoIterator for Poisson<N>
[src]
impl<const N: usize> IntoIterator for Poisson<N>
[src]impl<const N: usize> IntoIterator for &Poisson<N>
[src]
impl<const N: usize> IntoIterator for &Poisson<N>
[src]Auto Trait Implementations
impl<const N: usize> RefUnwindSafe for Poisson<N>
impl<const N: usize> Send for Poisson<N>
impl<const N: usize> Sync for Poisson<N>
impl<const N: usize> Unpin for Poisson<N>
impl<const N: usize> UnwindSafe for Poisson<N>
Blanket Implementations
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]pub fn borrow_mut(&mut self) -> &mut T
[src]
pub fn borrow_mut(&mut self) -> &mut T
[src]Mutably borrows from an owned value. Read more
impl<T> ToOwned for T where
T: Clone,
[src]
impl<T> ToOwned for T where
T: Clone,
[src]type Owned = T
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn to_owned(&self) -> T
[src]Creates owned data from borrowed data, usually by cloning. Read more
pub fn clone_into(&self, target: &mut T)
[src]
pub fn clone_into(&self, target: &mut T)
[src]🔬 This is a nightly-only experimental API. (toowned_clone_into
)
recently added
Uses borrowed data to replace owned data, usually by cloning. Read more
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
impl<V, T> VZip<V> for T where
V: MultiLane<T>,