Add surround method for Rectangles and SurroundingRectangles

This commit is contained in:
Grant Sanderson
2023-09-04 18:46:11 -04:00
parent fa798a2018
commit 87e4a71ca3
3 changed files with 24 additions and 8 deletions

View File

@ -7,7 +7,7 @@ import numpy as np
from manimlib.constants import DL, DOWN, DR, LEFT, ORIGIN, OUT, RIGHT, UL, UP, UR
from manimlib.constants import GREY_A, RED, WHITE, BLACK
from manimlib.constants import MED_SMALL_BUFF
from manimlib.constants import MED_SMALL_BUFF, SMALL_BUFF
from manimlib.constants import DEGREES, PI, TAU
from manimlib.mobject.mobject import Mobject
from manimlib.mobject.types.vectorized_mobject import DashedVMobject
@ -1046,6 +1046,12 @@ class Rectangle(Polygon):
self.set_width(width, stretch=True)
self.set_height(height, stretch=True)
def surround(self, mobject, buff=SMALL_BUFF) -> Self:
target_shape = np.array(mobject.get_shape()) + 2 * buff
self.set_shape(*target_shape)
self.move_to(mobject)
return self
class Square(Rectangle):
def __init__(self, side_length: float = 2.0, **kwargs):