diff --git a/crates/engine/src/cmd/float_cmds/tests.rs b/crates/engine/src/cmd/float_cmds/tests.rs index 44c887643f..1fec9630b7 100644 --- a/crates/engine/src/cmd/float_cmds/tests.rs +++ b/crates/engine/src/cmd/float_cmds/tests.rs @@ -501,6 +501,32 @@ fn a_soft_edge_is_as_selected_as_it_is_opaque_and_feathered_moves_leave_the_rest assert!((alpha(doc, id, 15, 20) - 0.5).abs() < 0.01 && (alpha(doc, id, 45, 20) - 0.5).abs() < 0.01, "half left, half moved"); } +/// #10461: after a move the selection is the moved pixels' alpha, and Free Transform then takes +/// each soft edge pixel whole, as moving does. Multiplying the selection in lifted a² and left +/// a × (1 − a) of every edge behind, a grey outline where the shape had been. +#[test] +fn transforming_after_a_move_takes_soft_edges_whole() { + let (mut s, id) = session(); + s.edit("soft edge", |doc, _| { + let surf = doc.layer_mut(id).unwrap().surface_mut().unwrap(); + for (x, a) in [(30, 0.75), (31, 0.5), (32, 0.25)] { + surf.fill_rect(Rect::new(x, 10, x + 1, 30), &[1.0, 0.0, 0.0, a]); + } + Ok(()) + }) + .unwrap(); + s.execute("select.rect", json!({"x": 5, "y": 5, "width": 40, "height": 30})).unwrap(); + s.execute("select.float", json!({"dx": 10, "dy": 0})).unwrap(); + s.execute("select.drop", json!({})).unwrap(); + assert!((selected(&s.active().unwrap().doc, 41, 20) - 0.5).abs() < 0.01, "the selection is the moved pixels' alpha"); + s.execute("edit.transform", json!({"matrix": [1, 0, 0, 1, 0, 20], "interpolation": "nearest"})).unwrap(); + let doc = &s.active().unwrap().doc; + for (x, a) in [(39, 1.0), (40, 0.75), (41, 0.5), (42, 0.25)] { + assert_eq!(alpha(doc, id, x, 15), 0.0, "x {x}: nothing left where it was"); + assert!((alpha(doc, id, x, 45) - a).abs() < 0.01, "x {x}: alpha {} where {a} moved", alpha(doc, id, x, 45)); + } +} + /// #7538: arrow nudges add up to one floating piece, so up then down is back at no offset. The /// selection is the moved pixels' all the same, as after each of Photoshop's nudges, in one step; /// a piece that never moved (a click) changes nothing. diff --git a/crates/engine/src/cmd/transform_cmds.rs b/crates/engine/src/cmd/transform_cmds.rs index 520f61e506..d4fab50a16 100644 --- a/crates/engine/src/cmd/transform_cmds.rs +++ b/crates/engine/src/cmd/transform_cmds.rs @@ -574,8 +574,13 @@ pub fn split_selected(surf: &Surface, sel: &Surface) -> Result<(Surface, Surface for (i, (l, r)) in lp.chunks_exact_mut(n).zip(rp.chunks_exact_mut(n)).enumerate() { let (x, y) = (src.x0 + (i % w) as i32, src.y0 + (i / w) as i32); let k = sel.sample_channel(x, y, 0); - l[n - 1] *= k; - r[n - 1] *= 1.0 - k; + // The selection lifts its share of a pixel's coverage, up to all of it, as moving selected + // pixels does (`float_cmds::cut_piece`, #7655): after a move the selection is the moved + // pixels' alpha, and multiplying left a × (1 − a) of every soft edge behind (#10461). + let a = l[n - 1]; + let lifted = a.min(k.max(0.0)); + l[n - 1] = lifted; + r[n - 1] = (a - lifted).max(0.0); // Likewise an unselected pixel leaves nothing in the lifted surface, so its bounds are the // selected pixels' (what a stretch repeats at the edge, #3773). if l[n - 1] <= 0.0 {