comparison python/moving.py @ 526:21bdeb29f855

corrected bug in initialization of lists and loading trajectories from vissim files
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Fri, 20 Jun 2014 17:45:32 -0400
parents 1dced8932b08
children 37830a831818
comparison
equal deleted inserted replaced
525:7124c7d2a663 526:21bdeb29f855
98 def fromInterval(inter): 98 def fromInterval(inter):
99 return TimeInterval(inter.first, inter.last) 99 return TimeInterval(inter.first, inter.last)
100 100
101 def __getitem__(self, i): 101 def __getitem__(self, i):
102 if not self.empty(): 102 if not self.empty():
103 return self.first+i 103 if isinstance(i, int):
104 return self.first+i
105 else:
106 raise TypeError, "Invalid argument type."
107 #elif isinstance( key, slice ):
104 108
105 def __iter__(self): 109 def __iter__(self):
106 self.iterInstantNum = -1 110 self.iterInstantNum = -1
107 return self 111 return self
108 112
432 return len(self.positions[0]) 436 return len(self.positions[0])
433 437
434 def length(self): 438 def length(self):
435 return self.__len__() 439 return self.__len__()
436 440
441 def __getitem__(self, i):
442 if isinstance(i, int):
443 return Point(self.positions[0][i], self.positions[1][i])
444 else:
445 raise TypeError, "Invalid argument type."
446 #elif isinstance( key, slice ):
447
437 def __str__(self): 448 def __str__(self):
438 return ' '.join([self.__getitem__(i).__str__() for i in xrange(self.length())]) 449 return ' '.join([self.__getitem__(i).__str__() for i in xrange(self.length())])
439 450
440 def __repr__(self): 451 def __repr__(self):
441 return str(self) 452 return self.__str__()
442
443 def __getitem__(self, i):
444 return Point(self.positions[0][i], self.positions[1][i])
445 453
446 def __iter__(self): 454 def __iter__(self):
447 self.iterInstantNum = 0 455 self.iterInstantNum = 0
448 return self 456 return self
449 457
564 if p.similarOrientation(refDirection, cosineThreshold): 572 if p.similarOrientation(refDirection, cosineThreshold):
565 count += 1 573 count += 1
566 if count > lengthThreshold: 574 if count > lengthThreshold:
567 return True 575 return True
568 return False 576 return False
569
570 577
571 def wiggliness(self): 578 def wiggliness(self):
572 return self.cumulatedDisplacement()/float(Point.distanceNorm2(self.__getitem__(0),self.__getitem__(self.length()-1))) 579 return self.cumulatedDisplacement()/float(Point.distanceNorm2(self.__getitem__(0),self.__getitem__(self.length()-1)))
573 580
574 def getIntersections(self, p1, p2): 581 def getIntersections(self, p1, p2):
623 class CurvilinearTrajectory(Trajectory): 630 class CurvilinearTrajectory(Trajectory):
624 '''Sub class of trajectory for trajectories with curvilinear coordinates and lane assignements 631 '''Sub class of trajectory for trajectories with curvilinear coordinates and lane assignements
625 longitudinal coordinate is stored as first coordinate (exterior name S) 632 longitudinal coordinate is stored as first coordinate (exterior name S)
626 lateral coordiante is stored as second coordinate''' 633 lateral coordiante is stored as second coordinate'''
627 634
628 def __init__(self, S = [], Y = [], lanes = []): 635 def __init__(self, S = None, Y = None, lanes = None):
629 self.positions = [S,Y] 636 if S == None or Y == None:
630 self.lanes = lanes 637 self.positions = [[],[]]
638 else:
639 self.positions = [S,Y]
640 if lanes == None:
641 self.lanes = []
642 else:
643 self.lanes = lanes
631 644
632 def __getitem__(self,i): 645 def __getitem__(self,i):
633 return [self.positions[0][i], self.positions[1][i], self.lanes[i]] 646 if isinstance(i, int):
647 return [self.positions[0][i], self.positions[1][i], self.lanes[i]]
648 else:
649 raise TypeError, "Invalid argument type."
650 #elif isinstance( key, slice ):
634 651
635 def getSCoordinates(self): 652 def getSCoordinates(self):
636 return self.getXCoordinates() 653 return self.getXCoordinates()
637 654
638 def getLanes(self): 655 def getLanes(self):