changeset 531:f012a8ad7a0e

corrected bug in Point.timeToCollision that might result in negative TTCs
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Fri, 27 Jun 2014 17:32:11 -0400
parents d6445cbe7791
children 018653d1db3c
files python/moving.py python/tests/moving.txt
diffstat 2 files changed, 14 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/python/moving.py	Thu Jun 26 23:20:36 2014 -0400
+++ b/python/moving.py	Fri Jun 27 17:32:11 2014 -0400
@@ -290,13 +290,12 @@
             ttc2 = (-b - deltaRoot)/(2*a)
             if ttc1 >= 0 and ttc2 >= 0:
                 ttc = min(ttc1,ttc2)
-            else:
-                if ttc1 < 0:
-                    ttc = ttc2
-                elif ttc2 < 0:
-                    ttc = ttc1
-                else: # ttc1 < 0 and ttc2 < 0:
-                    ttc = None
+            elif ttc1 >= 0:
+                ttc = ttc1
+            elif ttc2 >= 0:
+                ttc = ttc2
+            else: # ttc1 < 0 and ttc2 < 0:
+                ttc = None
         else:
             ttc = None
         return ttc
--- a/python/tests/moving.txt	Thu Jun 26 23:20:36 2014 -0400
+++ b/python/tests/moving.txt	Fri Jun 27 17:32:11 2014 -0400
@@ -93,6 +93,14 @@
 True
 >>> abs(Point.timeToCollision(p1, p2, v1, v2, 0.1)-4.5) < 0.00001
 True
+>>> p1=Point(0,1)
+>>> p2=Point(1,0)
+>>> v1 = Point(0,0.1)
+>>> v2 = Point(0.1, 0)
+>>> Point.timeToCollision(p1, p2, v1, v2, 0.) == None
+True
+>>> Point.timeToCollision(p2, p1, v2, v1, 0.) == None
+True
 
 >>> o1 = MovingObject(positions = Trajectory([[0]*3,[2]*3]), velocities = Trajectory([[0]*3,[1]*3]))
 >>> o1.classifyUserTypeSpeedMotorized(0.5, np.median)