mirror of
https://github.com/storytold/effectcraft.git
synced 2026-11-01 05:58:19 -06:00
Scale Composition: refuse more than one of factor, width and height instead of ignoring the others
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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()) {
|
||||
|
||||
Reference in New Issue
Block a user