Struct rustic_zen::sampler::Sampler
source · 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>
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 true
source§impl<T, R> From<T> for Sampler<T, R>
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 true