Skip to content

Commit

Permalink
Fix scene skipping for config.upto_animation_number (-n flag in C…
Browse files Browse the repository at this point in the history
…LI) 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 <[email protected]>
  • Loading branch information
3 people authored Nov 14, 2024
1 parent ab577dc commit c516932
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 8 deletions.
8 changes: 4 additions & 4 deletions manim/renderer/cairo_renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
8 changes: 4 additions & 4 deletions manim/renderer/opengl_renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
21 changes: 21 additions & 0 deletions tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit c516932

Please sign in to comment.