Merge pull request #1667 from TurkeyBilly/master

Overridden add operations for mobjects
This commit is contained in:
Grant Sanderson 2021-11-01 13:17:16 -07:00 committed by GitHub
commit 5a0e5a16ea
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 0 deletions

View file

@ -82,6 +82,14 @@ class Mobject(object):
def __str__(self):
return self.__class__.__name__
def __add__(self, other : 'Mobject') -> 'Mobject':
assert(isinstance(other, Mobject))
return self.get_group_class()(self, other)
def __mul__(self, other : 'int') -> 'Mobject':
assert(isinstance(other, int))
return self.replicate(other)
def init_data(self):
self.data = {
"points": np.zeros((0, 3)),
@ -1609,6 +1617,10 @@ class Group(Mobject):
raise Exception("All submobjects must be of type Mobject")
Mobject.__init__(self, **kwargs)
self.add(*mobjects)
def __add__(self, other : 'Mobject' or 'Group'):
assert(isinstance(other, Mobject))
return self.add(other)
class Point(Mobject):

View file

@ -998,6 +998,10 @@ class VGroup(VMobject):
raise Exception("All submobjects must be of type VMobject")
super().__init__(**kwargs)
self.add(*vmobjects)
def __add__(self:'VGroup', other : 'VMobject' or 'VGroup'):
assert(isinstance(other, VMobject))
return self.add(other)
class VectorizedPoint(Point, VMobject):