diff options
Diffstat (limited to 'src/lerp/poly/iter.rs')
-rw-r--r-- | src/lerp/poly/iter.rs | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/src/lerp/poly/iter.rs b/src/lerp/poly/iter.rs new file mode 100644 index 0000000..90cc4b5 --- /dev/null +++ b/src/lerp/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) + } + } +} |