Mercurial > hg > nsaunier > traffic-intelligence
comparison python/moving.py @ 104:13187af8622d
finally added the representation of intervals
| author | Nicolas Saunier <nico@confins.net> |
|---|---|
| date | Thu, 14 Jul 2011 17:15:09 -0400 |
| parents | b85912ab4064 |
| children | 9844c69d8fa2 |
comparison
equal
deleted
inserted
replaced
| 103:1621b46a1523 | 104:13187af8622d |
|---|---|
| 22 else: | 22 else: |
| 23 self.first=first | 23 self.first=first |
| 24 self.last=last | 24 self.last=last |
| 25 | 25 |
| 26 def __str__(self): | 26 def __str__(self): |
| 27 return '%d %d'%(self.first, self.last) | 27 return '[{0}, {1}]'.format(self.first, self.last) |
| 28 | |
| 29 def __repr__(self): | |
| 30 return self.__str__() | |
| 28 | 31 |
| 29 def empty(self): | 32 def empty(self): |
| 30 return self.first > self.last | 33 return self.first > self.last |
| 31 | 34 |
| 32 def length(self): | 35 def length(self): |
| 49 def union(self, interval2): | 52 def union(self, interval2): |
| 50 '''Largest interval comprising self and interval2''' | 53 '''Largest interval comprising self and interval2''' |
| 51 return TimeInterval(min(self.first, interval2.first), max(self.last, interval2.last)) | 54 return TimeInterval(min(self.first, interval2.first), max(self.last, interval2.last)) |
| 52 | 55 |
| 53 def intersection(self, interval2): | 56 def intersection(self, interval2): |
| 54 '''Largest interval comprising self and interval2''' | 57 '''Largest interval comprised in both self and interval2''' |
| 55 return TimeInterval(max(self.first, interval2.first), min(self.last, interval2.last)) | 58 return TimeInterval(max(self.first, interval2.first), min(self.last, interval2.last)) |
| 56 | 59 |
| 57 | 60 |
| 58 class TimeInterval(Interval): | 61 class TimeInterval(Interval): |
| 59 '''Temporal interval based on frame numbers (hence the modified length method) | 62 '''Temporal interval based on frame numbers (hence the modified length method) |
