diff --git a/manimlib/mobject/shape_matchers.py b/manimlib/mobject/shape_matchers.py index ce0b5097..29551878 100644 --- a/manimlib/mobject/shape_matchers.py +++ b/manimlib/mobject/shape_matchers.py @@ -2,50 +2,63 @@ from __future__ import annotations from colour import Color -from manimlib.constants import BLACK, RED, YELLOW +from manimlib.constants import BLACK, RED, YELLOW, WHITE from manimlib.constants import DL, DOWN, DR, LEFT, RIGHT, UL, UR from manimlib.constants import SMALL_BUFF from manimlib.mobject.geometry import Line from manimlib.mobject.geometry import Rectangle from manimlib.mobject.types.vectorized_mobject import VGroup from manimlib.mobject.types.vectorized_mobject import VMobject -from manimlib.utils.config_ops import digest_config from manimlib.utils.customization import get_customization from typing import TYPE_CHECKING if TYPE_CHECKING: + from typing import Sequence from manimlib.mobject.mobject import Mobject from manimlib.constants import ManimColor class SurroundingRectangle(Rectangle): - CONFIG = { - "color": YELLOW, - "buff": SMALL_BUFF, - } - - def __init__(self, mobject: Mobject, **kwargs): - digest_config(self, kwargs) - kwargs["width"] = mobject.get_width() + 2 * self.buff - kwargs["height"] = mobject.get_height() + 2 * self.buff - Rectangle.__init__(self, **kwargs) + def __init__( + self, + mobject: Mobject, + buff: float = SMALL_BUFF, + color: ManimColor = YELLOW, + **kwargs + ): + super().__init__( + width=mobject.get_width() + 2 * buff, + height=mobject.get_height() + 2 * buff, + color=color, + **kwargs + ) self.move_to(mobject) class BackgroundRectangle(SurroundingRectangle): - CONFIG = { - "stroke_width": 0, - "stroke_opacity": 0, - "fill_opacity": 0.75, - "buff": 0 - } - - def __init__(self, mobject: Mobject, color: ManimColor = None, **kwargs): + def __init__( + self, + mobject: Mobject, + color: ManimColor = None, + stroke_width: float = 0, + stroke_opacity: float = 0, + fill_opacity: float = 0.75, + buff: float = 0, + **kwargs + ): if color is None: color = get_customization()['style']['background_color'] - SurroundingRectangle.__init__(self, mobject, color=color, **kwargs) - self.original_fill_opacity = self.fill_opacity + super().__init__( + mobject, + color=color, + stroke_width=stroke_width, + stroke_opacity=stroke_opacity, + fill_opacity=fill_opacity, + buff=buff, + **kwargs + ) + self.original_fill_opacity = fill_opacity def pointwise_become_partial(self, mobject: Mobject, a: float, b: float): self.set_fill(opacity=b * self.original_fill_opacity) @@ -74,27 +87,37 @@ class BackgroundRectangle(SurroundingRectangle): class Cross(VGroup): - CONFIG = { - "stroke_color": RED, - "stroke_width": [0, 6, 0], - } - - def __init__(self, mobject: Mobject, **kwargs): + def __init__( + self, + mobject: Mobject, + stroke_color: ManimColor = RED, + stroke_width: float | Sequence[float] = [0, 6, 0], + **kwargs + ): super().__init__( Line(UL, DR), Line(UR, DL), ) self.insert_n_curves(20) self.replace(mobject, stretch=True) - self.set_stroke(self.stroke_color, width=self.stroke_width) + self.set_stroke(stroke_color, width=stroke_width) class Underline(Line): - CONFIG = { - "buff": SMALL_BUFF, - } - - def __init__(self, mobject: Mobject, **kwargs): - super().__init__(LEFT, RIGHT, **kwargs) + def __init__( + self, + mobject: Mobject, + buff: float = SMALL_BUFF, + stroke_color=WHITE, + stroke_width: float | Sequence[float] = [0, 3, 3, 0], + **kwargs + ): + super().__init__( + LEFT, RIGHT, + stroke_color=stroke_color, + stroke_width=stroke_width, + **kwargs + ) + self.insert_n_curves(30) self.match_width(mobject) - self.next_to(mobject, DOWN, buff=self.buff) + self.next_to(mobject, DOWN, buff=buff)