summaryrefslogtreecommitdiff
path: root/src/lib.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib.rs')
-rw-r--r--src/lib.rs21
1 files changed, 15 insertions, 6 deletions
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<f32>,
pub vy: Vec<f32>,
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::<f32>::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;
}