From c4382f3eb26a099a84c96d49a25f00724dce74f8 Mon Sep 17 00:00:00 2001 From: Eric Teunis de Boone Date: Thu, 10 Mar 2022 17:01:54 +0100 Subject: [PATCH] Allow Locations to be multiplied --- simulations/lib/location.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/simulations/lib/location.py b/simulations/lib/location.py index 8b0bf45..c088f87 100644 --- a/simulations/lib/location.py +++ b/simulations/lib/location.py @@ -28,6 +28,7 @@ class Location: def __setitem__(self, key, val): self.x[key] = val + # math def __add__(self, other): if isinstance(other, Location): other = other.x @@ -40,12 +41,20 @@ class Location: return self.__class__(self.x - other) + def __mul__(self, other): + return self.__class__(self.x * other) + def __eq__(self, other): if isinstance(other, Location): other = other.x return np.all(self.x == other) + # math alias functions + __radd__ = __add__ + __rsub__ = __sub__ + __rmul__ = __mul__ + class Receiver(Location): """ A location able to trace a signal over time.