Repository: ManimCommunity/manim
File: manim/mobject/shape_matchers.py (Python)

Code before:
"""Mobjects used to mark and annotate other mobjects."""

__all__ = ["SurroundingRectangle", "BackgroundRectangle", "Cross", "Underline"]


from ..constants import *
from ..mobject.geometry import Line, Rectangle
from ..mobject.types.vectorized_mobject import VGroup, VMobject
from ..utils.color import BLACK, RED, YELLOW, Color


class SurroundingRectangle(Rectangle):
    """A rectangle surrounding a `mobject`

    Examples
    --------

    .. manim:: SurroundingRectExample
        :save_last_frame:

        class SurroundingRectExample(Scene):
            def construct(self):
                title = Title("A Quote from Newton")
                quote = Text("If I have seen further than others, \\nit is by standing upon the shoulders of giants.", color=BLUE).scale(0.75)
                box = SurroundingRectangle(quote, color=YELLOW, buff=MED_LARGE_BUFF)
                self.add(title, box, quote)

    """

    def __init__(self, mobject, color=YELLOW, buff=SMALL_BUFF, **kwargs):
        self.color = color
        self.buff = buff
        Rectangle.__init__(
            self,
            color=color,
            width=mobject.width + 2 * self.buff,
            height=mobject.height + 2 * self.buff,
            **kwargs
        )
        self.move_to(mobject)


class BackgroundRectangle(SurroundingRectangle):
    """A background rectangle

    Examples
    --------

    .. manim:: ExampleBackgroundRectangle

Review comment (security):
This line is a bit too long, could you please break it up? Also, the escaped backslash actually confuses me, maybe using an r string would work as well instead?

```suggestion
                quote = Text(
                    r"If I have seen further than others, \n"
                    r"it is by standing upon the shoulders of giants.",
                    color=BLUE
                ).scale(0.75)
```

Code after:
"""Mobjects used to mark and annotate other mobjects."""

__all__ = ["SurroundingRectangle", "BackgroundRectangle", "Cross", "Underline"]


from ..constants import *
from ..mobject.geometry import Line, Rectangle
from ..mobject.types.vectorized_mobject import VGroup, VMobject
from ..utils.color import BLACK, RED, YELLOW, Color


class SurroundingRectangle(Rectangle):
    r"""A rectangle surrounding a :class:`~.Mobject`

    Examples
    --------

    .. manim:: SurroundingRectExample
        :save_last_frame:

        class SurroundingRectExample(Scene):
            def construct(self):
                title = Title("A Quote from Newton")
                quote = Text(
                    "If I have seen further than others, \n"
                    "it is by standing upon the shoulders of giants.",
                    color=BLUE
                ).scale(0.75)
                box = SurroundingRectangle(quote, color=YELLOW, buff=MED_LARGE_BUFF)
                self.add(title, box, quote)

    """

    def __init__(self, mobject, color=YELLOW, buff=SMALL_BUFF, **kwargs):
        self.color = color
        self.buff = buff
        Rectangle.__init__(
            self,
            color=color,
            width=mobject.width + 2 * self.buff,
            height=mobject.height + 2 * self.buff,
            **kwargs
        )
        self.move_to(mobject)


class BackgroundRectangle(SurroundingRectangle):
    """A background rectangle