comparison python/moving.py @ 918:3a06007a4bb7

modularized save trajectories, added slice to Trajectory, etc
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Wed, 05 Jul 2017 12:19:59 -0400
parents 8f60ecfc2f06
children 630934595871
comparison
equal deleted inserted replaced
917:89cc05867c4c 918:3a06007a4bb7
680 return self.__len__() == 0 680 return self.__len__() == 0
681 681
682 def __getitem__(self, i): 682 def __getitem__(self, i):
683 if isinstance(i, int): 683 if isinstance(i, int):
684 return Point(self.positions[0][i], self.positions[1][i]) 684 return Point(self.positions[0][i], self.positions[1][i])
685 elif isinstance(i, slice):
686 return Trajectory([self.positions[0][i],self.positions[1][i]])
685 else: 687 else:
686 raise TypeError, "Invalid argument type." 688 raise TypeError, "Invalid argument type."
687 #elif isinstance( key, slice ):
688 689
689 def __str__(self): 690 def __str__(self):
690 return ' '.join([self.__getitem__(i).__str__() for i in xrange(self.length())]) 691 return ' '.join([self.__getitem__(i).__str__() for i in xrange(self.length())])
691 692
692 def __repr__(self): 693 def __repr__(self):
1089 self.userType = userType 1090 self.userType = userType
1090 self.features = None 1091 self.features = None
1091 # compute bounding polygon from trajectory 1092 # compute bounding polygon from trajectory
1092 1093
1093 @staticmethod 1094 @staticmethod
1094 def generate(p, v, timeInterval): 1095 def generate(num, p, v, timeInterval):
1095 positions, velocities = Trajectory.generate(p, v, int(timeInterval.length())) 1096 positions, velocities = Trajectory.generate(p, v, int(timeInterval.length()))
1096 return MovingObject(timeInterval = timeInterval, positions = positions, velocities = velocities) 1097 return MovingObject(num = num, timeInterval = timeInterval, positions = positions, velocities = velocities)
1097 1098
1098 @staticmethod 1099 @staticmethod
1099 def concatenate(obj1, obj2, num = None): 1100 def concatenate(obj1, obj2, num = None):
1100 '''Concatenates two objects supposed to overlap temporally ''' 1101 '''Concatenates two objects supposed to overlap temporally '''
1101 commonTimeInterval = obj1.commonTimeInterval(obj2) 1102 commonTimeInterval = obj1.commonTimeInterval(obj2)