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 Poissons 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]

#[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]

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]

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]

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>

Notable traits for Iter<N>

impl<const N: usize> Iterator for Iter<N> type Item = Point<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]

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 Vecs; 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]

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> Clone for Poisson<N>[src]

fn clone(&self) -> Poisson<N>[src]

Returns a copy of the value. Read more

fn clone_from(&mut self, source: &Self)1.0.0[src]

Performs copy-assignment from source. Read more

impl<const N: usize> Debug for Poisson<N>[src]

fn fmt(&self, f: &mut Formatter<'_>) -> Result[src]

Formats the value using the given formatter. Read more

impl<const N: usize> Default for Poisson<N>[src]

fn default() -> Self[src]

Returns the “default value” for a type. Read more

impl<const N: usize> IntoIterator for Poisson<N>[src]

type Item = Point<N>

The type of the elements being iterated over.

type IntoIter = Iter<N>

Which kind of iterator are we turning this into?

fn into_iter(self) -> Self::IntoIter[src]

Creates an iterator from a value. Read more

impl<const N: usize> IntoIterator for &Poisson<N>[src]

type Item = Point<N>

The type of the elements being iterated over.

type IntoIter = Iter<N>

Which kind of iterator are we turning this into?

fn into_iter(self) -> Self::IntoIter[src]

Creates an iterator from a value. Read more

impl<const N: usize> PartialEq<Poisson<N>> for Poisson<N>[src]

No object is equal, not even to itself, if the seed is unspecified

fn eq(&self, other: &Self) -> bool[src]

This method tests for self and other values to be equal, and is used by ==. Read more

#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests for !=.

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> Any for T where
    T: 'static + ?Sized
[src]

pub fn type_id(&self) -> TypeId[src]

Gets the TypeId of self. Read more

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

pub fn borrow(&self) -> &T[src]

Immutably borrows from an owned value. Read more

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

pub fn borrow_mut(&mut self) -> &mut T[src]

Mutably borrows from an owned value. Read more

impl<T> From<T> for T[src]

pub fn from(t: T) -> T[src]

Performs the conversion.

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

pub fn into(self) -> U[src]

Performs the conversion.

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

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]

🔬 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<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]

Performs the conversion.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>[src]

Performs the conversion.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>, 

pub fn vzip(self) -> V