diff python/moving.py @ 776:84420159c5f4 dev

added __eq__ functions for Point and Trajectory
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Fri, 05 Feb 2016 17:17:12 -0500
parents bd13937818a4
children 1b22d81ef5ff
line wrap: on
line diff
--- a/python/moving.py	Fri Feb 05 12:28:18 2016 -0500
+++ b/python/moving.py	Fri Feb 05 17:17:12 2016 -0500
@@ -35,6 +35,9 @@
     def __repr__(self):
         return self.__str__()
 
+    def __eq__(self, other):
+        return ((self.first == other.first) and (self.last == other.last)) or ((self.first == other.last) and (self.last == other.first))
+
     def empty(self):
         return self.first > self.last
 
@@ -182,6 +185,9 @@
     def __repr__(self):
         return self.__str__()
 
+    def __eq__(self, other):
+        return (self.x == other.x) and (self.y == other.y)
+
     def __add__(self, other):
         return Point(self.x+other.x, self.y+other.y)
 
@@ -660,7 +666,6 @@
     def __repr__(self):
         return self.__str__()
 
-
     def __iter__(self):
         self.iterInstantNum = 0
         return self
@@ -672,6 +677,15 @@
             self.iterInstantNum += 1
             return self[self.iterInstantNum-1]
 
+    def __eq__(self, other):
+        if self.length() == other.length():
+            result = True
+            for p, po in zip(self, other):
+                result = result and (p == po)
+            return result
+        else:
+            return False
+
     def setPositionXY(self, i, x, y):
         if i < self.__len__():
             self.positions[0][i] = x