Skip to content

EffectCraft: An open-source motion graphics and compositing tool written by scratch in pure Rust

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

Marco Arnulfo495243c5b6d7
diff --git a/crates/engine/src/cmd/comp_more.rs b/crates/engine/src/cmd/comp_more.rs
index 940c09f8d..6eaeda862 100644
--- a/crates/engine/src/cmd/comp_more.rs
+++ b/crates/engine/src/cmd/comp_more.rs
@@ -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,
diff --git a/crates/engine/src/tests/scale_comp.rs b/crates/engine/src/tests/scale_comp.rs
index aad1511d9..752ce9fe5 100644
--- a/crates/engine/src/tests/scale_comp.rs
+++ b/crates/engine/src/tests/scale_comp.rs
@@ -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()) {