Merge pull request #3236 from vangel76/number-field-math-3195

Number fields: typed arithmetic (960/2, (3+4)*2) and a leading *, / or + applied to the value
This commit is contained in:
FredApps authored and GitHub committed 2026-11-14 17:29:47 +01:00
commit 38cd374bae
14 files changed
+744 -35

No files matched your search

+58
View File
@@ -1556,6 +1556,64 @@ fn a_typed_component_applies_only_that_component_to_the_selected_layers() {
assert_eq!(pos(&s, c), vec![1.0, 2.0, 3.0]);
}
/// #3195: a typed `*2` or `/2` with several layers selected scales each layer's own value (in
/// the typed components of a vector), not the edited layer's result.
#[test]
fn a_typed_factor_scales_each_selected_layers_own_value() {
let (mut s, a) = setup();
let b = s.execute("layer.newSolid", json!({"color": "#ff0000", "width": 50, "height": 50})).unwrap()["layer"].as_u64().unwrap();
s.execute("prop.set", json!({"layer": a, "path": "transform/opacity", "value": 40.0})).unwrap();
s.execute("prop.set", json!({"layer": b, "path": "transform/opacity", "value": 30.0})).unwrap();
s.execute("prop.set", json!({"layer": a, "path": "transform/position", "value": [10.0, 20.0]})).unwrap();
s.execute("prop.set", json!({"layer": b, "path": "transform/position", "value": [100.0, 50.0]})).unwrap();
s.execute("layer.select", json!({"layers": [a, b]})).unwrap();
let opacity = prop(&s, a, "transform/opacity").uid;
let undo = s.history.undo.len();
s.execute_checked("prop.set", json!({"layer": a, "prop": opacity, "value": 80.0, "selected": true, "factor": 2.0})).unwrap();
assert_eq!(prop(&s, a, "transform/opacity").value.as_f64(), 80.0);
assert_eq!(prop(&s, b, "transform/opacity").value.as_f64(), 60.0, "B doubles its own 30");
assert_eq!(s.history.undo.len(), undo + 1, "one undo step");
let position = prop(&s, a, "transform/position").uid;
s.execute_checked("prop.set", json!({"layer": a, "prop": position, "value": [5.0, 20.0], "selected": true, "dims": [0], "factor": 0.5})).unwrap();
assert_eq!(prop(&s, a, "transform/position").value.components()[..2], [5.0, 20.0]);
assert_eq!(prop(&s, b, "transform/position").value.components()[..2], [50.0, 50.0], "B halves its own X, keeps its Y");
// A typed `+10` (`addend`): each layer's own value plus 10, within its own range, even where
// the edited layer's range cut its change short (95 + 10 stops at 100).
s.execute("prop.set", json!({"layer": a, "path": "transform/opacity", "value": 95.0})).unwrap();
s.execute("prop.set", json!({"layer": b, "path": "transform/opacity", "value": 30.0})).unwrap();
s.execute_checked("prop.set", json!({"layer": a, "prop": opacity, "value": 100.0, "selected": true, "addend": 10.0})).unwrap();
assert_eq!(prop(&s, b, "transform/opacity").value.as_f64(), 40.0, "B adds 10, not the 5 A moved");
s.execute("prop.set", json!({"layer": b, "path": "transform/opacity", "value": 95.0})).unwrap();
s.execute_checked("prop.set", json!({"layer": a, "prop": opacity, "value": 100.0, "selected": true, "addend": 10.0})).unwrap();
assert_eq!(prop(&s, b, "transform/opacity").value.as_f64(), 100.0, "B's own range still applies");
s.execute_checked("prop.set", json!({"layer": a, "prop": position, "value": [15.0, 20.0], "selected": true, "dims": [0], "addend": 10.0})).unwrap();
assert_eq!(prop(&s, b, "transform/position").value.components()[..2], [60.0, 50.0], "B adds 10 to its own X");
}
/// #3195: Mask Feather is never negative on the other selected layers either, when a typed `*-1`
/// (the edited layer clamped at 0 by the panel) or a change by the same amount takes theirs
/// below 0.
#[test]
fn a_selected_mask_feather_stays_non_negative() {
let (mut s, a) = setup();
let b = s.execute("layer.newSolid", json!({"color": "#ff0000", "width": 50, "height": 50})).unwrap()["layer"].as_u64().unwrap();
for (l, feather) in [(a, [10.0, 20.0]), (b, [4.0, 30.0])] {
s.execute("mask.new", json!({"layer": l, "vertices": [[0, 0], [20, 0], [20, 20]]})).unwrap();
s.execute("prop.set", json!({"layer": l, "path": "masks/#1/feather", "value": feather})).unwrap();
}
s.execute("layer.select", json!({"layers": [a, b]})).unwrap();
let feather = |s: &Session, l: u64| prop(s, l, "masks/#1/feather").value.components();
let uid = prop(&s, a, "masks/#1/feather").uid;
// `*-1` into the linked pair: the panel clamps the edited layer at [0, 0].
s.execute_checked("prop.set", json!({"layer": a, "prop": uid, "value": [0.0, 0.0], "selected": true, "dims": [0, 1], "factor": -1.0})).unwrap();
assert_eq!(feather(&s, a), [0.0, 0.0]);
assert_eq!(feather(&s, b), [0.0, 0.0], "B is clamped at 0, not [-4, -30]");
// A change by the same amount (a scrub, or a typed `+`): A by [-10, -15] from [10, 20].
s.execute("edit.undo", json!({})).unwrap();
s.execute_checked("prop.set", json!({"layer": a, "prop": uid, "value": [0.0, 5.0], "selected": true, "offset": true})).unwrap();
assert_eq!(feather(&s, b), [0.0, 15.0], "B's X is clamped at 0, its Y moves by -15");
}
/// #2485: linked Audio Levels typed with several layers selected: each takes the typed Left, and
/// its Right moves by its own change, so every layer keeps its own stereo balance.
#[test]