aboutsummaryrefslogtreecommitdiff
path: root/src/sample
diff options
context:
space:
mode:
authorJulian T <julian@jtle.dk>2021-08-05 15:44:40 +0200
committerJulian T <julian@jtle.dk>2021-08-05 15:44:40 +0200
commit3ef8f4d918406eec6bdc29e0ebd883fabfac9b2e (patch)
treeaa4b1aac1e165821c16f222ebfb9212a9740e98b /src/sample
parent45119506c0293fdde6cef35f6e6f82d4055b46b6 (diff)
Add picture for c5505ab84820248c6dba35fc06aef9e0ced183derendered
Diffstat (limited to 'src/sample')
-rw-r--r--src/sample/mod.rs46
-rw-r--r--src/sample/uniform.rs39
2 files changed, 0 insertions, 85 deletions
diff --git a/src/sample/mod.rs b/src/sample/mod.rs
deleted file mode 100644
index 1a53921..0000000
--- a/src/sample/mod.rs
+++ /dev/null
@@ -1,46 +0,0 @@
-use crate::{M_PI, Float};
-use crate::core::{Vector3f, Vector2f};
-
-mod uniform;
-
-pub use uniform::UniformSampler;
-
-fn distribute_between(x: Float, a: Float, b: Float) -> Float {
- x * (b - a) + a
-}
-
-pub trait Sampler {
- fn get_sample(&mut self) -> Float;
-
- fn get_sample_2d(&mut self) -> Vector2f {
- Vector2f::new_xy(self.get_sample(), self.get_sample())
- }
-
- fn clone_and_seed(&mut self) -> Box<dyn Sampler + Send>;
-
- fn get_unit_vector(&mut self) -> Vector3f {
- let s2d = self.get_sample_2d();
-
- let lambda = distribute_between(s2d.x, -M_PI, M_PI);
- let costheta = 2.0 * s2d.y - 1.0;
- let sintheta = costheta.acos().sin();
-
- Vector3f::new_xyz(
- lambda.cos() * sintheta,
- lambda.sin() * sintheta,
- costheta,
- )
- }
-
- fn get_in_circle(&mut self) -> Vector2f {
- let s2d = self.get_sample_2d();
-
- let d = s2d.x.sqrt();
- let theta = s2d.y * 2.0 * M_PI;
-
- Vector2f::new_xy(
- d * theta.cos(),
- d * theta.sin(),
- )
- }
-}
diff --git a/src/sample/uniform.rs b/src/sample/uniform.rs
deleted file mode 100644
index c144f27..0000000
--- a/src/sample/uniform.rs
+++ /dev/null
@@ -1,39 +0,0 @@
-use crate::Float;
-use super::Sampler;
-
-use rand::prelude::*;
-use rand::distributions::Uniform;
-use rand_pcg::Pcg32;
-
-#[derive(Clone)]
-pub struct UniformSampler {
- r: Pcg32,
- d: Uniform<Float>,
-}
-
-impl UniformSampler {
- pub fn new() -> Self {
- Self::default()
- }
-}
-
-impl Default for UniformSampler {
- fn default() -> Self {
- Self {
- r: Pcg32::seed_from_u64(1),
- d: Uniform::new(0.0, 1.0),
- }
- }
-}
-
-impl Sampler for UniformSampler {
- fn get_sample(&mut self) -> Float {
- self.d.sample(&mut self.r)
- }
-
- fn clone_and_seed(&mut self) -> Box<dyn Sampler + Send> {
- let mut n = self.clone();
- n.r = Pcg32::seed_from_u64(self.r.next_u64());
- Box::new(n)
- }
-}