diff options
author | Juan Manuel Tomás <jtomas1815@gmail.com> | 2021-01-19 09:06:32 -0300 |
---|---|---|
committer | Juan Manuel Tomás <jtomas1815@gmail.com> | 2021-01-19 09:15:02 -0300 |
commit | 4998f5936dc7da36aba0cd018de2a1a6127dda08 (patch) | |
tree | 1363045387c3730d33fbed10f682662e3a635860 /src/poly | |
parent | be18a9a0503fa09318b5d99452a3407a92db4366 (diff) | |
download | bezier-4998f5936dc7da36aba0cd018de2a1a6127dda08.tar.gz bezier-4998f5936dc7da36aba0cd018de2a1a6127dda08.zip |
Make shader sample intervals uniform
Diffstat (limited to 'src/poly')
-rw-r--r-- | src/poly/iter.rs | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/src/poly/iter.rs b/src/poly/iter.rs new file mode 100644 index 0000000..90cc4b5 --- /dev/null +++ b/src/poly/iter.rs @@ -0,0 +1,38 @@ +use std::cmp; +use std::iter::{Take, Zip}; + +pub struct Iter { + index: usize, + data: Vec<f32>, + degree: usize, +} + +impl Iter { + pub fn new(data: Vec<f32>, degree: usize) -> Iter { + Iter { + index: 0, + data, + degree, + } + } + + pub fn zip(self, other: Self) -> Zip<Take<Iter>, Take<Iter>> { + let deg = cmp::max(self.degree, other.degree) + 1; + let a = self.take(deg); + let b = other.take(deg); + a.zip(b) + } +} + +impl Iterator for Iter { + type Item = f32; + + fn next(&mut self) -> Option<f32> { + self.index += 1; + if self.index <= self.data.len() { + Some(self.data[self.index - 1]) + } else { + Some(0.0) + } + } +} |