2022-02-12 23:47:23 +08:00
|
|
|
from __future__ import annotations
|
|
|
|
|
2022-02-14 21:34:56 +08:00
|
|
|
from typing import TYPE_CHECKING
|
2022-02-16 21:08:25 +08:00
|
|
|
|
2022-02-14 21:34:56 +08:00
|
|
|
if TYPE_CHECKING:
|
2022-12-26 07:46:40 -07:00
|
|
|
from typing import Iterable, List, Set, Tuple
|
2022-04-12 19:19:59 +08:00
|
|
|
|
2022-02-14 21:34:56 +08:00
|
|
|
from manimlib.mobject.mobject import Mobject
|
2020-01-15 18:30:58 -08:00
|
|
|
|
|
|
|
|
2022-02-12 23:47:23 +08:00
|
|
|
def extract_mobject_family_members(
|
|
|
|
mobject_list: Iterable[Mobject],
|
2022-04-20 21:51:56 -07:00
|
|
|
exclude_pointless: bool = False
|
2022-02-12 23:47:23 +08:00
|
|
|
) -> list[Mobject]:
|
2022-04-20 21:51:56 -07:00
|
|
|
return [
|
|
|
|
sm
|
2020-02-14 15:29:35 -08:00
|
|
|
for mob in mobject_list
|
2022-04-20 21:51:56 -07:00
|
|
|
for sm in mob.get_family()
|
|
|
|
if (not exclude_pointless) or sm.has_points()
|
|
|
|
]
|
2022-12-26 07:46:40 -07:00
|
|
|
|
|
|
|
|
|
|
|
def recursive_mobject_remove(mobjects: List[Mobject], to_remove: Set[Mobject]) -> Tuple[List[Mobject], bool]:
|
|
|
|
"""
|
|
|
|
Takes in a list of mobjects, together with a set of mobjects to remove.
|
|
|
|
|
|
|
|
The first component of what's removed is a new list such that any mobject
|
|
|
|
with one of the elements from `to_remove` in its family is no longer in
|
|
|
|
the list, and in its place are its family members which aren't in `to_remove`
|
|
|
|
|
|
|
|
The second component is a boolean value indicating whether any removals were made
|
|
|
|
"""
|
|
|
|
result = []
|
|
|
|
found_in_list = False
|
|
|
|
for mob in mobjects:
|
|
|
|
if mob in to_remove:
|
|
|
|
found_in_list = True
|
|
|
|
continue
|
|
|
|
# Recursive call
|
|
|
|
sub_list, found_in_submobjects = recursive_mobject_remove(
|
|
|
|
mob.submobjects, to_remove
|
|
|
|
)
|
|
|
|
if found_in_submobjects:
|
|
|
|
result.extend(sub_list)
|
|
|
|
found_in_list = True
|
|
|
|
else:
|
|
|
|
result.append(mob)
|
|
|
|
return result, found_in_list
|