summaryrefslogtreecommitdiff
path: root/src/lerp/poly/iter.rs
diff options
context:
space:
mode:
authorJuan Manuel Tomás <jtomas1815@gmail.com>2021-01-17 20:14:18 -0300
committerJuan Manuel Tomás <jtomas1815@gmail.com>2021-01-17 20:14:18 -0300
commit7141f388113f7ac0c8e8718826dd821fd6607434 (patch)
tree04acfd7b5f84d9344964bfb102617c611e1cd7fa /src/lerp/poly/iter.rs
parentb25771270f0fd1fe20432ce2c1a671a04bb57a50 (diff)
downloadbezier-7141f388113f7ac0c8e8718826dd821fd6607434.tar.gz
bezier-7141f388113f7ac0c8e8718826dd821fd6607434.zip
Render control points
Diffstat (limited to 'src/lerp/poly/iter.rs')
-rw-r--r--src/lerp/poly/iter.rs38
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)
+ }
+ }
+}