From 425a5de2bf9303228078c1d5790e86619678b788 Mon Sep 17 00:00:00 2001 From: Yerti <36551149+UZ9@users.noreply.github.com> Date: Tue, 26 Sep 2023 16:23:39 -0400 Subject: [PATCH] :bug: Fix TypeError resulting from lack of __rmul__ --- vpython/cyvector.pyx | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/vpython/cyvector.pyx b/vpython/cyvector.pyx index a3aeb1f..183848e 100644 --- a/vpython/cyvector.pyx +++ b/vpython/cyvector.pyx @@ -85,6 +85,12 @@ cdef class vector(object): return vector(self * other._x, self * other._y, self * other._z) return NotImplemented + def __rmul__(self, other): # required to prevent y * x error + if isinstance(other, (float, int)): + return vector(self._x * other, self._y * other, self._z * other) + + return NotImplemented + def __eq__(self,other): if type(self) is vector and type(other) is vector: return self.equals(other)