mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-25 19:28:12 +08:00
Implement functions to create a Bezier that goes through 3 specified points (#687)
* Implement quadratic and cubic from points * Catch edge cases and integrate `t` slider * Add 2 sliders for cubic * Create utils file for bezier-rs and address other PR comments * Rename variable and remove unnecessary ids * Update rustdoc comments and rename variables * Remove unnecessary file and refactor options for drawing beziers * Address PR comments * Update quadratic_through_points description * Add wasm-pack to dependencies and change from spaces to tabs for indents * Change strut to midpoint_separation, adjust sliders and section name * Minor refactor
This commit is contained in:
committed by
Keavon Chambers
parent
4eaffd0e5a
commit
2e3e079982
@@ -22,7 +22,7 @@ pub fn vec_to_point(p: &DVec2) -> JsValue {
|
||||
#[wasm_bindgen]
|
||||
impl WasmBezier {
|
||||
/// Expect js_points to be a list of 3 pairs
|
||||
pub fn new_quad(js_points: &JsValue) -> WasmBezier {
|
||||
pub fn new_quadratic(js_points: &JsValue) -> WasmBezier {
|
||||
let points: [DVec2; 3] = js_points.into_serde().unwrap();
|
||||
WasmBezier(Bezier::from_quadratic_dvec2(points[0], points[1], points[2]))
|
||||
}
|
||||
@@ -33,6 +33,16 @@ impl WasmBezier {
|
||||
WasmBezier(Bezier::from_cubic_dvec2(points[0], points[1], points[2], points[3]))
|
||||
}
|
||||
|
||||
pub fn quadratic_through_points(js_points: &JsValue, t: f64) -> WasmBezier {
|
||||
let points: [DVec2; 3] = js_points.into_serde().unwrap();
|
||||
WasmBezier(Bezier::quadratic_through_points(points[0], points[1], points[2], t))
|
||||
}
|
||||
|
||||
pub fn cubic_through_points(js_points: &JsValue, t: f64, midpoint_separation: f64) -> WasmBezier {
|
||||
let points: [DVec2; 3] = js_points.into_serde().unwrap();
|
||||
WasmBezier(Bezier::cubic_through_points(points[0], points[1], points[2], t, midpoint_separation))
|
||||
}
|
||||
|
||||
pub fn set_start(&mut self, x: f64, y: f64) {
|
||||
self.0.set_start(DVec2::new(x, y));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user