mirror of
https://github.com/storytold/deckcraft.git
synced 2026-12-04 22:50:29 +00:00
fix: keep the morph geometry fallback on the same object (#2467)
Signed-off-by: MaheshDesu <[email protected]>
This commit is contained in:
@@ -39,7 +39,7 @@ pub fn morph_pairs(a: &Slide, b: &Slide) -> Vec<(ShapeId, ShapeId)> {
|
||||
};
|
||||
// Forced names pair anything; ordinary names and the geometry fallback pair only the same
|
||||
// object; the text pass keeps pairing shapes that share their text (#316).
|
||||
let passes: [(&dyn Fn(&Shape, &str) -> Option<MorphKey>, bool); 4] = [(&forced, false), (&named, true), (&same_text, false), (&same_geom, false)];
|
||||
let passes: [(&dyn Fn(&Shape, &str) -> Option<MorphKey>, bool); 4] = [(&forced, false), (&named, true), (&same_text, false), (&same_geom, true)];
|
||||
for (key, strict) in passes {
|
||||
// Unused shapes of `b` by key, in slide order: the front of each queue is the first unused
|
||||
// match, which is the one a search through `b` would find.
|
||||
|
||||
@@ -607,6 +607,32 @@ fn same_name_changed_text_fades_in_place() {
|
||||
assert!((f.opacity_of(f.shapes[1].0.id) - s).abs() < 1e-9);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn same_name_pictures_with_different_images_fade_in_place() {
|
||||
// #2467: the same name is not enough when the picture changed; the geometry fallback must not
|
||||
// pair them either.
|
||||
let p = deckcraft_model::defaults::new_presentation(None);
|
||||
let pic = |id, media, x| Shape {
|
||||
xfrm: Some(Xfrm::new(x, 100.0, 200.0, 100.0)),
|
||||
kind: deckcraft_model::ShapeKind::Picture {
|
||||
fill: deckcraft_model::style::PictureFill { media: deckcraft_model::MediaId(media), ..Default::default() },
|
||||
},
|
||||
..shape(id, "Picture 1")
|
||||
};
|
||||
let mut a = Slide::default();
|
||||
let mut b = Slide::default();
|
||||
a.shapes = vec![pic(1, 10, 0.0)];
|
||||
b.shapes = vec![pic(2, 11, 400.0)];
|
||||
assert!(morph_pairs(&a, &b).is_empty(), "a different picture must not pair");
|
||||
let f = morph_frame(&p, &a, &b, 0.5, &|_| false);
|
||||
let s = f.mix;
|
||||
assert_eq!(f.shapes.len(), 2);
|
||||
assert_eq!(f.shapes[0].0.xfrm.unwrap().x, 0.0);
|
||||
assert_eq!(f.shapes[1].0.xfrm.unwrap().x, 400.0);
|
||||
assert!((f.opacity_of(f.shapes[0].0.id) - (1.0 - s)).abs() < 1e-9);
|
||||
assert!((f.opacity_of(f.shapes[1].0.id) - s).abs() < 1e-9);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn morph_crop_moves_the_image_linearly() {
|
||||
let bx = |x, w| Xfrm::new(x, 0.0, w, 100.0);
|
||||
@@ -633,6 +659,7 @@ fn morph_frame_morphs_a_picture_crop() {
|
||||
let mut b = Slide::default();
|
||||
a.shapes = vec![pic(1, [0.0, 0.0, 0.5, 0.0])];
|
||||
b.shapes = vec![pic(2, [0.5, 0.0, 0.0, 0.0])];
|
||||
assert_eq!(morph_pairs(&a, &b), [(ShapeId(1), ShapeId(2))], "a crop change still pairs");
|
||||
let f = morph_frame(&p, &a, &b, 0.5, &|_| false);
|
||||
assert_eq!(f.shapes.len(), 1);
|
||||
assert!(f.opacity.is_empty());
|
||||
|
||||
Reference in New Issue
Block a user