mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-10-10 00:30:55 +08:00
Bezier-rs: Add project function for Subpaths (#914)
* Added subpath project function * Set appropriate project default in single manipulator group case * Lint * Return optional from subpath project + stylistic changes per review Co-authored-by: Keavon Chambers <keavon@keavon.com>
This commit is contained in:
committed by
Keavon Chambers
co-authored by
Keavon Chambers
parent
0d703e857b
commit
72cd204c64
@@ -1,6 +1,6 @@
|
||||
use crate::svg_drawing::*;
|
||||
|
||||
use bezier_rs::{Bezier, ComputeType, ManipulatorGroup, Subpath};
|
||||
use bezier_rs::{Bezier, ComputeType, ManipulatorGroup, ProjectionOptions, Subpath};
|
||||
|
||||
use glam::DVec2;
|
||||
use wasm_bindgen::prelude::*;
|
||||
@@ -68,6 +68,15 @@ impl WasmSubpath {
|
||||
wrap_svg_tag(format!("{}{}", self.to_default_svg(), point_text))
|
||||
}
|
||||
|
||||
pub fn project(&self, x: f64, y: f64) -> String {
|
||||
let (segment_index, projected_t) = self.0.project(DVec2::new(x, y), ProjectionOptions::default()).unwrap();
|
||||
let projected_point = self.0.evaluate(ComputeType::Parametric((segment_index as f64 + projected_t) / (self.0.len_segments() as f64)));
|
||||
|
||||
let subpath_svg = self.to_default_svg();
|
||||
let content = format!("{subpath_svg}{}", draw_line(projected_point.x, projected_point.y, x, y, RED, 1.),);
|
||||
wrap_svg_tag(content)
|
||||
}
|
||||
|
||||
pub fn intersect_line_segment(&self, js_points: JsValue) -> String {
|
||||
let points: [DVec2; 2] = serde_wasm_bindgen::from_value(js_points).unwrap();
|
||||
let line = Bezier::from_linear_dvec2(points[0], points[1]);
|
||||
|
||||
Reference in New Issue
Block a user