Skip to content

Allow :class:.SurroundingRectangle to accept multiple Mobjects #3964

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
be10da1
Implement SurroundingRectangle.multiple and BackgroundRectangle.multiple
Boris-Filin Oct 18, 2024
8487b44
Merge branch 'main' of https://github.com/ManimCommunity/manim into 3…
Boris-Filin Oct 20, 2024
cc7b91e
Integrate SurroundingRectangle constructor for multiple objects into …
Boris-Filin Oct 20, 2024
faf45b4
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 20, 2024
7dd49b0
SurroundingRectangle now takes multiple Mobjects as positional args
Boris-Filin Oct 23, 2024
b208e71
Add tests for multiple Mobjects in SurroundingRectangle
Boris-Filin Oct 23, 2024
979f2ee
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 23, 2024
7f323b6
Merge branch 'main' into 3863-SurroundingRectangle-mobjects
Boris-Filin Oct 23, 2024
122ffff
Fix example that was not using keyword args for SurroundingRectangle
Boris-Filin Oct 23, 2024
3b8a766
Remove duplicate code from BackgroundRectangle
Boris-Filin Oct 23, 2024
dfecbfd
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 23, 2024
9a29bd9
Add typing to manim argument of SurroundingRecrabgle constructor
Boris-Filin Oct 24, 2024
90fa53d
Remove redundant argument from test_SurroundingRectangle
Boris-Filin Oct 24, 2024
71456aa
Merge branch 'main' of https://github.com/ManimCommunity/manim into 3…
Boris-Filin Oct 24, 2024
71d2b92
Merge branch '3863-SurroundingRectangle-mobjects' of https://github.c…
Boris-Filin Oct 24, 2024
23db5f8
Remove type check from SurroundingRectangle
Boris-Filin Oct 25, 2024
b4063e4
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 25, 2024
55b56f4
Fix missing line issue
Boris-Filin Oct 25, 2024
ec8da3b
resolve merge conflict
Boris-Filin Oct 25, 2024
dee8a4c
Merge branch '3863-SurroundingRectangle-mobjects' of https://github.c…
Boris-Filin Oct 25, 2024
7f94fd5
Fix Group import
Boris-Filin Oct 25, 2024
434d7d7
Move Group import into the body of SurroundingRectangle
Boris-Filin Oct 25, 2024
9aee0b5
Return type checking to SurroundingRectangle
Boris-Filin Oct 25, 2024
e218540
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 25, 2024
0cf407a
small change to error message
JasonGrace2282 Oct 29, 2024
f1fdeeb
Merge branch 'main' into 3863-SurroundingRectangle-mobjects
JasonGrace2282 Oct 29, 2024
aa24893
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 29, 2024
b3f91a0
fix missing imports
JasonGrace2282 Oct 29, 2024
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
2 changes: 1 addition & 1 deletion docs/source/examples.rst
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ Basic Concepts
[[i * 256 / n for i in range(0, n)] for _ in range(0, n)]
)
image = ImageMobject(imageArray).scale(2)
image.background_rectangle = SurroundingRectangle(image, GREEN)
image.background_rectangle = SurroundingRectangle(image, color=GREEN)
self.add(image, image.background_rectangle)

.. manim:: BooleanOperations
Expand Down
4 changes: 2 additions & 2 deletions manim/animation/indication.py
Original file line number Diff line number Diff line change
Expand Up @@ -608,8 +608,8 @@ def __init__(
if shape is Rectangle:
frame = SurroundingRectangle(
mobject,
color,
buff,
color=color,
buff=buff,
stroke_width=stroke_width,
)
elif shape is Circle:
Expand Down
31 changes: 23 additions & 8 deletions manim/mobject/geometry/shape_matchers.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,15 @@

from typing_extensions import Self

from manim import config, logger
from manim.constants import *
from manim import logger
from manim._config import config
from manim.constants import (
DOWN,
LEFT,
RIGHT,
SMALL_BUFF,
UP,
)
from manim.mobject.geometry.line import Line
from manim.mobject.geometry.polygram import RoundedRectangle
from manim.mobject.mobject import Mobject
Expand Down Expand Up @@ -43,21 +50,29 @@ def construct(self):

def __init__(
self,
mobject: Mobject,
*mobjects: Mobject,
color: ParsableManimColor = YELLOW,
buff: float = SMALL_BUFF,
corner_radius: float = 0.0,
**kwargs: Any,
) -> None:
from manim.mobject.mobject import Group

if not all(isinstance(mob, Mobject) for mob in mobjects):
raise TypeError(
"Expected all inputs for parameter mobjects to be a Mobjects"
)

group = Group(*mobjects)
super().__init__(
color=color,
width=mobject.width + 2 * buff,
height=mobject.height + 2 * buff,
width=group.width + 2 * buff,
height=group.height + 2 * buff,
corner_radius=corner_radius,
**kwargs,
)
self.buff = buff
self.move_to(mobject)
self.move_to(group)


class BackgroundRectangle(SurroundingRectangle):
Expand Down Expand Up @@ -87,7 +102,7 @@ def construct(self):

def __init__(
self,
mobject: Mobject,
*mobjects: Mobject,
color: ParsableManimColor | None = None,
stroke_width: float = 0,
stroke_opacity: float = 0,
Expand All @@ -99,7 +114,7 @@ def __init__(
color = config.background_color

super().__init__(
mobject,
*mobjects,
color=color,
stroke_width=stroke_width,
stroke_opacity=stroke_opacity,
Expand Down
15 changes: 12 additions & 3 deletions tests/module/mobject/geometry/test_unit_geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import numpy as np

from manim import BackgroundRectangle, Circle, Sector, Square
from manim import BackgroundRectangle, Circle, Sector, Square, SurroundingRectangle

logger = logging.getLogger(__name__)

Expand All @@ -15,9 +15,18 @@ def test_get_arc_center():
)


def test_SurroundingRectangle():
circle = Circle()
square = Square()
sr = SurroundingRectangle(circle, square)
sr.set_style(fill_opacity=0.42)
assert sr.get_fill_opacity() == 0.42


def test_BackgroundRectangle(manim_caplog):
c = Circle()
bg = BackgroundRectangle(c)
circle = Circle()
square = Square()
bg = BackgroundRectangle(circle, square)
bg.set_style(fill_opacity=0.42)
assert bg.get_fill_opacity() == 0.42
bg.set_style(fill_opacity=1, hello="world")
Expand Down
Loading