mirror of
https://github.com/3b1b/manim.git
synced 2025-04-13 09:47:07 +00:00
Have Transform only copy target_mobject if it must
This commit is contained in:
parent
0e60b124eb
commit
c4d698a169
4 changed files with 22 additions and 8 deletions
|
@ -36,7 +36,7 @@ class Fade(Transform):
|
|||
|
||||
class FadeIn(Fade):
|
||||
def create_target(self) -> Mobject:
|
||||
return self.mobject
|
||||
return self.mobject.copy()
|
||||
|
||||
def create_starting_mobject(self) -> Mobject:
|
||||
start = super().create_starting_mobject()
|
||||
|
|
|
@ -26,7 +26,7 @@ class GrowFromPoint(Transform):
|
|||
super().__init__(mobject, **kwargs)
|
||||
|
||||
def create_target(self) -> Mobject:
|
||||
return self.mobject
|
||||
return self.mobject.copy()
|
||||
|
||||
def create_starting_mobject(self) -> Mobject:
|
||||
start = super().create_starting_mobject()
|
||||
|
|
|
@ -54,12 +54,16 @@ class Transform(Animation):
|
|||
def begin(self) -> None:
|
||||
self.target_mobject = self.create_target()
|
||||
self.check_target_mobject_validity()
|
||||
# Use a copy of target_mobject for the align_data_and_family
|
||||
# call so that the actual target_mobject stays
|
||||
# preserved, since calling allign_data will potentially
|
||||
# change the structure of both arguments
|
||||
self.target_copy = self.target_mobject.copy()
|
||||
self.mobject.align_data_and_family(self.target_copy)
|
||||
|
||||
if self.mobject.is_aligned_with(self.target_mobject):
|
||||
self.target_copy = self.target_mobject
|
||||
else:
|
||||
# Use a copy of target_mobject for the align_data_and_family
|
||||
# call so that the actual target_mobject stays
|
||||
# preserved, since calling align_data will potentially
|
||||
# change the structure of both arguments
|
||||
self.target_copy = self.target_mobject.copy()
|
||||
self.mobject.align_data_and_family(self.target_copy)
|
||||
super().begin()
|
||||
if not self.mobject.has_updaters:
|
||||
self.mobject.lock_matching_data(
|
||||
|
|
|
@ -1672,6 +1672,16 @@ class Mobject(object):
|
|||
|
||||
# Alignment
|
||||
|
||||
def is_aligned_with(self, mobject: Mobject) -> bool:
|
||||
if len(self.data) != len(mobject.data):
|
||||
return False
|
||||
if len(self.submobjects) != len(mobject.submobjects):
|
||||
return False
|
||||
return all(
|
||||
sm1.is_aligned_with(sm2)
|
||||
for sm1, sm2 in zip(self.submobjects, mobject.submobjects)
|
||||
)
|
||||
|
||||
def align_data_and_family(self, mobject: Mobject) -> Self:
|
||||
self.align_family(mobject)
|
||||
self.align_data(mobject)
|
||||
|
|
Loading…
Add table
Reference in a new issue