Pencil and Blob Brush: Alt smooths with the Smooth tool's Fidelity

When Alt switches the Pencil (with Alt key toggles to Smooth Tool on)
or the Blob Brush to the Smooth tool, the drag sent the drawing tool's
own Fidelity (1.5 by default) to path.smoothRegion. The Smooth tool
sends its own Fidelity (2.5 by default, set in Smooth Tool Options).

Both tools now smooth with the Smooth tool's Fidelity. The engine gives
them the stored Smooth Fidelity when it makes the tool, and again when
Smooth Tool Options changes while one of them is active. Each tool's
own Fidelity still sets how its strokes are fitted.
This commit is contained in:
dotCooCoo
2026-10-30 23:52:26 +07:00
committed by bflatastic
parent 71f566c6aa
commit 7d97c633b7
4 changed files with 86 additions and 4 deletions
+35
View File
@@ -96,3 +96,38 @@ fn options_are_saved_with_the_preferences() {
t.execute("prefs.reset", &json!({})).unwrap();
assert_eq!(t.prefs.tool_settings["polygon"]["sides"], json!(9));
}
/// The Fidelity an Alt smoothing drag uses on a selected path.
fn alt_smooth_fidelity(s: &mut Session) -> Option<f64> {
use vectorcraft_tools::{Action, Mods, PointerEvent, PointerKind};
let mods = Mods { alt: true, ..Default::default() };
let mut last = vec![];
for (kind, x, y) in [(PointerKind::Down, 50.0, 150.0), (PointerKind::Drag, 150.0, 150.0), (PointerKind::Up, 250.0, 160.0)] {
let ev = PointerEvent { mods, ..PointerEvent::new(kind, x, y) };
last = s.with_tool_cx(ViewInfo::default(), |t, cx| t.pointer(cx, &ev));
}
last.iter().find_map(|a| match a {
Action::Exec(c, v) if c == "path.smoothRegion" => v["fidelity"].as_f64(),
_ => None,
})
}
/// Alt switches Pencil and Blob Brush to Smooth, using Smooth Tool Options' stored Fidelity.
#[test]
fn alt_smoothing_takes_the_smooth_tools_fidelity() {
for id in ["pencil", "blobBrush"] {
let mut s = session();
s.execute("shape.rectangle", &json!({"x": 100, "y": 100, "width": 100, "height": 100})).unwrap();
select(&mut s, "smooth");
s.set_tool_option("fidelity", &json!(6));
select(&mut s, id);
if id == "pencil" {
s.set_tool_option("altSmooth", &json!(true));
}
s.set_tool_option("fidelity", &json!(3));
assert_eq!(alt_smooth_fidelity(&mut s), Some(6.0), "{id}");
s.set_tool_option_cmd(&json!({"tool": "smooth", "key": "fidelity", "value": 9})).unwrap();
assert_eq!(alt_smooth_fidelity(&mut s), Some(9.0), "{id}");
assert_eq!(s.tool_options()["fidelity"], json!(3.0), "{id}");
}
}