changeset 583:6ebfb43e938e

added midpoint function (from laurent gauthier)
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Mon, 22 Sep 2014 16:21:53 -0400
parents 7e1ae4d97f1a
children 5bda87ac0a69 3550da215e7a
files python/moving.py python/tests/moving.txt
diffstat 2 files changed, 6 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/python/moving.py	Thu Sep 18 15:36:57 2014 -0400
+++ b/python/moving.py	Mon Sep 22 16:21:53 2014 -0400
@@ -316,6 +316,10 @@
             ttc = None
         return ttc
 
+    @staticmethod   
+    def midPoint(p1, p2):
+        'Returns the middle of the segment [p1, p2]'
+        return Point(0.5*p1.x+0.5*p2.x, 0.5*p1.y+0.5*p2.y)
 
 if shapelyAvailable:
     def pointsInPolygon(points, polygon):
--- a/python/tests/moving.txt	Thu Sep 18 15:36:57 2014 -0400
+++ b/python/tests/moving.txt	Mon Sep 22 16:21:53 2014 -0400
@@ -138,6 +138,8 @@
 True
 >>> Point.timeToCollision(p2, p1, v2, v1, 0.) == None
 True
+>>> Point.midPoint(p1, p2)
+(0.500000,0.500000)
 
 >>> t = CurvilinearTrajectory(S = [1., 2., 3., 5.], Y = [0.5, 0.5, 0.6, 0.7], lanes = ['1']*4)
 >>> t.differentiate() # doctest:+ELLIPSIS