# HG changeset patch # User Nicolas Saunier # Date 1403904731 14400 # Node ID f012a8ad7a0e5748ec53bb5b17438204238ccb9b # Parent d6445cbe779177a5e2958472cb785544a7fb6fd2 corrected bug in Point.timeToCollision that might result in negative TTCs diff -r d6445cbe7791 -r f012a8ad7a0e python/moving.py --- 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 diff -r d6445cbe7791 -r f012a8ad7a0e python/tests/moving.txt --- 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)