utils
parent
99dddfde57
commit
c35df147be
|
@ -34,3 +34,35 @@ impl Iterator for Halton {
|
|||
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)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue