From 4998f5936dc7da36aba0cd018de2a1a6127dda08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Manuel=20Tom=C3=A1s?= Date: Tue, 19 Jan 2021 09:06:32 -0300 Subject: Make shader sample intervals uniform --- src/lib.rs | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) (limited to 'src/lib.rs') diff --git a/src/lib.rs b/src/lib.rs index cadef3c..6f26672 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,14 +1,17 @@ mod lerp; +mod poly; use lerp::Lerp; -use lerp::poly::Poly; +use poly::Poly; pub struct Bezier { + pub degree: usize, pub vx: Vec, pub vy: Vec, pub px: Poly, pub py: Poly, - pub degree: usize + pub dpx: Poly, + pub dpy: Poly } impl Bezier { @@ -18,6 +21,8 @@ impl Bezier { vy: Vec::::new(), px: Poly::new(vec![]), py: Poly::new(vec![]), + dpy: Poly::new(vec![]), + dpx: Poly::new(vec![]), degree: 0, } } @@ -25,16 +30,20 @@ impl Bezier { 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.px = Lerp::new(&self.vx).to_poly(); + self.py = Lerp::new(&self.vy).to_poly(); + self.dpx = self.px.deriv(); + self.dpy = self.py.deriv(); 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.px = Lerp::new(&self.vx).to_poly(); + self.py = Lerp::new(&self.vy).to_poly(); + self.dpx = self.px.deriv(); + self.dpy = self.py.deriv(); self.degree -= 1; } -- cgit v1.2.3