+= operators

This commit is contained in:
Thomas Forgione 2021-01-05 14:52:09 +01:00
parent e865bf4c6d
commit 67ee904c9e
1 changed files with 24 additions and 0 deletions

24
obja.py
View File

@ -47,15 +47,39 @@ class Vector:
def __add__(self, other):
return Vector(self.x + other.x, self.y + other.y, self.z + other.z)
def __iadd__(self, other):
self.x += other.x
self.y += other.y
self.z += other.z
return self
def __sub__(self, other):
return Vector(self.x - other.x, self.y - other.y, self.z - other.z)
def __isub__(self, other):
self.x -= other.x
self.y -= other.y
self.z -= other.z
return self
def __mul__(self, other):
return Vector(self.x * other, self.y * other, self.z * other)
def __imul__(self, other):
self.x *= other
self.y *= other
self.z *= other
return self
def __truediv__(self, other):
return Vector(self.x / other, self.y / other, self.z / other)
def __itruediv__(self, other):
self.x /= other
self.y /= other
self.z /= other
return self
def __repr__(self):
return str(self)