mirror of
https://github.com/3b1b/manim.git
synced 2025-07-31 22:13:30 +08:00
Fixed Mobject.copy to be more efficient and fault taulerent
This commit is contained in:
@ -100,7 +100,7 @@ class Swap(CyclicReplace):
|
|||||||
|
|
||||||
class GrowFromPoint(Transform):
|
class GrowFromPoint(Transform):
|
||||||
def __init__(self, mobject, point, **kwargs):
|
def __init__(self, mobject, point, **kwargs):
|
||||||
target = mobject.deepcopy()
|
target = mobject.copy()
|
||||||
point_mob = Point(point)
|
point_mob = Point(point)
|
||||||
mobject.replace(point_mob)
|
mobject.replace(point_mob)
|
||||||
mobject.highlight(point_mob.get_color())
|
mobject.highlight(point_mob.get_color())
|
||||||
@ -143,7 +143,7 @@ class ApplyMethod(Transform):
|
|||||||
)
|
)
|
||||||
assert(isinstance(method.im_self, Mobject))
|
assert(isinstance(method.im_self, Mobject))
|
||||||
method_kwargs = kwargs.get("method_kwargs", {})
|
method_kwargs = kwargs.get("method_kwargs", {})
|
||||||
target = method.im_self.deepcopy()
|
target = method.im_self.copy()
|
||||||
method.im_func(target, *args, **method_kwargs)
|
method.im_func(target, *args, **method_kwargs)
|
||||||
Transform.__init__(self, method.im_self, target, **kwargs)
|
Transform.__init__(self, method.im_self, target, **kwargs)
|
||||||
|
|
||||||
@ -165,7 +165,7 @@ class FadeOut(Transform):
|
|||||||
|
|
||||||
class FadeIn(Transform):
|
class FadeIn(Transform):
|
||||||
def __init__(self, mobject, **kwargs):
|
def __init__(self, mobject, **kwargs):
|
||||||
target = mobject.deepcopy()
|
target = mobject.copy()
|
||||||
Transform.__init__(self, mobject, target, **kwargs)
|
Transform.__init__(self, mobject, target, **kwargs)
|
||||||
self.starting_mobject.fade(1)
|
self.starting_mobject.fade(1)
|
||||||
if isinstance(self.starting_mobject, VMobject):
|
if isinstance(self.starting_mobject, VMobject):
|
||||||
@ -232,7 +232,6 @@ class Rotate(ApplyMethod):
|
|||||||
)
|
)
|
||||||
Transform.__init__(self, mobject, target, **kwargs)
|
Transform.__init__(self, mobject, target, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
class ApplyPointwiseFunction(ApplyMethod):
|
class ApplyPointwiseFunction(ApplyMethod):
|
||||||
CONFIG = {
|
CONFIG = {
|
||||||
"run_time" : DEFAULT_POINTWISE_FUNCTION_RUN_TIME
|
"run_time" : DEFAULT_POINTWISE_FUNCTION_RUN_TIME
|
||||||
@ -258,7 +257,7 @@ class ApplyFunction(Transform):
|
|||||||
Transform.__init__(
|
Transform.__init__(
|
||||||
self,
|
self,
|
||||||
mobject,
|
mobject,
|
||||||
function(mobject.deepcopy()),
|
function(mobject.copy()),
|
||||||
**kwargs
|
**kwargs
|
||||||
)
|
)
|
||||||
self.name = "ApplyFunctionTo"+str(mobject)
|
self.name = "ApplyFunctionTo"+str(mobject)
|
||||||
|
@ -102,13 +102,17 @@ class Mobject(object):
|
|||||||
def copy(self):
|
def copy(self):
|
||||||
#TODO, either justify reason for shallow copy, or
|
#TODO, either justify reason for shallow copy, or
|
||||||
#remove this redundancy everywhere
|
#remove this redundancy everywhere
|
||||||
return self.deepcopy()
|
# return self.deepcopy()
|
||||||
# copy_mobject = copy.copy(self)
|
copy_mobject = copy.copy(self)
|
||||||
# copy_mobject.points = np.array(self.points)
|
copy_mobject.points = np.array(self.points)
|
||||||
# copy_mobject.submobjects = [
|
copy_mobject.submobjects = [
|
||||||
# submob.copy() for submob in self.submobjects
|
submob.copy() for submob in self.submobjects
|
||||||
# ]
|
]
|
||||||
# return copy_mobject
|
family = self.submobject_family()
|
||||||
|
for attr, value in self.__dict__.items():
|
||||||
|
if isinstance(value, Mobject) and value in family and value is not self:
|
||||||
|
setattr(copy_mobject, attr, value.copy())
|
||||||
|
return copy_mobject
|
||||||
|
|
||||||
def deepcopy(self):
|
def deepcopy(self):
|
||||||
return copy.deepcopy(self)
|
return copy.deepcopy(self)
|
||||||
@ -443,7 +447,7 @@ class Mobject(object):
|
|||||||
if hasattr(self, "saved_state"):
|
if hasattr(self, "saved_state"):
|
||||||
#Prevent exponential growth of data
|
#Prevent exponential growth of data
|
||||||
self.saved_state = None
|
self.saved_state = None
|
||||||
self.saved_state = self.deepcopy()
|
self.saved_state = self.copy()
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def restore(self):
|
def restore(self):
|
||||||
|
Reference in New Issue
Block a user