use crate::number::Number; use crate::poly::Poly; pub enum Lerp { Node(Box, Box), Leaf(Number, Number), } impl Lerp { pub fn new(v: Vec) -> Box { Lerp::new_s(&v[..]) } fn new_s(v: &[Number]) -> Box { 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) -> Poly { match *l { Lerp::Leaf(a, b) => Poly::new(vec![a, b - a]), Lerp::Node(a, b) => { let a = lp(a); let b = lp(b); let c = &b - &a; &a + &(&c * &Poly::new(vec![0.0, 1.0])) } } }