Allow Mobject.remove to remove any family member, not just immediate submobjects

This commit is contained in:
Grant Sanderson 2023-01-27 15:15:16 -08:00
parent 1f6363821b
commit d5b1a1725d

View file

@ -408,14 +408,15 @@ class Mobject(object):
self.assemble_family()
return self
def remove(self, *mobjects: Mobject, reassemble: bool = True):
for mobject in mobjects:
if mobject in self.submobjects:
self.submobjects.remove(mobject)
if self in mobject.parents:
mobject.parents.remove(self)
def remove(self, *to_remove: Mobject, reassemble: bool = True):
for parent in self.get_family():
for child in to_remove:
if child in parent.submobjects:
parent.submobjects.remove(child)
if parent in child.parents:
child.parents.remove(parent)
if reassemble:
self.assemble_family()
parent.assemble_family()
return self
def add_to_back(self, *mobjects: Mobject):