main
annieversary 2021-08-24 20:46:57 +02:00
parent 99dddfde57
commit c35df147be
1 changed files with 32 additions and 0 deletions

View File

@ -34,3 +34,35 @@ impl Iterator for Halton {
Some(r) Some(r)
} }
} }
pub struct VanDerCorput {
i: usize,
base: f32,
}
impl VanDerCorput {
pub fn new(base: f32) -> Self {
Self { i: 0, base }
}
pub fn points(base1: f32, base2: f32) -> impl Iterator<Item = Vec2> {
Self::new(base1)
.zip(Self::new(base2))
.map(crate::Tup2Extension::to_vec2)
}
}
impl Iterator for VanDerCorput {
type Item = f32;
fn next(&mut self) -> Option<Self::Item> {
let mut q = 0.0;
let mut bk = 1.0 / self.base;
let mut i = self.i as f32;
while i > 0.0 {
q += (i % self.base) * bk;
i /= self.base;
bk /= self.base;
}
Some(q)
}
}