From c516932f9f5215bf4b9c87836894aa19fed827ed Mon Sep 17 00:00:00 2001 From: Benjamin Hackl Date: Thu, 14 Nov 2024 01:23:50 +0100 Subject: [PATCH] Fix scene skipping for `config.upto_animation_number` (`-n` flag in CLI) set to 0 to end after first animation (#4013) * make checks involving from/upto_animation_number more explicit * add test for flag -n 0,0 for only rendering first animation * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Aarush Deshpande <110117391+JasonGrace2282@users.noreply.github.com> --- manim/renderer/cairo_renderer.py | 8 ++++---- manim/renderer/opengl_renderer.py | 8 ++++---- tests/test_config.py | 21 +++++++++++++++++++++ 3 files changed, 29 insertions(+), 8 deletions(-) diff --git a/manim/renderer/cairo_renderer.py b/manim/renderer/cairo_renderer.py index b97fa50299..0b13fb8638 100644 --- a/manim/renderer/cairo_renderer.py +++ b/manim/renderer/cairo_renderer.py @@ -252,13 +252,13 @@ def update_skipping_status(self): if config["save_last_frame"]: self.skip_animations = True if ( - config["from_animation_number"] - and self.num_plays < config["from_animation_number"] + config.from_animation_number > 0 + and self.num_plays < config.from_animation_number ): self.skip_animations = True if ( - config["upto_animation_number"] - and self.num_plays > config["upto_animation_number"] + config.upto_animation_number >= 0 + and self.num_plays > config.upto_animation_number ): self.skip_animations = True raise EndSceneEarlyException() diff --git a/manim/renderer/opengl_renderer.py b/manim/renderer/opengl_renderer.py index ead0d0d82b..2f0ad398fe 100644 --- a/manim/renderer/opengl_renderer.py +++ b/manim/renderer/opengl_renderer.py @@ -400,13 +400,13 @@ def update_skipping_status(self): if self.file_writer.sections[-1].skip_animations: self.skip_animations = True if ( - config["from_animation_number"] - and self.num_plays < config["from_animation_number"] + config.from_animation_number > 0 + and self.num_plays < config.from_animation_number ): self.skip_animations = True if ( - config["upto_animation_number"] - and self.num_plays > config["upto_animation_number"] + config.upto_animation_number >= 0 + and self.num_plays > config.upto_animation_number ): self.skip_animations = True raise EndSceneEarlyException() diff --git a/tests/test_config.py b/tests/test_config.py index a245f4027a..0703b31bf4 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -244,3 +244,24 @@ def test_tex_template_file(tmp_path): assert Path(custom_config.tex_template_file) == tex_file assert custom_config.tex_template.body == "Hello World!" + + +def test_from_to_animations_only_first_animation(config): + config: ManimConfig + config.from_animation_number = 0 + config.upto_animation_number = 0 + + class SceneWithTwoAnimations(Scene): + def construct(self): + self.after_first_animation = False + s = Square() + self.add(s) + self.play(s.animate.scale(2)) + self.renderer.update_skipping_status() + self.after_first_animation = True + self.play(s.animate.scale(2)) + + scene = SceneWithTwoAnimations() + scene.render() + + assert scene.after_first_animation is False