4
4
5
5
__all__ = ["Brace" , "BraceLabel" , "ArcBrace" , "BraceText" , "BraceBetweenPoints" ]
6
6
7
- from collections .abc import Sequence
8
- from typing import TYPE_CHECKING
7
+ from typing import TYPE_CHECKING , Any
9
8
10
9
import numpy as np
11
10
import svgelements as se
11
+ from typing_extensions import Self
12
12
13
13
from manim ._config import config
14
14
from manim .mobject .geometry .arc import Arc
15
15
from manim .mobject .geometry .line import Line
16
16
from manim .mobject .mobject import Mobject
17
17
from manim .mobject .opengl .opengl_compatibility import ConvertToOpenGL
18
- from manim .mobject .text .tex_mobject import MathTex , Tex
18
+ from manim .mobject .text .tex_mobject import MathTex , SingleStringMathTex , Tex
19
+ from manim .mobject .text .text_mobject import Text
19
20
21
+ from ...animation .animation import Animation
20
22
from ...animation .composition import AnimationGroup
21
23
from ...animation .fading import FadeIn
22
24
from ...animation .growing import GrowFromCenter
26
28
from ..svg .svg_mobject import VMobjectFromSVGPath
27
29
28
30
if TYPE_CHECKING :
29
- from manim .typing import Point3DLike , Vector3D
31
+ from manim .typing import Point3D , Point3DLike , Vector3D
30
32
from manim .utils .color .core import ParsableManimColor
31
33
32
- __all__ = ["Brace" , "BraceBetweenPoints" , "BraceLabel" , "ArcBrace" ]
33
-
34
34
35
35
class Brace (VMobjectFromSVGPath ):
36
36
"""Takes a mobject and draws a brace adjacent to it.
@@ -70,14 +70,14 @@ def construct(self):
70
70
def __init__ (
71
71
self ,
72
72
mobject : Mobject ,
73
- direction : Vector3D | None = DOWN ,
73
+ direction : Point3DLike = DOWN ,
74
74
buff : float = 0.2 ,
75
75
sharpness : float = 2 ,
76
76
stroke_width : float = 0 ,
77
77
fill_opacity : float = 1.0 ,
78
78
background_stroke_width : float = 0 ,
79
79
background_stroke_color : ParsableManimColor = BLACK ,
80
- ** kwargs ,
80
+ ** kwargs : Any ,
81
81
):
82
82
path_string_template = (
83
83
"m0.01216 0c-0.01152 0-0.01216 6.103e-4 -0.01216 0.01311v0.007762c0.06776 "
@@ -130,7 +130,7 @@ def __init__(
130
130
for mob in mobject , self :
131
131
mob .rotate (angle , about_point = ORIGIN )
132
132
133
- def put_at_tip (self , mob : Mobject , use_next_to : bool = True , ** kwargs ) :
133
+ def put_at_tip (self , mob : Mobject , use_next_to : bool = True , ** kwargs : Any ) -> Self :
134
134
"""Puts the given mobject at the brace tip.
135
135
136
136
Parameters
@@ -153,7 +153,7 @@ def put_at_tip(self, mob: Mobject, use_next_to: bool = True, **kwargs):
153
153
mob .shift (self .get_direction () * shift_distance )
154
154
return self
155
155
156
- def get_text (self , * text , ** kwargs ) :
156
+ def get_text (self , * text : str , ** kwargs : Any ) -> Tex :
157
157
"""Places the text at the brace tip.
158
158
159
159
Parameters
@@ -172,7 +172,7 @@ def get_text(self, *text, **kwargs):
172
172
self .put_at_tip (text_mob , ** kwargs )
173
173
return text_mob
174
174
175
- def get_tex (self , * tex , ** kwargs ) :
175
+ def get_tex (self , * tex : str , ** kwargs : Any ) -> MathTex :
176
176
"""Places the tex at the brace tip.
177
177
178
178
Parameters
@@ -191,15 +191,15 @@ def get_tex(self, *tex, **kwargs):
191
191
self .put_at_tip (tex_mob , ** kwargs )
192
192
return tex_mob
193
193
194
- def get_tip (self ):
194
+ def get_tip (self ) -> Point3D :
195
195
"""Returns the point at the brace tip."""
196
196
# Returns the position of the seventh point in the path, which is the tip.
197
197
if config ["renderer" ] == "opengl" :
198
198
return self .points [34 ]
199
199
200
200
return self .points [28 ] # = 7*4
201
201
202
- def get_direction (self ):
202
+ def get_direction (self ) -> Vector3D :
203
203
"""Returns the direction from the center to the brace tip."""
204
204
vect = self .get_tip () - self .get_center ()
205
205
return vect / np .linalg .norm (vect )
@@ -233,12 +233,12 @@ def __init__(
233
233
self ,
234
234
obj : Mobject ,
235
235
text : str ,
236
- brace_direction : np . ndarray = DOWN ,
237
- label_constructor : type = MathTex ,
236
+ brace_direction : Point3DLike = DOWN ,
237
+ label_constructor : type [ SingleStringMathTex | Text ] = MathTex ,
238
238
font_size : float = DEFAULT_FONT_SIZE ,
239
239
buff : float = 0.2 ,
240
- brace_config : dict | None = None ,
241
- ** kwargs ,
240
+ brace_config : dict [ str , Any ] | None = None ,
241
+ ** kwargs : Any ,
242
242
):
243
243
self .label_constructor = label_constructor
244
244
super ().__init__ (** kwargs )
@@ -249,37 +249,48 @@ def __init__(
249
249
self .brace = Brace (obj , brace_direction , buff , ** brace_config )
250
250
251
251
if isinstance (text , (tuple , list )):
252
- self .label = self .label_constructor (* text , font_size = font_size , ** kwargs )
252
+ self .label : VMobject = self .label_constructor (
253
+ * text , font_size = font_size , ** kwargs
254
+ )
253
255
else :
254
256
self .label = self .label_constructor (str (text ), font_size = font_size )
255
257
256
258
self .brace .put_at_tip (self .label )
257
259
self .add (self .brace , self .label )
258
260
259
- def creation_anim (self , label_anim = FadeIn , brace_anim = GrowFromCenter ):
261
+ def creation_anim (
262
+ self ,
263
+ label_anim : type [Animation ] = FadeIn ,
264
+ brace_anim : type [Animation ] = GrowFromCenter ,
265
+ ) -> AnimationGroup :
260
266
return AnimationGroup (brace_anim (self .brace ), label_anim (self .label ))
261
267
262
- def shift_brace (self , obj , ** kwargs ) :
268
+ def shift_brace (self , obj : Mobject , ** kwargs : Any ) -> Self :
263
269
if isinstance (obj , list ):
264
270
obj = self .get_group_class ()(* obj )
265
271
self .brace = Brace (obj , self .brace_direction , ** kwargs )
266
272
self .brace .put_at_tip (self .label )
267
273
return self
268
274
269
- def change_label (self , * text , ** kwargs ):
270
- self .label = self .label_constructor (* text , ** kwargs )
271
-
275
+ def change_label (self , * text : str , ** kwargs : Any ) -> Self :
276
+ self .label = self .label_constructor (* text , ** kwargs ) # type: ignore[arg-type]
272
277
self .brace .put_at_tip (self .label )
273
278
return self
274
279
275
- def change_brace_label (self , obj , * text , ** kwargs ) :
280
+ def change_brace_label (self , obj : Mobject , * text : str , ** kwargs : Any ) -> Self :
276
281
self .shift_brace (obj )
277
282
self .change_label (* text , ** kwargs )
278
283
return self
279
284
280
285
281
286
class BraceText (BraceLabel ):
282
- def __init__ (self , obj , text , label_constructor = Tex , ** kwargs ):
287
+ def __init__ (
288
+ self ,
289
+ obj : Mobject ,
290
+ text : str ,
291
+ label_constructor : type [SingleStringMathTex | Text ] = Text ,
292
+ ** kwargs : Any ,
293
+ ):
283
294
super ().__init__ (obj , text , label_constructor = label_constructor , ** kwargs )
284
295
285
296
@@ -317,10 +328,10 @@ def construct(self):
317
328
318
329
def __init__ (
319
330
self ,
320
- point_1 : Point3DLike | None ,
321
- point_2 : Point3DLike | None ,
322
- direction : Vector3D | None = ORIGIN ,
323
- ** kwargs ,
331
+ point_1 : Point3DLike ,
332
+ point_2 : Point3DLike ,
333
+ direction : Point3DLike = ORIGIN ,
334
+ ** kwargs : Any ,
324
335
):
325
336
if all (direction == ORIGIN ):
326
337
line_vector = np .array (point_2 ) - np .array (point_1 )
@@ -386,8 +397,8 @@ def construct(self):
386
397
def __init__ (
387
398
self ,
388
399
arc : Arc | None = None ,
389
- direction : Sequence [ float ] = RIGHT ,
390
- ** kwargs ,
400
+ direction : Point3DLike = RIGHT ,
401
+ ** kwargs : Any ,
391
402
):
392
403
if arc is None :
393
404
arc = Arc (start_angle = - 1 , angle = 2 , radius = 1 )
0 commit comments