A community-maintained Python framework for creating mathematical animations.
Fix: Include moving mobject ancestors to prevent duplication at animate time (#4936)
nikolajmunk443f32cf3757
diff --git a/manim/scene/scene.py b/manim/scene/scene.pyindex f86419e81..07c4a8f76 100644--- a/manim/scene/scene.py+++ b/manim/scene/scene.py@@ -914,7 +914,7 @@ class Scene:# Go through mobjects from start to end, and# as soon as there's one that needs updating of# some kind per frame, return the list from that- # point forward.+ # mobject's earliest ancestor.# Imported inside the method to avoid cyclic import.from ..animation.composition import AnimationGroup@@ -932,18 +932,20 @@ class Scene:)return animation_mobjects- animation_mobjects = _collect_animation_mobjects(animations)+ animation_mobjects = set(_collect_animation_mobjects(animations))mobjects = self.get_mobject_family_members()- for i, mob in enumerate(mobjects):- update_possibilities = [- mob in animation_mobjects,- len(mob.get_family_updaters()) > 0,- mob in self.foreground_mobjects,- ]- if any(update_possibilities):- return mobjects[i:]- return []++ def consider_moving(mob: Mobject) -> bool:+ return (+ mob in animation_mobjects+ or len(mob.updaters) > 0+ or mob in self.foreground_mobjects+ or any(consider_moving(m) for m in mob.submobjects)+ )++ i = next((i for i, mob in enumerate(mobjects) if consider_moving(mob)), None)+ return [] if i is None else mobjects[i:]def get_moving_and_static_mobjects(self, animations: Iterable[Animation]diff --git a/tests/module/scene/test_scene.py b/tests/module/scene/test_scene.pyindex 51db5a953..b9724b9ad 100644--- a/tests/module/scene/test_scene.py+++ b/tests/module/scene/test_scene.py@@ -80,6 +80,21 @@ def test_animation_group_moving_mobjects_preserve_z_index_order(dry_run):assert left_circle not in scene.static_mobjects[email protected]("parent_cls", [Group, Circle])[email protected]("z_index", [-10, 0, 10])+def test_parent_of_moving_submobject_is_marked_moving(dry_run, parent_cls, z_index):+ scene = Scene()+ child = Square()+ parent = parent_cls().set_z_index(z_index).add(child)+ scene.add(parent)++ scene.compile_animation_data(child.animate.shift((1, 0, 0)))+ scene.begin_animations()++ assert parent in scene.moving_mobjects+ assert parent not in scene.static_mobjects++def test_subcaption(dry_run):scene = Scene()scene.add_subcaption("Testing add_subcaption", duration=1, offset=0)diff --git a/tests/test_graphical_units/control_data/geometry/ZIndex.npz b/tests/test_graphical_units/control_data/geometry/ZIndex.npzindex 166cd0d1f..538541953 100644Binary files a/tests/test_graphical_units/control_data/geometry/ZIndex.npz and b/tests/test_graphical_units/control_data/geometry/ZIndex.npz differ