From ddfc3a656738577094a4a597b5b92f04ceb391f7 Mon Sep 17 00:00:00 2001 From: Grant Sanderson Date: Tue, 12 Jan 2021 07:27:32 -1000 Subject: [PATCH] Replace lingering .points references --- manimlib/animation/indication.py | 2 +- manimlib/animation/movement.py | 2 +- manimlib/mobject/changing.py | 4 ++-- manimlib/mobject/mobject.py | 3 +++ manimlib/mobject/numbers.py | 10 -------- manimlib/mobject/svg/text_mobject.py | 4 ++-- manimlib/mobject/types/point_cloud_mobject.py | 2 +- manimlib/mobject/types/surface.py | 9 +++++-- manimlib/mobject/value_tracker.py | 24 ++++++++++--------- manimlib/once_useful_constructs/fractals.py | 2 +- manimlib/once_useful_constructs/light.py | 4 ++-- 11 files changed, 33 insertions(+), 33 deletions(-) diff --git a/manimlib/animation/indication.py b/manimlib/animation/indication.py index 96ef36f7..a25ea932 100644 --- a/manimlib/animation/indication.py +++ b/manimlib/animation/indication.py @@ -260,7 +260,7 @@ class WiggleOutThenIn(Animation): return self.mobject.get_center() def interpolate_submobject(self, submobject, starting_sumobject, alpha): - submobject.points[:, :] = starting_sumobject.points + submobject.match_points(starting_sumobject) submobject.scale( interpolate(1, self.scale_value, there_and_back(alpha)), about_point=self.get_scale_about_point() diff --git a/manimlib/animation/movement.py b/manimlib/animation/movement.py index f6a3ec05..4b5136c5 100644 --- a/manimlib/animation/movement.py +++ b/manimlib/animation/movement.py @@ -20,7 +20,7 @@ class Homotopy(Animation): return lambda p: self.homotopy(*p, t) def interpolate_submobject(self, submob, start, alpha): - submob.points = start.points + submob.match_points(start) submob.apply_function( self.function_at_time_t(alpha), **self.apply_function_kwargs diff --git a/manimlib/mobject/changing.py b/manimlib/mobject/changing.py index 20f74a4f..2b854eaf 100644 --- a/manimlib/mobject/changing.py +++ b/manimlib/mobject/changing.py @@ -89,10 +89,10 @@ class TracedPath(VMobject): self.add_line_to(new_point) else: # Set the end to be the new point - self.points[-1] = new_point + self.get_points()[-1] = new_point # Second to last point 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: self.add_line_to(new_point) diff --git a/manimlib/mobject/mobject.py b/manimlib/mobject/mobject.py index 1459ac94..afc557e7 100644 --- a/manimlib/mobject/mobject.py +++ b/manimlib/mobject/mobject.py @@ -111,6 +111,9 @@ class Mobject(object): self.data["points"][-len(new_points):] = new_points return self + def match_points(self, mobject): + self.set_points(mobject.get_points()) + def get_points(self): return self.data["points"] diff --git a/manimlib/mobject/numbers.py b/manimlib/mobject/numbers.py index 515454e4..f46c26ee 100644 --- a/manimlib/mobject/numbers.py +++ b/manimlib/mobject/numbers.py @@ -121,21 +121,11 @@ class DecimalNumber(VMobject): full_config["font_size"] = self.font_size full_config.update(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.match_style(self) if self.is_fixed_in_frame: new_decimal.fix_in_frame() - - old_family = self.get_family() 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 return self diff --git a/manimlib/mobject/svg/text_mobject.py b/manimlib/mobject/svg/text_mobject.py index 48f12559..5a9873f5 100644 --- a/manimlib/mobject/svg/text_mobject.py +++ b/manimlib/mobject/svg/text_mobject.py @@ -56,9 +56,9 @@ class Text(SVGMobject): nppc = self.n_points_per_curve for each in self: - if len(each.points) == 0: + if len(each.get_points()) == 0: continue - points = each.points + points = each.get_points() last = points[0] each.clear_points() for index, point in enumerate(points): diff --git a/manimlib/mobject/types/point_cloud_mobject.py b/manimlib/mobject/types/point_cloud_mobject.py index 6c1a0848..616e83ca 100644 --- a/manimlib/mobject/types/point_cloud_mobject.py +++ b/manimlib/mobject/types/point_cloud_mobject.py @@ -45,7 +45,7 @@ class PMobject(Mobject): def set_color_by_gradient(self, *colors): self.data["rgbas"] = np.array(list(map( color_to_rgba, - color_gradient(colors, len(self.points)) + color_gradient(colors, self.get_num_points()) ))) return self diff --git a/manimlib/mobject/types/surface.py b/manimlib/mobject/types/surface.py index 1399b641..de28d1e9 100644 --- a/manimlib/mobject/types/surface.py +++ b/manimlib/mobject/types/surface.py @@ -104,7 +104,7 @@ class ParametricSurface(Mobject): axis = self.prefered_creation_axis assert(isinstance(smobject, ParametricSurface)) if a <= 0 and b >= 1: - self.set_points(smobject.points) + self.match_points(smobject) return self nu, nv = smobject.resolution @@ -136,7 +136,12 @@ class ParametricSurface(Mobject): def sort_faces_back_to_front(self, vect=OUT): tri_is = self.triangle_indices 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): tri_is[k::3] = tri_is[k::3][indices] return self diff --git a/manimlib/mobject/value_tracker.py b/manimlib/mobject/value_tracker.py index 79cdedce..ab707a78 100644 --- a/manimlib/mobject/value_tracker.py +++ b/manimlib/mobject/value_tracker.py @@ -10,17 +10,23 @@ class ValueTracker(Mobject): uses for its update function, and by treating it as a mobject it can still be animated and manipulated just like anything else. """ + CONFIG = { + "value_type": np.float64, + } def __init__(self, value=0, **kwargs): - Mobject.__init__(self, **kwargs) - self.points = np.zeros((1, 3)) + super().__init__(**kwargs) 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): - return self.points[0, 0] + return self.data["value"][0, 0] def set_value(self, value): - self.points[0, 0] = value + self.data["value"][0, 0] = value return self def increment_value(self, d_value): @@ -42,10 +48,6 @@ class ExponentialValueTracker(ValueTracker): class ComplexValueTracker(ValueTracker): - def get_value(self): - return complex(*self.points[0, :2]) - - def set_value(self, z): - z = complex(z) - self.points[0, :2] = (z.real, z.imag) - return self + CONFIG = { + "value_type": np.complex128 + } diff --git a/manimlib/once_useful_constructs/fractals.py b/manimlib/once_useful_constructs/fractals.py index 4daa7270..6285f554 100644 --- a/manimlib/once_useful_constructs/fractals.py +++ b/manimlib/once_useful_constructs/fractals.py @@ -326,7 +326,7 @@ class FractalCurve(VMobject): self, *alpha_pair ) self.add(submobject) - self.points = np.zeros((0, 3)) + self.set_points(np.zeros((0, 3))) def init_colors(self): VMobject.init_colors(self) diff --git a/manimlib/once_useful_constructs/light.py b/manimlib/once_useful_constructs/light.py index 7bc15a6b..b10a8883 100644 --- a/manimlib/once_useful_constructs/light.py +++ b/manimlib/once_useful_constructs/light.py @@ -388,7 +388,7 @@ class LightSource(VMobject): def has_screen(self): if self.screen is None: return False - elif np.size(self.screen.points) == 0: + elif self.screen.get_num_points() == 0: return False else: return True @@ -572,7 +572,7 @@ class LightSource(VMobject): # add two control points for the outer cone if np.size(anchors) == 0: - self.shadow.points = [] + self.shadow.resize_points(0) return ray1 = anchors[source_index - 1] - projected_source