From 41b4483fd17c775243c355e09656c1e2869b06c7 Mon Sep 17 00:00:00 2001 From: Grant Sanderson Date: Fri, 24 Mar 2017 17:27:09 -0700 Subject: [PATCH] Made Mobject.copy somewhat lighter-weight --- mobject/mobject.py | 12 ++++++++++-- mobject/vectorized_mobject.py | 4 +--- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/mobject/mobject.py b/mobject/mobject.py index b8339659..6305d15d 100644 --- a/mobject/mobject.py +++ b/mobject/mobject.py @@ -1,8 +1,8 @@ import numpy as np import operator as op import os +import copy from PIL import Image -from copy import deepcopy from colour import Color from helpers import * @@ -97,7 +97,15 @@ class Mobject(object): ) def copy(self): - return deepcopy(self) + copy_mobject = copy.copy(self) + copy_mobject.points = np.array(self.points) + copy_mobject.submobjects = [ + submob.copy() for submob in self.submobjects + ] + return copy_mobject + + def deepcopy(self): + return copy.deepcopy(self) def generate_target(self): self.target = None #Prevent exponential explosion diff --git a/mobject/vectorized_mobject.py b/mobject/vectorized_mobject.py index 27a6452c..c6fb8be6 100644 --- a/mobject/vectorized_mobject.py +++ b/mobject/vectorized_mobject.py @@ -200,9 +200,7 @@ class VMobject(Mobject): but will be tracked in a separate special list for when it comes time to display. """ - subpath_mobject = self.copy()#TODO, better way? - subpath_mobject.submobjects = [] - # subpath_mobject = self.__class__() + subpath_mobject = VMobject() subpath_mobject.is_subpath = True subpath_mobject.set_points(points) self.add(subpath_mobject)