diff options
author | Juan Manuel Tomás <jtomas1815@gmail.com> | 2021-01-10 19:54:34 -0300 |
---|---|---|
committer | Juan Manuel Tomás <jtomas1815@gmail.com> | 2021-01-10 19:54:34 -0300 |
commit | 7fa34698ba8ee80227fa0b8eaab7a7382a5cf465 (patch) | |
tree | 2a2b8bbfd2de5c93744629e0a16bc82f53e63273 /src/lerp.rs | |
parent | 6d356f0c681cb2bb0f26d848ed467f65c49769a5 (diff) | |
download | bezier-7fa34698ba8ee80227fa0b8eaab7a7382a5cf465.tar.gz bezier-7fa34698ba8ee80227fa0b8eaab7a7382a5cf465.zip |
Separate project into modules
Diffstat (limited to 'src/lerp.rs')
-rw-r--r-- | src/lerp.rs | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/src/lerp.rs b/src/lerp.rs new file mode 100644 index 0000000..7c4994c --- /dev/null +++ b/src/lerp.rs @@ -0,0 +1,33 @@ +use crate::poly::{self, Number, Poly}; + +pub enum Lerp { + Node(Box<Lerp>, Box<Lerp>), + Leaf(Number, Number) +} + +impl Lerp { + pub fn new(v: Vec<Number>) -> Box<Lerp> { + Lerp::new_s(&v[..]) + } + + fn new_s(v: &[Number]) -> Box<Lerp> { + match v.len() { + 0 => Box::new(Lerp::Leaf(0.0, 0.0)), + 1 => Box::new(Lerp::Leaf(v[0], v[0])), + 2 => Box::new(Lerp::Leaf(v[0], v[1])), + _ => Box::new(Lerp::Node(Lerp::new_s(&v[0..v.len() - 1]), Lerp::new_s(&v[1..v.len()]))) + } + } +} + +pub fn lp(l: Box<Lerp>) -> Poly { + match *l { + Lerp::Leaf(a, b) => vec![a, b - a], + Lerp::Node(a, b) => { + let a = lp(a); + let b = lp(b); + let c = poly::sub(&b, &a); + poly::skewed_sum(a, c) + } + } +} |