Mercurial > hg > nsaunier > traffic-intelligence
comparison 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 |
comparison
equal
deleted
inserted
replaced
| 21:3c4629550f5f | 22:169cd4679366 |
|---|---|
| 85 def getLastInstant(self): | 85 def getLastInstant(self): |
| 86 return self.timeInterval.first() | 86 return self.timeInterval.first() |
| 87 | 87 |
| 88 class Trajectory: | 88 class Trajectory: |
| 89 '''Class for trajectories | 89 '''Class for trajectories |
| 90 i.e. a temporal sequence of positions''' | 90 i.e. a temporal sequence of positions |
| 91 | |
| 92 the class is iterable.''' | |
| 91 | 93 |
| 92 def __init__(self, positions = None): | 94 def __init__(self, positions = None): |
| 95 # self.iterInstantNum = 0 | |
| 93 self.positions = positions | 96 self.positions = positions |
| 94 | 97 |
| 95 def __str__(self): | 98 def __str__(self): |
| 96 return ' '.join(map(utils.printPoint, self.positions[0], self.positions[1])) | 99 return ' '.join(map(utils.printPoint, self.positions[0], self.positions[1])) |
| 100 | |
| 101 def __iter__(self): | |
| 102 self.iterInstantNum = 0 | |
| 103 return self | |
| 104 | |
| 105 def next(self): | |
| 106 if self.iterInstantNum >= self.length(): | |
| 107 self.iterInstantNum = 0 | |
| 108 raise StopIteration | |
| 109 else: | |
| 110 self.iterInstantNum += 1 | |
| 111 return self.getPosition(self.iterInstantNum-1) | |
| 112 | |
| 113 def getPosition(self, i): | |
| 114 return [self.positions[0][i], self.positions[1][i]] | |
| 97 | 115 |
| 98 def addPosition(self, point): | 116 def addPosition(self, point): |
| 99 if not self.positions: | 117 if not self.positions: |
| 100 self.positions = [[point[0]],[point[1]]] | 118 self.positions = [[point[0]],[point[1]]] |
| 101 else: | 119 else: |
| 157 def getYCoordinates(self): | 175 def getYCoordinates(self): |
| 158 return self.positions.getYCoordinates() | 176 return self.positions.getYCoordinates() |
| 159 | 177 |
| 160 def draw(self): | 178 def draw(self): |
| 161 self.positions.draw() | 179 self.positions.draw() |
| 180 | |
| 181 def getInstantPassingLane(self, p1, p2): | |
| 182 '''Returns the instant(s) the object passes from one side of the segment to the other | |
| 183 None if does not''' | |
| 184 # parallel | |
| 162 | 185 |
| 163 # def computeVelocities(self): | 186 # def computeVelocities(self): |
| 164 | 187 |
| 165 # need for a class representing the indicators, their units, how to print them in graphs... | 188 # need for a class representing the indicators, their units, how to print them in graphs... |
| 166 class TemporalIndicator: | 189 class TemporalIndicator: |
