comparison trafficintelligence/moving.py @ 1077:3939ae415be0

Merging
author Wendlasida
date Fri, 20 Jul 2018 14:03:34 -0400
parents 108c5dc4e34a cbc026dacf0b
children 845d694af7b8
comparison
equal deleted inserted replaced
1076:108c5dc4e34a 1077:3939ae415be0
31 else: 31 else:
32 self.first=first 32 self.first=first
33 self.last=last 33 self.last=last
34 34
35 def __str__(self): 35 def __str__(self):
36 return '[{0}, {1}]'.format(self.first, self.last) 36 return '{0}-{1}'.format(self.first, self.last)
37 37
38 def __repr__(self): 38 def __repr__(self):
39 return self.__str__() 39 return self.__str__()
40 40
41 def __eq__(self, other): 41 def __eq__(self, other):
66 66
67 def shift(self, offset): 67 def shift(self, offset):
68 self.first += offset 68 self.first += offset
69 self.last += offset 69 self.last += offset
70 70
71 @classmethod
72 def parse(cls, s):
73 if '-' in s:
74 tmp = s.split('-')
75 if len(tmp) == 2:
76 return cls(int(tmp[0]), int(tmp[1])) # TODO with floats?
77 print(s+' is not a valid representation of an interval')
78 return None
79
71 @classmethod 80 @classmethod
72 def union(cls, interval1, interval2): 81 def union(cls, interval1, interval2):
73 '''Smallest interval comprising self and interval2''' 82 '''Smallest interval comprising self and interval2'''
74 return cls(min(interval1.first, interval2.first), max(interval1.last, interval2.last)) 83 return cls(min(interval1.first, interval2.first), max(interval1.last, interval2.last))
75 84