Implement self-intersection function for Beziers (#740)

* Initial commit and refactor reduce

* Refactor reduce to get t values

* Implement self intersection

* Return pairs of t values

* Fix results for the case where self is linear and other is not, address other comments

* Update a rustdoc comment

* Address final PR comments
This commit is contained in:
Hannah Li
2022-07-31 22:46:33 -04:00
committed by Keavon Chambers
parent c00f520351
commit a9b63f2a4c
3 changed files with 211 additions and 51 deletions
@@ -174,6 +174,12 @@ impl WasmBezier {
self.intersect(&cubic, Some(error))
}
/// The wrapped return type is `Vec<[f64; 2]>`.
pub fn intersect_self(&self, error: f64) -> JsValue {
let points: Vec<[f64; 2]> = self.0.self_intersections(Some(error));
to_js_value(points)
}
pub fn reduce(&self) -> JsValue {
let bezier_points: Vec<Vec<Point>> = self.0.reduce(None).into_iter().map(bezier_to_points).collect();
to_js_value(bezier_points)