comparison python/moving.py @ 978:184f1dd307f9

corrected print and exception statements for Python 3
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Thu, 08 Feb 2018 05:53:50 -0500
parents 4f32d82ca390
children 51d8406b2489
comparison
equal deleted inserted replaced
977:9c27a0315c4d 978:184f1dd307f9
112 def __getitem__(self, i): 112 def __getitem__(self, i):
113 if not self.empty(): 113 if not self.empty():
114 if isinstance(i, int): 114 if isinstance(i, int):
115 return self.first+i 115 return self.first+i
116 else: 116 else:
117 raise TypeError, "Invalid argument type." 117 raise TypeError("Invalid argument type.")
118 #elif isinstance( key, slice ): 118 #elif isinstance( key, slice ):
119 119
120 def __iter__(self): 120 def __iter__(self):
121 self.iterInstantNum = -1 121 self.iterInstantNum = -1
122 return self 122 return self
695 if isinstance(i, int): 695 if isinstance(i, int):
696 return Point(self.positions[0][i], self.positions[1][i]) 696 return Point(self.positions[0][i], self.positions[1][i])
697 elif isinstance(i, slice): 697 elif isinstance(i, slice):
698 return Trajectory([self.positions[0][i],self.positions[1][i]]) 698 return Trajectory([self.positions[0][i],self.positions[1][i]])
699 else: 699 else:
700 raise TypeError, "Invalid argument type." 700 raise TypeError("Invalid argument type.")
701 701
702 def __str__(self): 702 def __str__(self):
703 return ' '.join([self.__getitem__(i).__str__() for i in xrange(self.length())]) 703 return ' '.join([self.__getitem__(i).__str__() for i in xrange(self.length())])
704 704
705 def __repr__(self): 705 def __repr__(self):
790 return Interval(min(self.getYCoordinates()), max(self.getYCoordinates())) 790 return Interval(min(self.getYCoordinates()), max(self.getYCoordinates()))
791 791
792 def add(self, traj2): 792 def add(self, traj2):
793 '''Returns a new trajectory of the same length''' 793 '''Returns a new trajectory of the same length'''
794 if self.length() != traj2.length(): 794 if self.length() != traj2.length():
795 print 'Trajectories of different lengths' 795 print('Trajectories of different lengths')
796 return None 796 return None
797 else: 797 else:
798 return Trajectory([[a+b for a,b in zip(self.getXCoordinates(),traj2.getXCoordinates())], 798 return Trajectory([[a+b for a,b in zip(self.getXCoordinates(),traj2.getXCoordinates())],
799 [a+b for a,b in zip(self.getYCoordinates(),traj2.getYCoordinates())]]) 799 [a+b for a,b in zip(self.getYCoordinates(),traj2.getYCoordinates())]])
800 800
801 def subtract(self, traj2): 801 def subtract(self, traj2):
802 '''Returns a new trajectory of the same length''' 802 '''Returns a new trajectory of the same length'''
803 if self.length() != traj2.length(): 803 if self.length() != traj2.length():
804 print 'Trajectories of different lengths' 804 print('Trajectories of different lengths')
805 return None 805 return None
806 else: 806 else:
807 return Trajectory([[a-b for a,b in zip(self.getXCoordinates(),traj2.getXCoordinates())], 807 return Trajectory([[a-b for a,b in zip(self.getXCoordinates(),traj2.getXCoordinates())],
808 [a-b for a,b in zip(self.getYCoordinates(),traj2.getYCoordinates())]]) 808 [a-b for a,b in zip(self.getYCoordinates(),traj2.getYCoordinates())]])
809 809
1046 1046
1047 def __getitem__(self,i): 1047 def __getitem__(self,i):
1048 if isinstance(i, int): 1048 if isinstance(i, int):
1049 return [self.positions[0][i], self.positions[1][i], self.lanes[i]] 1049 return [self.positions[0][i], self.positions[1][i], self.lanes[i]]
1050 else: 1050 else:
1051 raise TypeError, "Invalid argument type." 1051 raise TypeError("Invalid argument type.")
1052 #elif isinstance( key, slice ): 1052 #elif isinstance( key, slice ):
1053 1053
1054 def getSCoordinates(self): 1054 def getSCoordinates(self):
1055 return self.getXCoordinates() 1055 return self.getXCoordinates()
1056 1056
1198 obj = MovingObject(self.num, intersection, self.positions.getTrajectoryInInterval(trajectoryInterval), self.geometry, self.userType) 1198 obj = MovingObject(self.num, intersection, self.positions.getTrajectoryInInterval(trajectoryInterval), self.geometry, self.userType)
1199 if self.velocities: 1199 if self.velocities:
1200 obj.velocities = self.velocities.getTrajectoryInInterval(trajectoryInterval) 1200 obj.velocities = self.velocities.getTrajectoryInInterval(trajectoryInterval)
1201 return obj 1201 return obj
1202 else: 1202 else:
1203 print 'The object does not exist at '+str(inter) 1203 print('The object does not exist at {}'.format(inter))
1204 return None 1204 return None
1205 1205
1206 def getObjectsInMask(self, mask, homography = None, minLength = 1): 1206 def getObjectsInMask(self, mask, homography = None, minLength = 1):
1207 '''Returns new objects made of the positions in the mask 1207 '''Returns new objects made of the positions in the mask
1208 mask is in the destination of the homography space''' 1208 mask is in the destination of the homography space'''
1872 for a in previousMatches: 1872 for a in previousMatches:
1873 if a not in matches and previousMatches[a] in matches.values(): 1873 if a not in matches and previousMatches[a] in matches.values():
1874 mismatches.append(previousMatches[a]) 1874 mismatches.append(previousMatches[a])
1875 if debug: 1875 if debug:
1876 for mm in set(mismatches): 1876 for mm in set(mismatches):
1877 print type(mm), mm.getNum() 1877 print('{} {}'.format(type(mm), mm.getNum()))
1878 # some object mismatches may appear twice 1878 # some object mismatches may appear twice
1879 mme += len(set(mismatches)) 1879 mme += len(set(mismatches))
1880 1880
1881 if ct > 0: 1881 if ct > 0:
1882 motp = dist/ct 1882 motp = dist/ct