pub struct Sampler<T: Copy, R: Rng> { /* private fields */ }Expand description
Wrapper for a bounded stocastically sampled value
a Sampler encloses the distribution function and bounds for a random
variable of type T, such that is can be sampled with an external random
number generator of type R
Several constructors are provided for common distributions of values, however
if a custom one is needed it can be provided as a closure and set of bounds to
Sampler::from_fn
Implementations§
Source§impl<T, R> Sampler<T, R>
impl<T, R> Sampler<T, R>
Sourcepub fn new_gaussian<A, B>(mean: A, std_dev: B) -> Self
pub fn new_gaussian<A, B>(mean: A, std_dev: B) -> Self
Creates a new Sampler with a normal (gaussian) distibution.
Real gaussian’s have infinate bounds, this can cause problems in the raytracing engine, so this implementation wraps at 3 standard deviations.
When sampled the Sampler will always return a value between mean - 3 * std_dev and mean + 3 * std_dev (inclusive)
Source§impl<T, R> Sampler<T, R>
impl<T, R> Sampler<T, R>
Sourcepub fn new_blackbody<A>(temperature: A) -> Selfwhere
A: Into<T>,
pub fn new_blackbody<A>(temperature: A) -> Selfwhere
A: Into<T>,
Creates a new Sampler with a blackbody radiation curve distibution.
This is only really useful for creating realistic white lights of a given colour temprature, or stars.
This sampler should be used carefully; it can lead to unexpected results when used on a value other than Light.wavelength.
It is also substancially slower than the other Sampler types. When Sampled it will return a value between
0 and T::MAX (probably larger than you want) This can cause all sorts of weird problems for collision detection, so please
don’t use this on a SamplerPoint
Source§impl<T, R> Sampler<T, R>
impl<T, R> Sampler<T, R>
Sourcepub fn from_fn(
f: Arc<dyn Fn(&mut R) -> T + Send + Sync>,
lower: T,
upper: T,
) -> Self
pub fn from_fn( f: Arc<dyn Fn(&mut R) -> T + Send + Sync>, lower: T, upper: T, ) -> Self
Creates a new Sampler with a distribution dictated by f
f must always return a value within the bounds specified by lower & upper
This is very low level access to how the renderer works; you’re in control, if you break it it’s your fault!
Trait Implementations§
Source§impl<T, R> From<(T, T)> for Sampler<T, R>
A tuple of type (T,T) will be interpreted as a uniform distribution if turned into a sampler.
impl<T, R> From<(T, T)> for Sampler<T, R>
A tuple of type (T,T) will be interpreted as a uniform distribution if turned into a sampler.
§Example:
extern crate rand;
use rustic_zen::sampler::Sampler;
use rand::prelude::*;
let mut r = rand::thread_rng();
let s: Sampler<f64, ThreadRng> = (5.0,10.0).into();
assert!(s.sample(&mut r) >= 5.0); // will always be true
assert!(s.sample(&mut r) <= 10.0); // will always be trueSource§impl<T, R> From<T> for Sampler<T, R>
A single value of type T will be interpreted as a constant distribution if turned into a sampler.
impl<T, R> From<T> for Sampler<T, R>
A single value of type T will be interpreted as a constant distribution if turned into a sampler.
§Example:
extern crate rand;
use rustic_zen::sampler::Sampler;
use rand::prelude::*;
let mut r = rand::thread_rng();
let s: Sampler<f64, ThreadRng> = 5.0.into();
assert_eq!(s.sample(&mut r), 5.0); // will always be trueAuto Trait Implementations§
impl<T, R> Freeze for Sampler<T, R>where
T: Freeze,
impl<T, R> !RefUnwindSafe for Sampler<T, R>
impl<T, R> Send for Sampler<T, R>where
T: Send,
impl<T, R> Sync for Sampler<T, R>where
T: Sync,
impl<T, R> Unpin for Sampler<T, R>where
T: Unpin,
impl<T, R> !UnwindSafe for Sampler<T, R>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more