mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-29 07:28:11 +08:00
Handle intersections between two bezier curves (#735)
* Refactor intersections function * Implement intersect for quadratic and cubic bezier curves * Return t value instead of point * Change project return the t value * Add error threshold for curve intersection * Refactor to use if let statements and improve comments * Refactor intersection helper to return vector, other minor name/text changes * Rename function * Minor change * Minor fixes * Add missing test tag * Address comments * Adjust comment * Change function call * Edit comments
This commit is contained in:
committed by
Keavon Chambers
parent
8c1e6455eb
commit
c00f520351
@@ -119,8 +119,8 @@ impl WasmBezier {
|
||||
WasmBezier(self.0.trim(t1, t2))
|
||||
}
|
||||
|
||||
pub fn project(&self, x: f64, y: f64) -> JsValue {
|
||||
vec_to_point(&self.0.project(DVec2::new(x, y), ProjectionOptions::default()))
|
||||
pub fn project(&self, x: f64, y: f64) -> f64 {
|
||||
self.0.project(DVec2::new(x, y), ProjectionOptions::default())
|
||||
}
|
||||
|
||||
pub fn local_extrema(&self) -> JsValue {
|
||||
@@ -152,9 +152,26 @@ impl WasmBezier {
|
||||
WasmBezier(self.0.rotate(angle))
|
||||
}
|
||||
|
||||
pub fn intersect_line_segment(&self, js_points: &JsValue) -> Vec<JsValue> {
|
||||
let line: [DVec2; 2] = js_points.into_serde().unwrap();
|
||||
self.0.intersect_line_segment(line).iter().map(|&p| vec_to_point(&p)).collect::<Vec<JsValue>>()
|
||||
fn intersect(&self, curve: &Bezier, error: Option<f64>) -> Vec<f64> {
|
||||
self.0.intersections(curve, error)
|
||||
}
|
||||
|
||||
pub fn intersect_line_segment(&self, js_points: &JsValue) -> Vec<f64> {
|
||||
let points: [DVec2; 2] = js_points.into_serde().unwrap();
|
||||
let line = Bezier::from_linear_dvec2(points[0], points[1]);
|
||||
self.intersect(&line, None)
|
||||
}
|
||||
|
||||
pub fn intersect_quadratic_segment(&self, js_points: &JsValue, error: f64) -> Vec<f64> {
|
||||
let points: [DVec2; 3] = js_points.into_serde().unwrap();
|
||||
let quadratic = Bezier::from_quadratic_dvec2(points[0], points[1], points[2]);
|
||||
self.intersect(&quadratic, Some(error))
|
||||
}
|
||||
|
||||
pub fn intersect_cubic_segment(&self, js_points: &JsValue, error: f64) -> Vec<f64> {
|
||||
let points: [DVec2; 4] = js_points.into_serde().unwrap();
|
||||
let cubic = Bezier::from_cubic_dvec2(points[0], points[1], points[2], points[3]);
|
||||
self.intersect(&cubic, Some(error))
|
||||
}
|
||||
|
||||
pub fn reduce(&self) -> JsValue {
|
||||
|
||||
Reference in New Issue
Block a user