Scale Composition: refuse more than one of factor, width and height instead of ignoring the others

This commit is contained in:
Marco Arnulfo
2026-10-30 00:44:58 +01:00
parent 807803c14b
commit 495243c5b6
2 changed files with 6 additions and 0 deletions
+4
View File
@@ -153,6 +153,10 @@ fn scale_comp(s: &mut Session, p: &Value) -> Result<Value> {
let cid = comp_id(s, p)?;
let comp = s.project.comp(cid).ok_or(EngineError::NoComp)?;
let (ow, oh) = (f64::from(comp.width), f64::from(comp.height));
// The three are alternatives: with two, one would be ignored without a word.
if ["factor", "width", "height"].iter().filter(|k| f_p(p, k).is_some()).count() > 1 {
return Err(bad(C, "pass only one of `factor`, `width` or `height`"));
}
let f = match (f_p(p, "factor"), f_p(p, "width"), f_p(p, "height")) {
(Some(f), ..) => f,
(None, Some(w), _) => w / ow,
+2
View File
@@ -273,6 +273,8 @@ fn scale_comp_refuses_a_bad_factor_and_changes_nothing() {
(json!({"width": 0}), "4 to 30,000 px"),
(json!({"factor": 100}), "4 to 30,000 px"),
(json!({"factor": 0.001}), "4 to 30,000 px"),
(json!({"factor": 2, "width": 960}), "only one of"),
(json!({"width": 960, "height": 360}), "only one of"),
];
for (p, why) in cases {
match s.execute("comp.scale", p.clone()) {