A community-maintained Python framework for creating mathematical animations.
Add type annotations to `movement.py` (#4371)
Henrik Skov Midtibyd0521fa06d64
diff --git a/manim/animation/movement.py b/manim/animation/movement.pyindex 6393d8bee..c0c79d4ae 100644--- a/manim/animation/movement.py+++ b/manim/animation/movement.py@@ -18,7 +18,13 @@ from ..animation.animation import Animationfrom ..utils.rate_functions import linearif TYPE_CHECKING:- from ..mobject.mobject import Mobject, VMobject+ from typing_extensions import Self++ from manim.mobject.types.vectorized_mobject import VMobject+ from manim.typing import MappingFunction, Point3D+ from manim.utils.rate_functions import RateFunction++ from ..mobject.mobject import Mobjectclass Homotopy(Animation):@@ -72,27 +78,33 @@ class Homotopy(Animation):mobject: Mobject,run_time: float = 3,apply_function_kwargs: dict[str, Any] | None = None,- **kwargs,- ) -> None:+ **kwargs: Any,+ ):self.homotopy = homotopyself.apply_function_kwargs = (apply_function_kwargs if apply_function_kwargs is not None else {})super().__init__(mobject, run_time=run_time, **kwargs)- def function_at_time_t(self, t: float) -> tuple[float, float, float]:- return lambda p: self.homotopy(*p, t)+ def function_at_time_t(self, t: float) -> MappingFunction:+ def mapping_function(p: Point3D) -> Point3D:+ x, y, z = p+ return np.array(self.homotopy(x, y, z, t))++ return mapping_functiondef interpolate_submobject(self,submobject: Mobject,starting_submobject: Mobject,alpha: float,- ) -> None:+ ) -> Self:submobject.points = starting_submobject.pointssubmobject.apply_function(- self.function_at_time_t(alpha), **self.apply_function_kwargs+ self.function_at_time_t(alpha),+ **self.apply_function_kwargs,)+ return selfclass SmoothedVectorizedHomotopy(Homotopy):@@ -101,15 +113,20 @@ class SmoothedVectorizedHomotopy(Homotopy):submobject: Mobject,starting_submobject: Mobject,alpha: float,- ) -> None:+ ) -> Self:+ assert isinstance(submobject, VMobject)super().interpolate_submobject(submobject, starting_submobject, alpha)submobject.make_smooth()+ return selfclass ComplexHomotopy(Homotopy):def __init__(- self, complex_homotopy: Callable[[complex], float], mobject: Mobject, **kwargs- ) -> None:+ self,+ complex_homotopy: Callable[[complex, float], float],+ mobject: Mobject,+ **kwargs: Any,+ ):"""Complex Homotopy a function Cx[0, 1] to C"""def homotopy(@@ -131,9 +148,9 @@ class PhaseFlow(Animation):mobject: Mobject,virtual_time: float = 1,suspend_mobject_updating: bool = False,- rate_func: Callable[[float], float] = linear,- **kwargs,- ) -> None:+ rate_func: RateFunction = linear,+ **kwargs: Any,+ ):self.virtual_time = virtual_timeself.function = functionsuper().__init__(@@ -149,7 +166,7 @@ class PhaseFlow(Animation):self.rate_func(alpha) - self.rate_func(self.last_alpha))self.mobject.apply_function(lambda p: p + dt * self.function(p))- self.last_alpha = alpha+ self.last_alpha: float = alphaclass MoveAlongPath(Animation):@@ -172,8 +189,8 @@ class MoveAlongPath(Animation):mobject: Mobject,path: VMobject,suspend_mobject_updating: bool = False,- **kwargs,- ) -> None:+ **kwargs: Any,+ ):self.path = pathsuper().__init__(mobject, suspend_mobject_updating=suspend_mobject_updating, **kwargsdiff --git a/mypy.ini b/mypy.iniindex 4a70f08c2..a830f2336 100644--- a/mypy.ini+++ b/mypy.ini@@ -57,9 +57,6 @@ ignore_errors = True[mypy-manim.animation.creation]ignore_errors = True-[mypy-manim.animation.movement]-ignore_errors = True-[mypy-manim.animation.rotation]ignore_errors = True