changeset 1109:6e8ab471ebd4

minor adjustment to Lionel s needs
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Tue, 16 Apr 2019 11:58:23 -0400
parents 77ce1cb3c868
children 6bbcd9433732
files trafficintelligence/moving.py
diffstat 1 files changed, 15 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/trafficintelligence/moving.py	Fri Mar 15 16:10:08 2019 -0400
+++ b/trafficintelligence/moving.py	Tue Apr 16 11:58:23 2019 -0400
@@ -263,7 +263,7 @@
 
     def rotate(self, theta):
         return Point(self.x*cos(theta)-self.y*sin(theta), self.x*sin(theta)+self.y*cos(theta))
-        
+
     def plot(self, options = 'o', **kwargs):
         plot([self.x], [self.y], options, **kwargs)
 
@@ -357,7 +357,7 @@
 
     @staticmethod
     def plotAll(points, options = '', **kwargs):
-        plot([p.x for p in points],[p.y for p in points], options, **kwargs)
+        plot([p.x for p in points], [p.y for p in points], options, **kwargs)
 
     def similarOrientation(self, refDirection, cosineThreshold):
         'Indicates whether the cosine of the vector and refDirection is smaller than cosineThreshold'
@@ -420,7 +420,7 @@
         rearLeft = Point(xmin, ymin)
         rearRight = Point(xmin, ymax)
         return [Point(Point.dot(e1, p), Point.dot(e2, p)) for p in [frontLeft, frontRight, rearRight, rearLeft]]
-    
+
 if shapelyAvailable:
     def pointsInPolygon(points, polygon):
         '''Optimized tests of a series of points within (Shapely) polygon (not prepared)'''
@@ -532,7 +532,6 @@
         d = s - alignment.getCumulativeDistance(i-1) # distance on subsegment
         #Get difference vector and then snap
         dv = alignment[i] - alignment[i-1]
-        #magnitude  = dv.norm2()
         normalizedV = dv.normalize()
         #snapped = alignment[i-1] + normalizedV*d # snapped point coordinate along alignment
         # add offset finally
@@ -968,7 +967,7 @@
                 intersections.append(p)
         return indices, intersections
 
-    def getTrajectoryInInterval(self, inter):
+    def subTrajectoryInInterval(self, inter):
         'Returns all position between index inter.first and index.last (included)'
         if inter.first >=0 and inter.last<= self.length():
             return Trajectory([self.positions[0][inter.first:inter.last+1],
@@ -1148,6 +1147,15 @@
     def getLaneAt(self, i):
         return self.lanes[i]
 
+    def subTrajectoryInInterval(self, inter):
+        'Returns all curvilinear positions between index inter.first and index.last (included)'
+        if inter.first >=0 and inter.last<= self.length():
+            return CurvilinearTrajectory(self.positions[0][inter.first:inter.last+1],
+                                         self.positions[1][inter.first:inter.last+1],
+                                         self.lanes[inter.first:inter.last+1])
+        else:
+            return None
+
     def addPositionSYL(self, s, y, lane = None):
         self.addPositionXY(s,y)
         self.lanes.append(lane)
@@ -1725,7 +1733,7 @@
             for proto in prototypes:
                 lcss.similarities(proto.getMovingObject().getPositions().asArray().T, self.getPositions().asArray().T)
                 similarities = lcss.similarityTable[-1, :-1].astype(float)
-                self.prototypeSimilarities.append(similarities/minimum(arange(1.,len(similarities)+1), proto.getMovingObject().length()*ones(len(similarities))))
+                self.prototypeSimilarities.append(similarities/minimum(arange(1., len(similarities)+1), proto.getMovingObject().length()*ones(len(similarities))))
     
     @staticmethod
     def computePET(obj1, obj2, collisionDistanceThreshold):
@@ -1795,7 +1803,7 @@
         else:
             print('Object {} has no features'.format(self.getNum()))
             return None
-                        
+
     ###
     # User Type Classification
     ###