mod lerp; use lerp::Lerp; use lerp::poly::Poly; pub struct Bezier { pub vx: Vec, pub vy: Vec, pub px: Poly, pub py: Poly, pub degree: usize } impl Bezier { pub fn new() -> Bezier { Bezier { vx: Vec::::new(), vy: Vec::::new(), px: Poly::new(vec![]), py: Poly::new(vec![]), degree: 0, } } pub fn push(&mut self, x: i32, y: i32) { self.vx.push(x as f32); self.vy.push(y as f32); self.px = Lerp::new(self.vx.clone()).to_poly(); self.py = Lerp::new(self.vy.clone()).to_poly(); self.degree += 1; } pub fn remove(&mut self, index: usize) { self.vx.remove(index); self.vy.remove(index); self.px = Lerp::new(self.vx.clone()).to_poly(); self.py = Lerp::new(self.vy.clone()).to_poly(); self.degree -= 1; } pub fn show_x(&self) -> String{ let mut s = String::new(); for i in 0..self.degree { s.push_str(&self.vx[i].to_string()); if i < self.degree - 1 { s.push_str(", "); } } s } pub fn show_y(&self) -> String { let mut s = String::new(); for i in 0..self.degree { s.push_str(&self.vy[i].to_string()); if i < self.degree - 1 { s.push_str(", "); } } s } }