Implement bezier library's De Casteljau points function (#715)

* pre-rebase

* broken wasm

* hull lines

* update rust lib description

* update comments, handle match statement better, pass Point type to vue

* cleanup

* add linear case

* More idiomatic code

* Further simplifications to the algorithm and removal of more heap allocations

* Rename to de_casteljau_points and use colors for the iterations

* Small comment changes

* Improve colors

Co-authored-by: Jackie Chen <jackiechen73>
Co-authored-by: Keavon Chambers <keavon@keavon.com>
Co-authored-by: Hannah Li <hannahli2010@gmail.com>
This commit is contained in:
Jackie Chen
2022-07-27 00:35:43 -04:00
committed by Keavon Chambers
co-authored by Jackie Chen Keavon Chambers Hannah Li
parent dc0b38750c
commit 004c2aeff6
3 changed files with 57 additions and 0 deletions
@@ -138,4 +138,14 @@ impl WasmBezier {
let bezier_points: Vec<Vec<Point>> = self.0.reduce(None).into_iter().map(bezier_to_points).collect();
to_js_value(bezier_points)
}
pub fn de_casteljau_points(&self, t: f64) -> JsValue {
let hull = self
.0
.de_casteljau_points(t)
.iter()
.map(|level| level.iter().map(|&point| Point { x: point.x, y: point.y }).collect::<Vec<Point>>())
.collect::<Vec<Vec<Point>>>();
to_js_value(hull)
}
}