mirror of
https://github.com/3b1b/manim.git
synced 2025-11-14 09:17:51 +00:00
Factor out computing bounding box
This commit is contained in:
parent
521e3ef143
commit
65f4f4bd29
1 changed files with 7 additions and 7 deletions
|
|
@ -190,10 +190,12 @@ class Mobject(object):
|
|||
return self.get_num_points() > 0
|
||||
|
||||
def get_bounding_box(self):
|
||||
if not self.needs_new_bounding_box:
|
||||
return self.data["bounding_box"]
|
||||
if self.needs_new_bounding_box:
|
||||
self.data["bounding_box"] = self.compute_bounding_box()
|
||||
self.needs_new_bounding_box = False
|
||||
return self.data["bounding_box"]
|
||||
|
||||
# all_points = self.get_all_points()
|
||||
def compute_bounding_box(self):
|
||||
all_points = np.vstack([
|
||||
self.get_points(),
|
||||
*(
|
||||
|
|
@ -203,15 +205,13 @@ class Mobject(object):
|
|||
)
|
||||
])
|
||||
if len(all_points) == 0:
|
||||
self.data["bounding_box"] = np.zeros((3, self.dim))
|
||||
return np.zeros((3, self.dim))
|
||||
else:
|
||||
# Lower left and upper right corners
|
||||
mins = all_points.min(0)
|
||||
maxs = all_points.max(0)
|
||||
mids = (mins + maxs) / 2
|
||||
self.data["bounding_box"] = np.array([mins, mids, maxs])
|
||||
self.needs_new_bounding_box = False
|
||||
return self.data["bounding_box"]
|
||||
return np.array([mins, mids, maxs])
|
||||
|
||||
def refresh_bounding_box(self, recurse_down=False, recurse_up=True):
|
||||
for mob in self.get_family(recurse_down):
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue