ManimCommunity / manim

A community-maintained Python framework for creating mathematical animations.
https://www.manim.community
MIT License
26.81k stars 1.84k forks source link

Refactored `run_time` validation for `Animation` and `Scene.wait()` #3982

Closed chopan050 closed 1 month ago

chopan050 commented 1 month ago

I made a new function validate_run_time() to refactor a validation already done somewhere else: it takes a run_time and raises a ValueError if it is <= 0, or a warning if it's too short for the current frame rate. Then, I called it on Animation.begin(), Wait.begin() and AnimationGroup.begin(), as well as in Scene.wait(), Scene.pause() and Scene.wait_until(), for reasons I'll explain later.

Previously, this was strangely done inside the Scene.get_run_time() which is called by Scene.play_internal(). The merged PR #3491 did a run_time check inside Animation.begin(), but, for some reason, this was removed later.

As for Scene.wait(): currently, in the main branch, Scene.wait() plays a Wait animation. Right now, it doesn't seem necessary to add this validation here, because Wait.begin() would already take care of that. However, in the experimental branch, Scene.wait() does something different. Therefore, it is also necessary to validate the wait duration there. The plan is to port this PR into experimental.

Reviewer Checklist