4
4
5
5
import os
6
6
from pathlib import Path
7
+ from typing import Any
7
8
from xml .etree import ElementTree as ET
8
9
9
10
import numpy as np
@@ -108,7 +109,7 @@ def __init__(
108
109
svg_default : dict | None = None ,
109
110
path_string_config : dict | None = None ,
110
111
use_svg_cache : bool = True ,
111
- ** kwargs ,
112
+ ** kwargs : Any ,
112
113
):
113
114
super ().__init__ (color = None , stroke_color = None , fill_color = None , ** kwargs )
114
115
@@ -121,10 +122,10 @@ def __init__(
121
122
self .color = color
122
123
self .opacity = opacity
123
124
self .fill_color = fill_color
124
- self .fill_opacity = fill_opacity
125
+ self .fill_opacity = fill_opacity # type: ignore[assignment]
125
126
self .stroke_color = stroke_color
126
- self .stroke_opacity = stroke_opacity
127
- self .stroke_width = stroke_width
127
+ self .stroke_opacity = stroke_opacity # type: ignore[assignment]
128
+ self .stroke_width = stroke_width # type: ignore[assignment]
128
129
if self .stroke_width is None :
129
130
self .stroke_width = 0
130
131
@@ -264,13 +265,13 @@ def get_mobjects_from(self, svg: se.SVG) -> list[VMobject]:
264
265
svg
265
266
The parsed SVG file.
266
267
"""
267
- result = []
268
+ result : list [ VMobject ] = []
268
269
for shape in svg .elements ():
269
270
# can we combine the two continue cases into one?
270
271
if isinstance (shape , se .Group ): # noqa: SIM114
271
272
continue
272
273
elif isinstance (shape , se .Path ):
273
- mob = self .path_to_mobject (shape )
274
+ mob : VMobject = self .path_to_mobject (shape )
274
275
elif isinstance (shape , se .SimpleLine ):
275
276
mob = self .line_to_mobject (shape )
276
277
elif isinstance (shape , se .Rect ):
@@ -424,7 +425,7 @@ def polyline_to_mobject(self, polyline: se.Polyline) -> VMobject:
424
425
return vmobject_class ().set_points_as_corners (points )
425
426
426
427
@staticmethod
427
- def text_to_mobject (text : se .Text ):
428
+ def text_to_mobject (text : se .Text ) -> VMobject :
428
429
"""Convert a text element to a vectorized mobject.
429
430
430
431
.. warning::
@@ -437,7 +438,7 @@ def text_to_mobject(text: se.Text):
437
438
The parsed SVG text.
438
439
"""
439
440
logger .warning (f"Unsupported element type: { type (text )} " )
440
- return
441
+ return # type: ignore[return-value]
441
442
442
443
def move_into_position (self ) -> None :
443
444
"""Scale and move the generated mobject into position."""
@@ -482,7 +483,7 @@ def __init__(
482
483
long_lines : bool = False ,
483
484
should_subdivide_sharp_curves : bool = False ,
484
485
should_remove_null_curves : bool = False ,
485
- ** kwargs ,
486
+ ** kwargs : Any ,
486
487
):
487
488
# Get rid of arcs
488
489
path_obj .approximate_arcs_with_quads ()
@@ -511,11 +512,11 @@ def init_points(self) -> None:
511
512
512
513
def handle_commands (self ) -> None :
513
514
all_points : list [np .ndarray ] = []
514
- last_move = None
515
+ last_move : np . ndarray = None
515
516
curve_start = None
516
517
last_true_move = None
517
518
518
- def move_pen (pt , * , true_move : bool = False ):
519
+ def move_pen (pt : np . ndarray , * , true_move : bool = False ) -> None :
519
520
nonlocal last_move , curve_start , last_true_move
520
521
last_move = pt
521
522
if curve_start is None :
@@ -525,25 +526,29 @@ def move_pen(pt, *, true_move: bool = False):
525
526
526
527
if self .n_points_per_curve == 4 :
527
528
528
- def add_cubic (start , cp1 , cp2 , end ):
529
+ def add_cubic (
530
+ start : np .ndarray , cp1 : np .ndarray , cp2 : np .ndarray , end : np .ndarray
531
+ ) -> None :
529
532
nonlocal all_points
530
533
assert len (all_points ) % 4 == 0 , len (all_points )
531
534
all_points += [start , cp1 , cp2 , end ]
532
535
move_pen (end )
533
536
534
- def add_quad (start , cp , end ) :
537
+ def add_quad (start : np . ndarray , cp : np . ndarray , end : np . ndarray ) -> None :
535
538
add_cubic (start , (start + cp + cp ) / 3 , (cp + cp + end ) / 3 , end )
536
539
move_pen (end )
537
540
538
- def add_line (start , end ) :
541
+ def add_line (start : np . ndarray , end : np . ndarray ) -> None :
539
542
add_cubic (
540
543
start , (start + start + end ) / 3 , (start + end + end ) / 3 , end
541
544
)
542
545
move_pen (end )
543
546
544
547
else :
545
548
546
- def add_cubic (start , cp1 , cp2 , end ):
549
+ def add_cubic (
550
+ start : np .ndarray , cp1 : np .ndarray , cp2 : np .ndarray , end : np .ndarray
551
+ ) -> None :
547
552
nonlocal all_points
548
553
assert len (all_points ) % 3 == 0 , len (all_points )
549
554
two_quads = get_quadratic_approximation_of_cubic (
@@ -556,13 +561,13 @@ def add_cubic(start, cp1, cp2, end):
556
561
all_points += two_quads [3 :].tolist ()
557
562
move_pen (end )
558
563
559
- def add_quad (start , cp , end ) :
564
+ def add_quad (start : np . ndarray , cp : np . ndarray , end : np . ndarray ) -> None :
560
565
nonlocal all_points
561
566
assert len (all_points ) % 3 == 0 , len (all_points )
562
567
all_points += [start , cp , end ]
563
568
move_pen (end )
564
569
565
- def add_line (start , end ) :
570
+ def add_line (start : np . ndarray , end : np . ndarray ) -> None :
566
571
add_quad (start , (start + end ) / 2 , end )
567
572
move_pen (end )
568
573
0 commit comments