From 67ee904c9e384bbbde7ed364f65c2de498b78be2 Mon Sep 17 00:00:00 2001 From: Thomas Forgione Date: Tue, 5 Jan 2021 14:52:09 +0100 Subject: [PATCH] += operators --- obja.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/obja.py b/obja.py index 9af4985..9722e3f 100755 --- a/obja.py +++ b/obja.py @@ -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)