mirror of
https://github.com/3b1b/manim.git
synced 2025-08-05 16:49:03 +00:00
Change how bounding box points are calculated, in anticipation of a time when these are more intelligently cached
This commit is contained in:
parent
574b464a3c
commit
095a3ef28c
1 changed files with 27 additions and 24 deletions
|
@ -51,8 +51,9 @@ class Mobject(Container):
|
||||||
self.name = self.__class__.__name__
|
self.name = self.__class__.__name__
|
||||||
self.updaters = []
|
self.updaters = []
|
||||||
self.updating_suspended = False
|
self.updating_suspended = False
|
||||||
|
|
||||||
self.reset_points()
|
self.reset_points()
|
||||||
self.init_points() # TODO, rename this to "init_points?"
|
self.init_points()
|
||||||
self.init_colors()
|
self.init_colors()
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
|
@ -237,9 +238,9 @@ class Mobject(Container):
|
||||||
|
|
||||||
def shift(self, *vectors):
|
def shift(self, *vectors):
|
||||||
total_vector = reduce(op.add, vectors)
|
total_vector = reduce(op.add, vectors)
|
||||||
for mob in self.family_members_with_points():
|
for mob in self.get_family():
|
||||||
mob.points = mob.points.astype('float')
|
if len(mob.points) > 0:
|
||||||
mob.points += total_vector
|
mob.points += total_vector
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def scale(self, scale_factor, **kwargs):
|
def scale(self, scale_factor, **kwargs):
|
||||||
|
@ -702,17 +703,17 @@ class Mobject(Container):
|
||||||
]
|
]
|
||||||
|
|
||||||
def get_merged_array(self, array_attr):
|
def get_merged_array(self, array_attr):
|
||||||
result = getattr(self, array_attr)
|
return np.vstack([
|
||||||
for submob in self.submobjects:
|
getattr(sm, array_attr)
|
||||||
result = np.append(
|
for sm in self.family_members_with_points()
|
||||||
result, submob.get_merged_array(array_attr),
|
])
|
||||||
axis=0
|
|
||||||
)
|
|
||||||
submob.get_merged_array(array_attr)
|
|
||||||
return result
|
|
||||||
|
|
||||||
def get_all_points(self):
|
def get_all_points(self):
|
||||||
return self.get_merged_array("points")
|
arrays = [sm.points for sm in self.family_members_with_points()]
|
||||||
|
if arrays:
|
||||||
|
return np.vstack(arrays)
|
||||||
|
else:
|
||||||
|
return np.zeros((0, self.dim))
|
||||||
|
|
||||||
# Getters
|
# Getters
|
||||||
|
|
||||||
|
@ -734,20 +735,22 @@ class Mobject(Container):
|
||||||
return np.max(values)
|
return np.max(values)
|
||||||
|
|
||||||
def get_bounding_box_point(self, direction):
|
def get_bounding_box_point(self, direction):
|
||||||
"""
|
|
||||||
Picture a box bounding the mobject. Such a box has
|
|
||||||
9 'critical points': 4 corners, 4 edge center, the
|
|
||||||
center. This returns one of them.
|
|
||||||
"""
|
|
||||||
result = np.zeros(self.dim)
|
result = np.zeros(self.dim)
|
||||||
|
bb = self.get_bounding_box()
|
||||||
|
result[direction < 0] = bb[0, direction < 0]
|
||||||
|
result[direction == 0] = bb[1, direction == 0]
|
||||||
|
result[direction > 0] = bb[2, direction > 0]
|
||||||
|
return result
|
||||||
|
|
||||||
|
def get_bounding_box(self):
|
||||||
all_points = self.get_points_defining_boundary()
|
all_points = self.get_points_defining_boundary()
|
||||||
if len(all_points) == 0:
|
if len(all_points) == 0:
|
||||||
return result
|
return np.zeros((3, self.dim))
|
||||||
for dim in range(self.dim):
|
else:
|
||||||
result[dim] = self.get_extremum_along_dim(
|
# Lower left and upper right corners
|
||||||
all_points, dim=dim, key=direction[dim]
|
dl = np.apply_along_axis(np.min, 0, all_points)
|
||||||
)
|
ur = np.apply_along_axis(np.max, 0, all_points)
|
||||||
return result
|
return np.array([dl, (dl + ur) / 2, ur])
|
||||||
|
|
||||||
# Pseudonyms for more general get_bounding_box_point method
|
# Pseudonyms for more general get_bounding_box_point method
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue