From 7141f388113f7ac0c8e8718826dd821fd6607434 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Manuel=20Tom=C3=A1s?= Date: Sun, 17 Jan 2021 20:14:18 -0300 Subject: Render control points --- src/lerp/poly/iter.rs | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 src/lerp/poly/iter.rs (limited to 'src/lerp/poly/iter.rs') 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, + degree: usize, +} + +impl Iter { + pub fn new(data: Vec, degree: usize) -> Iter { + Iter { + index: 0, + data, + degree, + } + } + + pub fn zip(self, other: Self) -> Zip, Take> { + 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 { + self.index += 1; + if self.index <= self.data.len() { + Some(self.data[self.index - 1]) + } else { + Some(0.0) + } + } +} -- cgit v1.2.3