Mercurial Hosting > traffic-intelligence
comparison python/moving.py @ 107:916678481896
corrected bug for TimeInterval interation and added corresponding test
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Fri, 15 Jul 2011 02:32:34 -0400 |
parents | 9844c69d8fa2 |
children | 6efe470ea5e5 |
comparison
equal
deleted
inserted
replaced
106:ce4cb46b3603 | 107:916678481896 |
---|---|
7 from math import sqrt, hypot; | 7 from math import sqrt, hypot; |
8 | 8 |
9 #from shapely.geometry import Polygon | 9 #from shapely.geometry import Polygon |
10 | 10 |
11 __metaclass__ = type | 11 __metaclass__ = type |
12 | |
13 #class MovingObject: | |
14 | 12 |
15 class Interval: | 13 class Interval: |
16 '''Generic Interval''' | 14 '''Generic Interval''' |
17 def __init__(self, first=0, last=-1, revert = False): | 15 def __init__(self, first=0, last=-1, revert = False): |
18 'Warning, do not revert if last<first, it contradicts the definition of empty' | 16 'Warning, do not revert if last<first, it contradicts the definition of empty' |
68 def __getitem__(self, i): | 66 def __getitem__(self, i): |
69 if not self.empty(): | 67 if not self.empty(): |
70 return self.first+i | 68 return self.first+i |
71 | 69 |
72 def __iter__(self): | 70 def __iter__(self): |
73 self.iterInstantNum = 0 | 71 self.iterInstantNum = -1 |
74 return self | 72 return self |
75 | 73 |
76 def next(self): | 74 def next(self): |
77 if self.iterInstantNum >= self.length()-1: | 75 if self.iterInstantNum >= self.length()-1: |
78 raise StopIteration | 76 raise StopIteration |