Skip to content

Commit c516932

Browse files
behacklpre-commit-ci[bot]JasonGrace2282
authored
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 <[email protected]>
1 parent ab577dc commit c516932

File tree

3 files changed

+29
-8
lines changed

3 files changed

+29
-8
lines changed

manim/renderer/cairo_renderer.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -252,13 +252,13 @@ def update_skipping_status(self):
252252
if config["save_last_frame"]:
253253
self.skip_animations = True
254254
if (
255-
config["from_animation_number"]
256-
and self.num_plays < config["from_animation_number"]
255+
config.from_animation_number > 0
256+
and self.num_plays < config.from_animation_number
257257
):
258258
self.skip_animations = True
259259
if (
260-
config["upto_animation_number"]
261-
and self.num_plays > config["upto_animation_number"]
260+
config.upto_animation_number >= 0
261+
and self.num_plays > config.upto_animation_number
262262
):
263263
self.skip_animations = True
264264
raise EndSceneEarlyException()

manim/renderer/opengl_renderer.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -400,13 +400,13 @@ def update_skipping_status(self):
400400
if self.file_writer.sections[-1].skip_animations:
401401
self.skip_animations = True
402402
if (
403-
config["from_animation_number"]
404-
and self.num_plays < config["from_animation_number"]
403+
config.from_animation_number > 0
404+
and self.num_plays < config.from_animation_number
405405
):
406406
self.skip_animations = True
407407
if (
408-
config["upto_animation_number"]
409-
and self.num_plays > config["upto_animation_number"]
408+
config.upto_animation_number >= 0
409+
and self.num_plays > config.upto_animation_number
410410
):
411411
self.skip_animations = True
412412
raise EndSceneEarlyException()

tests/test_config.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,3 +244,24 @@ def test_tex_template_file(tmp_path):
244244

245245
assert Path(custom_config.tex_template_file) == tex_file
246246
assert custom_config.tex_template.body == "Hello World!"
247+
248+
249+
def test_from_to_animations_only_first_animation(config):
250+
config: ManimConfig
251+
config.from_animation_number = 0
252+
config.upto_animation_number = 0
253+
254+
class SceneWithTwoAnimations(Scene):
255+
def construct(self):
256+
self.after_first_animation = False
257+
s = Square()
258+
self.add(s)
259+
self.play(s.animate.scale(2))
260+
self.renderer.update_skipping_status()
261+
self.after_first_animation = True
262+
self.play(s.animate.scale(2))
263+
264+
scene = SceneWithTwoAnimations()
265+
scene.render()
266+
267+
assert scene.after_first_animation is False

0 commit comments

Comments
 (0)