Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix scene skipping for config.upto_animation_number (-n flag in CLI) set to 0 to end after first animation #4013

Merged
merged 4 commits into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading