diff options
author | Juan Manuel Tomás <jtomas1815@gmail.com> | 2021-01-11 19:44:07 -0300 |
---|---|---|
committer | Juan Manuel Tomás <jtomas1815@gmail.com> | 2021-01-11 19:44:07 -0300 |
commit | 1891436bf1d6b18f1dded15ae693f90f8a6ab975 (patch) | |
tree | 0042eb0075f0b684bd7b1ecc6a4bd4f54f5440ab /src/poly | |
parent | 857b9974b7a8e89016357cc91ca4a37561ead7be (diff) | |
download | bezier-1891436bf1d6b18f1dded15ae693f90f8a6ab975.tar.gz bezier-1891436bf1d6b18f1dded15ae693f90f8a6ab975.zip |
Move zip implementation from poly to poly/iter
Zip seems more appropriate on an iterator.
Diffstat (limited to 'src/poly')
-rw-r--r-- | src/poly/iter.rs | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/src/poly/iter.rs b/src/poly/iter.rs index 26c5989..abc7462 100644 --- a/src/poly/iter.rs +++ b/src/poly/iter.rs @@ -1,13 +1,23 @@ use crate::number::Number; +use std::cmp; +use std::iter::{Zip, Take}; pub struct Iter { index: usize, - data: Vec<Number> + data: Vec<Number>, + degree: usize } impl Iter { - pub fn new(data: Vec<Number>) -> Iter { - Iter { index: 0, data } + pub fn new(data: Vec<Number>, 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) } } |