Skip to content

armgit / manim

Public Imported from GitHub
0

A community-maintained Python framework for creating mathematical animations.

Fix arguments of overridden `set_style` for `BackgroundRectangle` (#2658)

dawn*squirrylf43f54365ab9
diff --git a/manim/mobject/geometry/shape_matchers.py b/manim/mobject/geometry/shape_matchers.py
index 5aad30309..4376213ef 100644
--- a/manim/mobject/geometry/shape_matchers.py
+++ b/manim/mobject/geometry/shape_matchers.py
@@ -4,7 +4,7 @@ from __future__ import annotations
__all__ = ["SurroundingRectangle", "BackgroundRectangle", "Cross", "Underline"]
-from manim import config
+from manim import config, logger
from manim.constants import *
from manim.mobject.geometry.line import Line
from manim.mobject.geometry.polygram import RoundedRectangle
@@ -104,21 +104,20 @@ class BackgroundRectangle(SurroundingRectangle):
self.set_fill(opacity=b * self.original_fill_opacity)
return self
- def set_style(
- self,
- stroke_color=None,
- stroke_width=None,
- fill_color=None,
- fill_opacity=None,
- family=True,
- ):
+ def set_style(self, fill_opacity, **kwargs):
# Unchangeable style, except for fill_opacity
+ # All other style arguments are ignored
super().set_style(
stroke_color=BLACK,
stroke_width=0,
fill_color=BLACK,
fill_opacity=fill_opacity,
)
+ if len(kwargs) > 0:
+ logger.info(
+ "Argument %s is ignored in BackgroundRectangle.set_style.",
+ kwargs,
+ )
return self
def get_fill_color(self):
diff --git a/tests/test_unit_geometry.py b/tests/test_unit_geometry.py
index b85cc0805..23b944ece 100644
--- a/tests/test_unit_geometry.py
+++ b/tests/test_unit_geometry.py
@@ -1,9 +1,26 @@
from __future__ import annotations
+import logging
+
import numpy as np
-from manim import Sector
+logger = logging.getLogger(__name__)
+
+from manim import BackgroundRectangle, Circle, Sector
def test_get_arc_center():
assert np.all(Sector(arc_center=[1, 2, 0]).get_arc_center() == [1, 2, 0])
+
+
+def test_BackgroundRectangle(caplog):
+ caplog.set_level(logging.INFO)
+ c = Circle()
+ bg = BackgroundRectangle(c)
+ bg.set_style(fill_opacity=0.42)
+ assert bg.get_fill_opacity() == 0.42
+ bg.set_style(fill_opacity=1, hello="world")
+ assert (
+ "Argument {'hello': 'world'} is ignored in BackgroundRectangle.set_style."
+ in caplog.text
+ )