From 9482e0c7102aa96e909ea1358ab08bb3069ca0fe Mon Sep 17 00:00:00 2001 From: David Mann Date: Sat, 10 Oct 2026 07:10:12 +0200 Subject: [PATCH] Smudge: use the Brush Settings spacing for retouch strokes (#2140) (#2171) parse_brush, shared by Smudge, Blur, Sharpen, Dodge, Burn, Sponge, the clone/healing tools and the History Brush, defaulted `spacing` to a fixed 25% instead of the session brush's spacing (Brush Settings > Brush Tip Shape > Spacing). The UI never sends `spacing` for these tools, so the Brush Settings value was ignored. Default to the session brush spacing, as Photoshop does; an explicit `spacing` param still wins. Co-authored-by: Claude Opus 5.5 (1M context) --- crates/engine/src/retouch_cmds.rs | 5 +++-- crates/engine/src/retouch_cmds/tests.rs | 29 ++++++++++++++++++++++++- 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/crates/engine/src/retouch_cmds.rs b/crates/engine/src/retouch_cmds.rs index 472bea882f..394746e79b 100644 --- a/crates/engine/src/retouch_cmds.rs +++ b/crates/engine/src/retouch_cmds.rs @@ -89,7 +89,8 @@ fn parse_brush(s: &Session, p: &Value, cmd: &str) -> Result<(Stroke, Option AllLayers<'a> { /// The brush every retouching command shares, plus the tool's own params. macro_rules! brush_params { ($extra:literal) => { - concat!("{", r#""points":[[x,y,pressure?],…],"size":1..5000 px=tool size,"hardness":0..100=tool hardness,"opacity":1..100=100,"flow":1..100=100,"spacing":1..1000 (% of size)=25,"layer":id?=active,"target":"pixels"|"mask"|"quickMask"|{"channel":i}=Channels panel target"#, $extra, "}") + concat!("{", r#""points":[[x,y,pressure?],…],"size":1..5000 px=tool size,"hardness":0..100=tool hardness,"opacity":1..100=100,"flow":1..100=100,"spacing":1..1000 (% of size)=Brush Settings spacing,"layer":id?=active,"target":"pixels"|"mask"|"quickMask"|{"channel":i}=Channels panel target"#, $extra, "}") }; } diff --git a/crates/engine/src/retouch_cmds/tests.rs b/crates/engine/src/retouch_cmds/tests.rs index ed7eb271b1..6e4c118cef 100644 --- a/crates/engine/src/retouch_cmds/tests.rs +++ b/crates/engine/src/retouch_cmds/tests.rs @@ -311,7 +311,8 @@ fn blur_reduces_local_variance_and_sharpen_increases_it() { let v0 = var(&s, 10); s.execute("paint.sharpen", json!({"points": [[5, 15], [25, 15]], "size": 20, "hardness": 100, "strength": 100, "protectDetail": false})).unwrap(); assert!(var(&s, 10) > v0 * 1.5, "depth {depth}: {v0} → {}", var(&s, 10)); - s.execute("paint.sharpen", json!({"points": [[35, 15], [55, 15]], "size": 20, "hardness": 100, "strength": 100})).unwrap(); + // Pinned at 25%: Protect Detail clamps per dab, so denser dabs creep past the range. + s.execute("paint.sharpen", json!({"points": [[35, 15], [55, 15]], "size": 20, "hardness": 100, "strength": 100, "spacing": 25})).unwrap(); let hi = (10..20).flat_map(|y| (40..50).map(move |x| (x, y))).map(|(x, y)| rgba(&s, x, y)[0]).fold(0.0, f32::max); assert!(hi <= 0.55 + tol(depth), "protect detail: {hi}"); } @@ -333,6 +334,32 @@ fn smudge_moves_colour_along_the_stroke() { } } +#[test] +fn smudge_uses_the_brush_settings_spacing() { + // #2140: the Brush Settings spacing (the session brush) drives Smudge dabs when the stroke + // has no `spacing` param, as it drives the Brush. + let run = |spacing: f32, p: Value| { + let mut s = session(100, 30, 8, "rgb"); + paint_layer(&mut s, |x, _| if x < 30 { [1.0, 0.0, 0.0, 1.0] } else { [1.0, 1.0, 1.0, 1.0] }); + s.tools.brush.spacing = spacing; + let mut p = p; + p["points"] = json!([[20, 15], [90, 15]]); + s.execute("paint.smudge", p).unwrap(); + (30..95).map(|x| rgba(&s, x, 15)[1]).collect::>() + }; + let base = json!({"size": 12, "hardness": 100, "strength": 80}); + let dense = run(0.01, base.clone()); + let sparse = run(10.0, base.clone()); + // 1000% of 12 px puts the next dab 120 px away: only the first dab, behind the edge, lands. + assert!(sparse.iter().all(|g| *g > 0.99), "1000% spacing: nothing dragged past the edge"); + assert!(dense.first().is_some_and(|g| *g < 0.6), "1% spacing: red dragged right ({:?})", dense.first()); + assert_ne!(dense, run(0.25, base.clone()), "1% and 25% differ"); + // An explicit `spacing` param still wins over the Brush Settings value. + let mut explicit = base; + explicit["spacing"] = json!(1000); + assert_eq!(run(0.01, explicit), sparse); +} + #[test] fn history_brush_restores_earlier_pixels() { for depth in [8u64, 32] {