changeset 582:7e1ae4d97f1a

corrected bug for curvilinear trajectory with only one position and differentiation
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Thu, 18 Sep 2014 15:36:57 -0400
parents 10e8a9f2bd9f
children 6ebfb43e938e
files python/moving.py python/tests/moving.txt
diffstat 2 files changed, 7 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/python/moving.py	Wed Sep 17 17:29:19 2014 -0400
+++ b/python/moving.py	Thu Sep 18 15:36:57 2014 -0400
@@ -614,6 +614,9 @@
     def length(self):
         return self.__len__()
 
+    def empty(self):
+        return self.__len__() == 0
+
     def __getitem__(self, i):
         if isinstance(i, int):
             return Point(self.positions[0][i], self.positions[1][i])
@@ -884,7 +887,7 @@
             p2 = self[i]
             diff.addPositionSYL(p2[0]-p1[0], p2[1]-p1[1], p1[2])
             p1=p2
-        if doubleLastPosition:
+        if doubleLastPosition and self.length() > 1:
             diff.addPosition(diff[-1])
         return diff
 
--- a/python/tests/moving.txt	Wed Sep 17 17:29:19 2014 -0400
+++ b/python/tests/moving.txt	Thu Sep 18 15:36:57 2014 -0400
@@ -144,6 +144,9 @@
 [1.0, 0.0, '1'] [1.0, 0.099..., '1'] [2.0, 0.099..., '1']
 >>> t.differentiate(True) # doctest:+ELLIPSIS
 [1.0, 0.0, '1'] [1.0, 0.099..., '1'] [2.0, 0.099..., '1'] [2.0, 0.099..., '1']
+>>> t = CurvilinearTrajectory(S = [1.], Y = [0.5], lanes = ['1'])
+>>> t.differentiate().empty()
+True
 
 >>> o1 = MovingObject(positions = Trajectory([[0]*3,[2]*3]), velocities = Trajectory([[0]*3,[1]*3]))
 >>> o1.classifyUserTypeSpeedMotorized(0.5, np.median)