diff python/moving.py @ 22:169cd4679366

made Trajectory iterable
author Nicolas Saunier <nico@confins.net>
date Fri, 04 Dec 2009 01:01:11 -0500
parents 3c4629550f5f
children 5f2921ad4f7e
line wrap: on
line diff
--- a/python/moving.py	Mon Nov 30 18:54:26 2009 -0500
+++ b/python/moving.py	Fri Dec 04 01:01:11 2009 -0500
@@ -87,14 +87,32 @@
 
 class Trajectory:
     '''Class for trajectories
-    i.e. a temporal sequence of positions'''
+    i.e. a temporal sequence of positions
+
+    the class is iterable.'''
 
     def __init__(self, positions = None):
+#        self.iterInstantNum = 0
         self.positions = positions
 
     def __str__(self):
         return ' '.join(map(utils.printPoint, self.positions[0], self.positions[1]))
 
+    def __iter__(self):
+        self.iterInstantNum = 0
+        return self
+
+    def next(self):
+        if self.iterInstantNum >= self.length():
+            self.iterInstantNum = 0
+            raise StopIteration
+        else:
+            self.iterInstantNum += 1
+            return self.getPosition(self.iterInstantNum-1)
+
+    def getPosition(self, i):
+        return [self.positions[0][i], self.positions[1][i]]
+
     def addPosition(self, point):
         if not self.positions:
             self.positions = [[point[0]],[point[1]]]
@@ -159,6 +177,11 @@
     
     def draw(self):
         self.positions.draw()
+
+    def getInstantPassingLane(self, p1, p2):
+        '''Returns the instant(s) the object passes from one side of the segment to the other
+        None if does not'''
+        # parallel
     
     # def computeVelocities(self):