# HG changeset patch # User Nicolas Saunier # Date 1260034288 18000 # Node ID 54d9cb0c902b488260e05bd600e9eb0377b94dbd # Parent 28e546861263fd94884c10ac51ec239f9a7a6b0e generalized intervals diff -r 28e546861263 -r 54d9cb0c902b python/moving.py --- a/python/moving.py Sat Dec 05 12:08:25 2009 -0500 +++ b/python/moving.py Sat Dec 05 12:31:28 2009 -0500 @@ -11,11 +11,16 @@ #class MovingObject: -class TimeInterval: - '''Temporal interval''' - def __init__(self, first=0, last=-1): - self.first=first - self.last=last +class Interval: + '''Generic Interval''' + def __init__(self, first=0, last=-1, revert = False): + 'Warning, do not revert if last>> TimeInterval().empty() + >>> Interval().empty() True - >>> TimeInterval(0,1).empty() + >>> Interval(0,1).empty() False ''' return self.first > self.last @@ -43,12 +48,14 @@ def length(self): '''Returns the length of the interval - >>> TimeInterval(0,1).length() - 2 - >>> TimeInterval(10,8).length() + >>> Interval(0,1).length() + 1 + >>> Interval(23.2,24.9).length() + 1.6999999999999993 + >>> Interval(10,8).length() 0 ''' - return max(0,self.last-self.first+1) + return max(0,self.last-self.first) def getList(self): return [self.first, self.last] @@ -68,6 +75,21 @@ '''Largest interval comprising self and interval2''' return TimeInterval(max(self.first, interval2.first), min(self.last, interval2.last)) +def TimeInterval(Interval): + '''Temporal interval''' + + def __init__(self, first=0, last=-1): + Interval.__init__(self, first, last, False) + + def length(self): + '''Returns the length of the interval + + >>> TimeInterval(0,1).length() + 2 + >>> TimeInterval(10,8).length() + 0 + ''' + return max(0,self.last-self.first+1) # class BoundingPolygon: # '''Class for a polygon bounding a set of points