Replace lingering .points references

This commit is contained in:
Grant Sanderson 2021-01-12 07:27:32 -10:00
parent 6b29691e0e
commit ddfc3a6567
11 changed files with 33 additions and 33 deletions

View file

@ -260,7 +260,7 @@ class WiggleOutThenIn(Animation):
return self.mobject.get_center() return self.mobject.get_center()
def interpolate_submobject(self, submobject, starting_sumobject, alpha): def interpolate_submobject(self, submobject, starting_sumobject, alpha):
submobject.points[:, :] = starting_sumobject.points submobject.match_points(starting_sumobject)
submobject.scale( submobject.scale(
interpolate(1, self.scale_value, there_and_back(alpha)), interpolate(1, self.scale_value, there_and_back(alpha)),
about_point=self.get_scale_about_point() about_point=self.get_scale_about_point()

View file

@ -20,7 +20,7 @@ class Homotopy(Animation):
return lambda p: self.homotopy(*p, t) return lambda p: self.homotopy(*p, t)
def interpolate_submobject(self, submob, start, alpha): def interpolate_submobject(self, submob, start, alpha):
submob.points = start.points submob.match_points(start)
submob.apply_function( submob.apply_function(
self.function_at_time_t(alpha), self.function_at_time_t(alpha),
**self.apply_function_kwargs **self.apply_function_kwargs

View file

@ -89,10 +89,10 @@ class TracedPath(VMobject):
self.add_line_to(new_point) self.add_line_to(new_point)
else: else:
# Set the end to be the new point # Set the end to be the new point
self.points[-1] = new_point self.get_points()[-1] = new_point
# Second to last point # Second to last point
nppcc = self.n_points_per_cubic_curve nppcc = self.n_points_per_cubic_curve
dist = get_norm(new_point - self.points[-nppcc]) dist = get_norm(new_point - self.get_points()[-nppcc])
if dist >= self.min_distance_to_new_point: if dist >= self.min_distance_to_new_point:
self.add_line_to(new_point) self.add_line_to(new_point)

View file

@ -111,6 +111,9 @@ class Mobject(object):
self.data["points"][-len(new_points):] = new_points self.data["points"][-len(new_points):] = new_points
return self return self
def match_points(self, mobject):
self.set_points(mobject.get_points())
def get_points(self): def get_points(self):
return self.data["points"] return self.data["points"]

View file

@ -121,21 +121,11 @@ class DecimalNumber(VMobject):
full_config["font_size"] = self.font_size full_config["font_size"] = self.font_size
full_config.update(config) full_config.update(config)
new_decimal = DecimalNumber(number, **full_config) new_decimal = DecimalNumber(number, **full_config)
# # Make sure last digit has constant height
# new_decimal.scale(
# self[-1].get_height() / new_decimal[-1].get_height()
# )
new_decimal.move_to(self, self.edge_to_fix) new_decimal.move_to(self, self.edge_to_fix)
new_decimal.match_style(self) new_decimal.match_style(self)
if self.is_fixed_in_frame: if self.is_fixed_in_frame:
new_decimal.fix_in_frame() new_decimal.fix_in_frame()
old_family = self.get_family()
self.set_submobjects(new_decimal.submobjects) self.set_submobjects(new_decimal.submobjects)
for mob in old_family:
# Dumb hack...due to how scene handles families
# of animated mobjects
mob.points[:] = 0
self.number = number self.number = number
return self return self

View file

@ -56,9 +56,9 @@ class Text(SVGMobject):
nppc = self.n_points_per_curve nppc = self.n_points_per_curve
for each in self: for each in self:
if len(each.points) == 0: if len(each.get_points()) == 0:
continue continue
points = each.points points = each.get_points()
last = points[0] last = points[0]
each.clear_points() each.clear_points()
for index, point in enumerate(points): for index, point in enumerate(points):

View file

@ -45,7 +45,7 @@ class PMobject(Mobject):
def set_color_by_gradient(self, *colors): def set_color_by_gradient(self, *colors):
self.data["rgbas"] = np.array(list(map( self.data["rgbas"] = np.array(list(map(
color_to_rgba, color_to_rgba,
color_gradient(colors, len(self.points)) color_gradient(colors, self.get_num_points())
))) )))
return self return self

View file

@ -104,7 +104,7 @@ class ParametricSurface(Mobject):
axis = self.prefered_creation_axis axis = self.prefered_creation_axis
assert(isinstance(smobject, ParametricSurface)) assert(isinstance(smobject, ParametricSurface))
if a <= 0 and b >= 1: if a <= 0 and b >= 1:
self.set_points(smobject.points) self.match_points(smobject)
return self return self
nu, nv = smobject.resolution nu, nv = smobject.resolution
@ -136,7 +136,12 @@ class ParametricSurface(Mobject):
def sort_faces_back_to_front(self, vect=OUT): def sort_faces_back_to_front(self, vect=OUT):
tri_is = self.triangle_indices tri_is = self.triangle_indices
indices = list(range(len(tri_is) // 3)) indices = list(range(len(tri_is) // 3))
indices.sort(key=lambda i: np.dot(self.points[tri_is[3 * i]], vect)) points = self.get_points()
def index_dot(index):
return np.dot(points[tri_is[3 * index]], vect)
indices.sort(key=index_dot)
for k in range(3): for k in range(3):
tri_is[k::3] = tri_is[k::3][indices] tri_is[k::3] = tri_is[k::3][indices]
return self return self

View file

@ -10,17 +10,23 @@ class ValueTracker(Mobject):
uses for its update function, and by treating it as a mobject it can uses for its update function, and by treating it as a mobject it can
still be animated and manipulated just like anything else. still be animated and manipulated just like anything else.
""" """
CONFIG = {
"value_type": np.float64,
}
def __init__(self, value=0, **kwargs): def __init__(self, value=0, **kwargs):
Mobject.__init__(self, **kwargs) super().__init__(**kwargs)
self.points = np.zeros((1, 3))
self.set_value(value) self.set_value(value)
def init_data(self):
super().init_data()
self.data["value"] = np.zeros((1, 1), dtype=self.value_type)
def get_value(self): def get_value(self):
return self.points[0, 0] return self.data["value"][0, 0]
def set_value(self, value): def set_value(self, value):
self.points[0, 0] = value self.data["value"][0, 0] = value
return self return self
def increment_value(self, d_value): def increment_value(self, d_value):
@ -42,10 +48,6 @@ class ExponentialValueTracker(ValueTracker):
class ComplexValueTracker(ValueTracker): class ComplexValueTracker(ValueTracker):
def get_value(self): CONFIG = {
return complex(*self.points[0, :2]) "value_type": np.complex128
}
def set_value(self, z):
z = complex(z)
self.points[0, :2] = (z.real, z.imag)
return self

View file

@ -326,7 +326,7 @@ class FractalCurve(VMobject):
self, *alpha_pair self, *alpha_pair
) )
self.add(submobject) self.add(submobject)
self.points = np.zeros((0, 3)) self.set_points(np.zeros((0, 3)))
def init_colors(self): def init_colors(self):
VMobject.init_colors(self) VMobject.init_colors(self)

View file

@ -388,7 +388,7 @@ class LightSource(VMobject):
def has_screen(self): def has_screen(self):
if self.screen is None: if self.screen is None:
return False return False
elif np.size(self.screen.points) == 0: elif self.screen.get_num_points() == 0:
return False return False
else: else:
return True return True
@ -572,7 +572,7 @@ class LightSource(VMobject):
# add two control points for the outer cone # add two control points for the outer cone
if np.size(anchors) == 0: if np.size(anchors) == 0:
self.shadow.points = [] self.shadow.resize_points(0)
return return
ray1 = anchors[source_index - 1] - projected_source ray1 = anchors[source_index - 1] - projected_source