engine: Free Transform takes soft edges whole after a move (#10461)

After moving selected pixels, the selection is the moved pixels' alpha
(#7538, measured in Photoshop). Free Transform split the layer by
multiplying the selection into each pixel, so a soft edge pixel of
alpha a was lifted as a² and a × (1 − a) of it stayed behind: a grey
outline of the shape at its old place.

`split_selected` now lifts the selection's share of each pixel's
coverage, up to all of it, as moving selected pixels already does
(`float_cmds::cut_piece`, #7655). Opaque pixels still split as k and
1 − k, and fully selected pixels move whole, as before. Warp, Distort
and the live transform preview share the function.
This commit is contained in:
Lcoding15 committed 2026-10-31 14:05:02 +01:00
1 parent 422ca7beda
commit dce32b66d8
2 files changed
+33 -2

No files matched your search

+26
View File
@@ -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.
+7 -2
View File
@@ -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 {