Kill config in svg_mobject

This commit is contained in:
Grant Sanderson 2022-12-15 12:48:06 -08:00
parent c2766c9837
commit c55374245d

View file

@ -20,6 +20,11 @@ from manimlib.utils.images import get_full_vector_image_path
from manimlib.utils.iterables import hash_obj from manimlib.utils.iterables import hash_obj
from manimlib.utils.simple_functions import hash_string from manimlib.utils.simple_functions import hash_string
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from manimlib.constants import ManimColor
SVG_HASH_TO_MOB_MAP: dict[int, VMobject] = {} SVG_HASH_TO_MOB_MAP: dict[int, VMobject] = {}
@ -29,36 +34,51 @@ def _convert_point_to_3d(x: float, y: float) -> np.ndarray:
class SVGMobject(VMobject): class SVGMobject(VMobject):
CONFIG = { file_name: str = ""
"should_center": True,
"height": 2, def __init__(
"width": None, self,
"file_name": None, file_name: str = "",
should_center: bool = True,
height: float | None = 2.0,
width: float | None = None,
# Style that overrides the original svg # Style that overrides the original svg
"color": None, color: ManimColor = None,
"opacity": None, fill_color: ManimColor = None,
"fill_color": None, fill_opacity: float | None = None,
"fill_opacity": None, stroke_width: float | None = 0.0,
"stroke_width": None, stroke_color: ManimColor = None,
"stroke_color": None, stroke_opacity: float | None = None,
"stroke_opacity": None,
# Style that fills only when not specified # Style that fills only when not specified
# If None, regarded as default values from svg standard # If None, regarded as default values from svg standard
"svg_default": { svg_default: dict = dict(
"color": None, color=None,
"opacity": None, opacity=None,
"fill_color": None, fill_color=None,
"fill_opacity": None, fill_opacity=None,
"stroke_width": None, stroke_width=None,
"stroke_color": None, stroke_color=None,
"stroke_opacity": None, stroke_opacity=None,
}, ),
"path_string_config": {}, path_string_config: dict = dict(),
} **kwargs
):
def __init__(self, file_name: str | None = None, **kwargs):
super().__init__(**kwargs)
self.file_name = file_name or self.file_name self.file_name = file_name or self.file_name
self.should_center = should_center
self.height = height
self.width = width
self.svg_default = svg_default
self.path_string_config = path_string_config
super().__init__(
color=color,
fill_color=fill_color,
fill_opacity=fill_opacity,
stroke_width=stroke_width,
stroke_color=stroke_color,
stroke_opacity=stroke_opacity,
**kwargs
)
self.init_svg_mobject() self.init_svg_mobject()
self.init_colors() self.init_colors()
self.move_into_position() self.move_into_position()
@ -268,16 +288,20 @@ class SVGMobject(VMobject):
class VMobjectFromSVGPath(VMobject): class VMobjectFromSVGPath(VMobject):
CONFIG = { def __init__(
"long_lines": False, self,
"should_subdivide_sharp_curves": False, path_obj: se.Path,
"should_remove_null_curves": False, long_lines: bool = False,
} should_subdivide_sharp_curves: bool = False,
should_remove_null_curves: bool = False,
def __init__(self, path_obj: se.Path, **kwargs): **kwargs
):
# Get rid of arcs # Get rid of arcs
path_obj.approximate_arcs_with_quads() path_obj.approximate_arcs_with_quads()
self.path_obj = path_obj self.path_obj = path_obj
self.long_lines = long_lines
self.should_subdivide_sharp_curves = should_subdivide_sharp_curves
self.should_remove_null_curves = should_remove_null_curves
super().__init__(**kwargs) super().__init__(**kwargs)
def init_points(self) -> None: def init_points(self) -> None: