mirror of
https://github.com/storytold/effectcraft.git
synced 2026-10-31 15:48:33 +00:00
Follow-up to #2716: addItem applies in before out; anchor takes exactly [x, y]
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
4b7767401b
commit
2a7888d2c0
2 files changed
+14
-3
No files matched your search
@@ -279,6 +279,7 @@ fn anchor_param(p: &Value, cmd: &str) -> Result<Option<[f64; 2]>> {
|
||||
None | Some(Value::Null) => Ok(None),
|
||||
Some(v) => v
|
||||
.as_array()
|
||||
.filter(|a| a.len() == 2)
|
||||
.and_then(|a| Some([a.first()?.as_f64()?, a.get(1)?.as_f64()?]))
|
||||
.filter(|c| c.iter().all(|x| x.is_finite() && x.abs() <= MAX_PLACEMENT))
|
||||
.map(Some)
|
||||
@@ -361,12 +362,13 @@ pub(super) fn add_item(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
l.out_point = fr.snap_nearest(end).max(start + fr.frame_duration());
|
||||
// `in` / `out` are comp times like `layer.timing`'s; each keeps at least one frame.
|
||||
let fd = fr.frame_duration();
|
||||
if let Some(o) = out_p {
|
||||
l.out_point = fr.snap_nearest(o).max(l.in_point + fd);
|
||||
}
|
||||
// In first, as `layer.timing` does, so an `out` before the layer's start still lands.
|
||||
if let Some(i) = in_p {
|
||||
l.in_point = fr.snap_nearest(i).min(l.out_point - fd);
|
||||
}
|
||||
if let Some(o) = out_p {
|
||||
l.out_point = fr.snap_nearest(o).max(l.in_point + fd);
|
||||
}
|
||||
place(&mut l, position);
|
||||
set_anchor(&mut l, anchor);
|
||||
insert_layer_at(proj, st, cid, l, index)
|
||||
|
||||
@@ -82,3 +82,12 @@ fn invalid_values_are_errors_and_change_nothing() {
|
||||
}
|
||||
assert_eq!(s.active_comp().unwrap().layers.len(), n);
|
||||
}
|
||||
|
||||
/// `in` applies before `out` (as `layer.timing`), so a range before the layer's start lands as asked.
|
||||
#[test]
|
||||
fn in_and_out_before_the_start_land_and_a_three_value_anchor_is_refused() {
|
||||
let (mut s, item, _) = setup();
|
||||
let id = s.execute_checked("layer.addItem", json!({"item": item, "time": 5.0, "in": 1.0, "out": 2.0})).unwrap()["layer"].as_u64().unwrap();
|
||||
assert_eq!((secs(layer(&s, id).in_point), secs(layer(&s, id).out_point)), (1.0, 2.0));
|
||||
assert!(s.execute_checked("layer.addItem", json!({"item": item, "anchor": [1.0, 2.0, 3.0]})).is_err());
|
||||
}
|
||||
Reference in new issue
Block a user