Skip to content
Open
Changes from 4 commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
736f6b4
Optimized AnimationGroup computation of start-end times with lag ratio
chopan050 Dec 20, 2023
488a4e1
Added extra comment for init_run_time
chopan050 Dec 20, 2023
c22a1fc
Added full path to imports in composition.py
chopan050 Dec 20, 2023
7a40ac5
Optimized AnimationGroup.interpolate
chopan050 Dec 20, 2023
4e0321e
Fixed final bugs
chopan050 Dec 20, 2023
aa161d8
Removed accidental print
chopan050 Dec 20, 2023
3e1bc50
Final fix to AnimationGroup.interpolate
chopan050 Dec 20, 2023
57fc724
Fixed animations being skipped unintentionally
chopan050 Dec 21, 2023
6a463b6
Merge branch 'main' into anim_composition_optimization
chopan050 Apr 25, 2024
0a2e3a0
Merged
chopan050 Apr 28, 2024
a388df7
Port ManimGL's family handling
chopan050 May 2, 2024
fc04be4
Make Mobject.submobjects a property
chopan050 May 2, 2024
42420de
Move assignation of parents to the middle of the for loop in __deepco…
chopan050 May 2, 2024
e601d66
Merge branch 'ManimCommunity:main' into family_issues
chopan050 May 2, 2024
c5598a5
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] May 2, 2024
ccfffbf
Implement requested changes and an _assert_valid_submobjects() method
chopan050 May 11, 2024
17f30b7
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] May 11, 2024
cdf4af8
Merge branch 'main' into family_issues
chopan050 May 11, 2024
df2a3c8
Added docstrings to get_family and _assert_valid_submobjects
chopan050 May 11, 2024
ac296f8
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] May 11, 2024
2f1c448
Merge branch 'main' of https://github.com/ManimCommunity/manim into f…
chopan050 May 17, 2024
17d1681
Add self as parents in self.submobjects.setter
chopan050 May 20, 2024
ee6fc61
Merge branch 'main' of https://github.com/ManimCommunity/manim into f…
chopan050 May 20, 2024
9f4d7d1
Merge branch 'main' of https://github.com/ManimCommunity/manim into f…
chopan050 May 21, 2024
b4f7f3a
Merge branch 'main' of https://github.com/ManimCommunity/manim into f…
chopan050 May 30, 2024
ac76433
Remove duplicated assertion in Mobject.add()
chopan050 May 30, 2024
2ababf4
Skip _family attribute when JSON encoding with manim.utils.hashing._C…
chopan050 May 30, 2024
9f30e33
Remove unused import of manim.utils.iterables.tuplify
chopan050 May 30, 2024
01c3e7d
Merge branch 'main' of https://github.com/ManimCommunity/manim into f…
chopan050 Jun 11, 2024
71a4bea
Make parents a property and add Mobject._add_as_parent_of_submobs() m…
chopan050 Jun 11, 2024
a46c6ed
parents -> _parents
chopan050 Jun 11, 2024
232b2f6
Add family property
chopan050 Jun 11, 2024
f8f9c01
Merge branch 'main' of https://github.com/ManimCommunity/manim into f…
chopan050 Jun 16, 2024
497233a
Merge branch 'main' into family_issues
chopan050 Jun 21, 2024
c569304
Apply requested changes
chopan050 Jul 15, 2024
29cc725
Merge branch 'main' of https://github.com/ManimCommunity/manim into f…
chopan050 Jul 15, 2024
143a0a9
Explicit import of constants
chopan050 Jul 15, 2024
4101669
Changed a return None to return self
chopan050 Jul 15, 2024
2d4fd9a
Remove unused variable k in list comprehension and use underscore
chopan050 Jul 15, 2024
78a294a
Change mentions of submobjects to _submobjects
chopan050 Jul 15, 2024
836958e
Changed a self to submob in add_n_more_submobjects
chopan050 Jul 15, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 36 additions & 30 deletions manim/mobject/mobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,10 @@ def __init__(
self.target = target
self.z_index = z_index
self.point_hash = None
# NOTE: the parents, _submobjects and _family attributes MUST BE
# NOTE: the _parents, _submobjects and _family attributes MUST BE
# IN THIS ORDER! Otherwise, Mobject.__deepcopy__() will break or
# generate a Mobject with a different hash!
self.parents: list[Mobject] = []
self._parents: list[Mobject] = []
self._submobjects: list[Mobject] = []
self._family: list[Mobject] | None = None
self.updaters: list[Updater] = []
Expand Down Expand Up @@ -193,11 +193,17 @@ def submobjects(self) -> list[Mobject]:
def submobjects(self, new_submobjects: list[Mobject]) -> None:
self._assert_valid_submobjects(new_submobjects)
self._submobjects = new_submobjects
for submob in new_submobjects:
if self not in submob.parents:
submob.parents.append(self)
self._add_as_parent_of_submobs(new_submobjects)
self.note_changed_family()

@property
def parents(self) -> list[Mobject]:
return self._parents

@property
def family(self) -> list[Mobject]:
return self.get_family()

@classmethod
def animation_override_for(
cls,
Expand Down Expand Up @@ -423,13 +429,12 @@ def __deepcopy__(self, clone_from_id) -> Self:
# This must be set manually because result has no attributes,
# and specifically INSIDE the loop to preserve attribute order,
# or test_hash_consistency() will fail!
if k == "parents":
result.parents = []
if k == "_parents":
result._parents = []
continue
if k == "_submobjects":
# Call the submobjects property which calculates parents
result._submobjects = []
result.submobjects = copy.deepcopy(v, clone_from_id)
result._submobjects = copy.deepcopy(v, clone_from_id)
result._add_as_parent_of_submobs(result._submobjects)
elif k == "_family":
result._family = None
else:
Expand Down Expand Up @@ -458,6 +463,12 @@ def generate_points(self) -> None:
subclasses.
"""

def _add_as_parent_of_submobs(self, mobjects: Iterable[Mobject]) -> Self:
for mobject in mobjects:
if self not in mobject._parents:
mobject._parents.append(self)
return self

def add(self, *mobjects: Mobject) -> Self:
"""Add mobjects as submobjects.

Expand Down Expand Up @@ -543,10 +554,8 @@ def add(self, *mobjects: Mobject) -> Self:
"this is not possible. Repetitions are ignored.",
)

self.submobjects = list_update(self.submobjects, unique_mobjects)
for mobject in unique_mobjects:
if self not in mobject.parents:
mobject.parents.append(self)
self._submobjects = list_update(self._submobjects, unique_mobjects)
self._add_as_parent_of_submobs(mobjects)
self.note_changed_family()
return self

Expand All @@ -567,9 +576,8 @@ def insert(self, index: int, mobject: Mobject) -> None:
"""
self._assert_valid_submobjects([mobject])
# TODO: should verify that subsequent submobjects are not repeated
self.submobjects.insert(index, mobject)
if self not in mobject.parents:
mobject.parents.append(self)
self._submobjects.insert(index, mobject)
self._add_as_parent_of_submobs([mobject])
self.note_changed_family()
# TODO: should return Self instead of None?

Expand Down Expand Up @@ -626,10 +634,8 @@ def add_to_back(self, *mobjects: Mobject) -> Self:
self._assert_valid_submobjects(mobjects)
self.remove(*mobjects)
# dict.fromkeys() removes duplicates while maintaining order
self.submobjects = list(dict.fromkeys(mobjects)) + self.submobjects
for mobject in mobjects:
if self not in mobject.parents:
mobject.parents.append(self)
self._submobjects = list(dict.fromkeys(mobjects)) + self._submobjects
self._add_as_parent_of_submobs(mobjects)
self.note_changed_family()
return self

Expand All @@ -656,10 +662,10 @@ def remove(self, *mobjects: Mobject) -> Self:

"""
for mobject in mobjects:
if mobject in self.submobjects:
self.submobjects.remove(mobject)
if self in mobject.parents:
mobject.parents.remove(self)
if mobject in self._submobjects:
self._submobjects.remove(mobject)
if self in mobject._parents:
mobject._parents.remove(self)
self.note_changed_family()
return self

Expand Down Expand Up @@ -2394,7 +2400,7 @@ def note_changed_family(self, only_changed_order=False) -> Self:
# if not only_changed_order:
# self.refresh_has_updater_status()
# self.refresh_bounding_box()
for parent in self.parents:
for parent in self._parents:
parent.note_changed_family(only_changed_order)
return self

Expand Down Expand Up @@ -2732,7 +2738,7 @@ def sort(
def submob_func(m: Mobject):
return point_to_num_func(m.get_center())

self.submobjects.sort(key=submob_func)
self._submobjects.sort(key=submob_func)
self.note_changed_family(only_changed_order=True)
return self

Expand All @@ -2741,7 +2747,7 @@ def shuffle(self, recursive: bool = False) -> None:
if recursive:
for submob in self.submobjects:
submob.shuffle(recursive=True)
random.shuffle(self.submobjects)
random.shuffle(self._submobjects)
self.note_changed_family(only_changed_order=True)
# TODO: should return Self instead of None?

Expand Down Expand Up @@ -2769,7 +2775,7 @@ def construct(self):
if recursive:
for submob in self.submobjects:
submob.invert(recursive=True)
self.submobjects.reverse()
self._submobjects.reverse()
self.note_changed_family(only_changed_order=True)
# TODO: should return Self instead of None?

Expand Down Expand Up @@ -2888,7 +2894,7 @@ def null_point_align(self, mobject: Mobject):

def push_self_into_submobjects(self) -> Self:
copy = self.copy()
copy.submobjects = []
copy._submobjects = []
self.reset_points()
self.add(copy)
return self
Expand Down