mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-19 19:08:05 +08:00
Bezier-rs: Add trim for Subpath (#1006)
* Move compare.rs * Update traits for Subpath and ManipulatorGroup * Implement trim * UI adjustments and more tests * Add reverse, refactor code, rename variables * Improve comments * Comment nits * Address comments * Update trim behavior * Update doc comment for trim --------- Co-authored-by: Keavon Chambers <keavon@keavon.com>
This commit is contained in:
@@ -105,6 +105,15 @@ const subpathFeatures = {
|
||||
sliderOptions: [tSliderOptions],
|
||||
chooseTVariant: true,
|
||||
},
|
||||
trim: {
|
||||
name: "Trim",
|
||||
callback: (subpath: WasmSubpathInstance, options: Record<string, number>, _: undefined, tVariant: TVariant): string => subpath.trim(options.tVariant1, options.tVariant2, tVariant),
|
||||
sliderOptions: [
|
||||
{ ...tSliderOptions, default: 0.2, variable: "tVariant1" },
|
||||
{ ...tSliderOptions, variable: "tVariant2" },
|
||||
],
|
||||
chooseTVariant: true,
|
||||
},
|
||||
};
|
||||
|
||||
export type SubpathFeatureKey = keyof typeof subpathFeatures;
|
||||
|
||||
@@ -359,4 +359,21 @@ impl WasmSubpath {
|
||||
|
||||
wrap_svg_tag(format!("{}{}{}", self.to_default_svg(), main_subpath_svg, other_subpath_svg))
|
||||
}
|
||||
|
||||
pub fn trim(&self, t1: f64, t2: f64, t_variant: String) -> String {
|
||||
let t1 = parse_t_variant(&t_variant, t1);
|
||||
let t2 = parse_t_variant(&t_variant, t2);
|
||||
let trimmed_subpath = self.0.trim(t1, t2);
|
||||
|
||||
let mut trimmed_subpath_svg = String::new();
|
||||
trimmed_subpath.to_svg(
|
||||
&mut trimmed_subpath_svg,
|
||||
CURVE_ATTRIBUTES.to_string().replace(BLACK, RED).replace("stroke-width=\"2\"", "stroke-width=\"8\"") + " opacity=\"0.5\"",
|
||||
ANCHOR_ATTRIBUTES.to_string().replace(BLACK, RED),
|
||||
HANDLE_ATTRIBUTES.to_string().replace(GRAY, RED),
|
||||
HANDLE_LINE_ATTRIBUTES.to_string().replace(GRAY, RED),
|
||||
);
|
||||
|
||||
wrap_svg_tag(format!("{}{}", self.to_default_svg(), trimmed_subpath_svg))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user