18
18
from ..utils .rate_functions import linear
19
19
20
20
if TYPE_CHECKING :
21
- from ..mobject .mobject import Mobject , VMobject
21
+ from typing_extensions import Self
22
+
23
+ from manim .mobject .types .vectorized_mobject import VMobject
24
+ from manim .typing import MappingFunction , Point3D
25
+ from manim .utils .rate_functions import RateFunction
26
+
27
+ from ..mobject .mobject import Mobject
22
28
23
29
24
30
class Homotopy (Animation ):
@@ -72,27 +78,33 @@ def __init__(
72
78
mobject : Mobject ,
73
79
run_time : float = 3 ,
74
80
apply_function_kwargs : dict [str , Any ] | None = None ,
75
- ** kwargs ,
76
- ) -> None :
81
+ ** kwargs : Any ,
82
+ ):
77
83
self .homotopy = homotopy
78
84
self .apply_function_kwargs = (
79
85
apply_function_kwargs if apply_function_kwargs is not None else {}
80
86
)
81
87
super ().__init__ (mobject , run_time = run_time , ** kwargs )
82
88
83
- def function_at_time_t (self , t : float ) -> tuple [float , float , float ]:
84
- return lambda p : self .homotopy (* p , t )
89
+ def function_at_time_t (self , t : float ) -> MappingFunction :
90
+ def mapping_function (p : Point3D ) -> Point3D :
91
+ x , y , z = p
92
+ return np .array (self .homotopy (x , y , z , t ))
93
+
94
+ return mapping_function
85
95
86
96
def interpolate_submobject (
87
97
self ,
88
98
submobject : Mobject ,
89
99
starting_submobject : Mobject ,
90
100
alpha : float ,
91
- ) -> None :
101
+ ) -> Self :
92
102
submobject .points = starting_submobject .points
93
103
submobject .apply_function (
94
- self .function_at_time_t (alpha ), ** self .apply_function_kwargs
104
+ self .function_at_time_t (alpha ),
105
+ ** self .apply_function_kwargs ,
95
106
)
107
+ return self
96
108
97
109
98
110
class SmoothedVectorizedHomotopy (Homotopy ):
@@ -101,15 +113,20 @@ def interpolate_submobject(
101
113
submobject : Mobject ,
102
114
starting_submobject : Mobject ,
103
115
alpha : float ,
104
- ) -> None :
116
+ ) -> Self :
117
+ assert isinstance (submobject , VMobject )
105
118
super ().interpolate_submobject (submobject , starting_submobject , alpha )
106
119
submobject .make_smooth ()
120
+ return self
107
121
108
122
109
123
class ComplexHomotopy (Homotopy ):
110
124
def __init__ (
111
- self , complex_homotopy : Callable [[complex ], float ], mobject : Mobject , ** kwargs
112
- ) -> None :
125
+ self ,
126
+ complex_homotopy : Callable [[complex , float ], float ],
127
+ mobject : Mobject ,
128
+ ** kwargs : Any ,
129
+ ):
113
130
"""Complex Homotopy a function Cx[0, 1] to C"""
114
131
115
132
def homotopy (
@@ -131,9 +148,9 @@ def __init__(
131
148
mobject : Mobject ,
132
149
virtual_time : float = 1 ,
133
150
suspend_mobject_updating : bool = False ,
134
- rate_func : Callable [[ float ], float ] = linear ,
135
- ** kwargs ,
136
- ) -> None :
151
+ rate_func : RateFunction = linear ,
152
+ ** kwargs : Any ,
153
+ ):
137
154
self .virtual_time = virtual_time
138
155
self .function = function
139
156
super ().__init__ (
@@ -149,7 +166,7 @@ def interpolate_mobject(self, alpha: float) -> None:
149
166
self .rate_func (alpha ) - self .rate_func (self .last_alpha )
150
167
)
151
168
self .mobject .apply_function (lambda p : p + dt * self .function (p ))
152
- self .last_alpha = alpha
169
+ self .last_alpha : float = alpha
153
170
154
171
155
172
class MoveAlongPath (Animation ):
@@ -172,8 +189,8 @@ def __init__(
172
189
mobject : Mobject ,
173
190
path : VMobject ,
174
191
suspend_mobject_updating : bool = False ,
175
- ** kwargs ,
176
- ) -> None :
192
+ ** kwargs : Any ,
193
+ ):
177
194
self .path = path
178
195
super ().__init__ (
179
196
mobject , suspend_mobject_updating = suspend_mobject_updating , ** kwargs
0 commit comments