Skip to content

Commit 6f825e8

Browse files
irvanalhaq9behacklpre-commit-ci[bot]
authored
Fix unintended kwargs propagation in LaggedStartMap (#4613)
* Fix unintended kwargs propagation in LaggedStartMap Ensure intended for are not forwarded to the superclass, and make explicit. * add test for keyword propagation in LaggedStartMap * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Update test_composition.py update the test * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Update test_composition.py add there_and_back --------- Co-authored-by: Benjamin Hackl <mail@behackl.dev> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent a0414dc commit 6f825e8

2 files changed

Lines changed: 34 additions & 3 deletions

File tree

manim/animation/composition.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ class LaggedStartMap(LaggedStart):
353353
354354
Parameters
355355
----------
356-
AnimationClass
356+
animation_class
357357
:class:`~.Animation` to apply to mobject.
358358
mobject
359359
:class:`~.Mobject` whose submobjects the animation, and optionally the function,
@@ -362,6 +362,17 @@ class LaggedStartMap(LaggedStart):
362362
Function which will be applied to :class:`~.Mobject`.
363363
run_time
364364
The duration of the animation in seconds.
365+
lag_ratio
366+
Defines the delay after which the animation is applied to submobjects. A lag_ratio of
367+
``n.nn`` means the next animation will play when ``nnn%`` of the current animation has played.
368+
Defaults to 0.05, meaning that the next animation will begin when 5% of the current
369+
animation has played.
370+
371+
This does not influence the total runtime of the animation. Instead the runtime
372+
of individual animations is adjusted so that the complete animation has the defined
373+
run time.
374+
kwargs
375+
Further keyword arguments that are passed to `animation_class`.
365376
366377
Examples
367378
--------
@@ -392,6 +403,7 @@ def __init__(
392403
mobject: Mobject,
393404
arg_creator: Callable[[Mobject], Iterable[Any]] | None = None,
394405
run_time: float = 2,
406+
lag_ratio: float = DEFAULT_LAGGED_START_LAG_RATIO,
395407
**kwargs: Any,
396408
):
397409
if arg_creator is None:
@@ -406,4 +418,4 @@ def identity(mob: Mobject) -> Mobject:
406418
if "lag_ratio" in anim_kwargs:
407419
anim_kwargs.pop("lag_ratio")
408420
animations = [animation_class(*args, **anim_kwargs) for args in args_list]
409-
super().__init__(*animations, run_time=run_time, **kwargs)
421+
super().__init__(*animations, run_time=run_time, lag_ratio=lag_ratio)

tests/module/animation/test_composition.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,16 @@
55
import pytest
66

77
from manim.animation.animation import Animation, Wait
8-
from manim.animation.composition import AnimationGroup, Succession
8+
from manim.animation.composition import AnimationGroup, LaggedStartMap, Succession
99
from manim.animation.creation import Create, Write
1010
from manim.animation.fading import FadeIn, FadeOut
1111
from manim.constants import DOWN, UP
1212
from manim.mobject.geometry.arc import Circle
1313
from manim.mobject.geometry.line import Line
1414
from manim.mobject.geometry.polygram import RegularPolygon, Square
15+
from manim.mobject.types.vectorized_mobject import VGroup
1516
from manim.scene.scene import Scene
17+
from manim.utils.rate_functions import linear, there_and_back
1618

1719

1820
def test_succession_timing():
@@ -189,6 +191,23 @@ def finish(self):
189191
assert circ_animation.finished
190192

191193

194+
def test_laggedstartmap_only_passes_kwargs_to_subanimations():
195+
mobject = VGroup(Square(), Circle())
196+
animation = LaggedStartMap(
197+
FadeIn,
198+
mobject,
199+
rate_func=there_and_back,
200+
lag_ratio=0.3,
201+
)
202+
203+
assert animation.rate_func is linear
204+
assert animation.lag_ratio == 0.3
205+
assert all(
206+
subanimation.rate_func is there_and_back
207+
for subanimation in animation.animations
208+
)
209+
210+
192211
def test_empty_animation_group_fails():
193212
with pytest.raises(ValueError, match="Please add at least one subanimation."):
194213
AnimationGroup().begin()

0 commit comments

Comments
 (0)