Implement function to find intersections between a Bezier and a linear line (#708)

* Implement line intersection for quadratics, begin work for cubic

* Implement line intersection for cubic beziers, add tests for cubic root finding

* Rename function and update comments

* Minor refactor and adjust comments

* Address PR comments
This commit is contained in:
Hannah Li
2022-07-04 19:29:25 -04:00
committed by Keavon Chambers
parent a6c91204d6
commit 3c2fff4465
4 changed files with 322 additions and 12 deletions
@@ -107,4 +107,13 @@ impl WasmBezier {
let local_extrema = self.0.local_extrema();
JsValue::from_serde(&serde_json::to_string(&local_extrema).unwrap()).unwrap()
}
pub fn rotate(&self, angle: f64) -> WasmBezier {
WasmBezier(self.0.rotate(angle))
}
pub fn line_intersection(&self, js_points: &JsValue) -> Vec<JsValue> {
let line: [DVec2; 2] = js_points.into_serde().unwrap();
self.0.line_intersection(line).iter().map(|&p| vec_to_point(&p)).collect::<Vec<JsValue>>()
}
}