Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions manim/mobject/geometry/shape_matchers.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def __init__(
self,
*mobjects: Mobject,
color: ParsableManimColor = YELLOW,
buff: float = SMALL_BUFF,
buff: float | tuple[float, float] = SMALL_BUFF,
corner_radius: float = 0.0,
**kwargs: Any,
) -> None:
Expand All @@ -64,11 +64,17 @@ def __init__(
"Expected all inputs for parameter mobjects to be a Mobjects"
)

if isinstance(buff, tuple):
buff_x = buff[0]
buff_y = buff[1]
else:
buff_x = buff_y = buff

group = Group(*mobjects)
super().__init__(
color=color,
width=group.width + 2 * buff,
height=group.height + 2 * buff,
width=group.width + 2 * buff_x,
height=group.height + 2 * buff_y,
corner_radius=corner_radius,
**kwargs,
)
Expand Down Expand Up @@ -108,7 +114,7 @@ def __init__(
stroke_width: float = 0,
stroke_opacity: float = 0,
fill_opacity: float = 0.75,
buff: float = 0,
buff: float | tuple[float, float] = 0,
**kwargs: Any,
) -> None:
if color is None:
Expand Down
11 changes: 11 additions & 0 deletions tests/module/mobject/geometry/test_unit_geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,17 @@ def test_SurroundingRectangle():
assert sr.get_fill_opacity() == 0.42


def test_SurroundingRectangle_buff():
sq = Square()
rect1 = SurroundingRectangle(sq, buff=1)
assert rect1.width == sq.width + 2
assert rect1.height == sq.height + 2

rect2 = SurroundingRectangle(sq, buff=(1, 2))
assert rect2.width == sq.width + 2
assert rect2.height == sq.height + 4


def test_BackgroundRectangle(manim_caplog):
circle = Circle()
square = Square()
Expand Down
Loading