changeset 1300:f3574e43c238

correcting bug on line crossings (and renaming method)
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Fri, 11 Apr 2025 16:14:51 -0400
parents c4bef099d0a2
children 7e42f83aab1f
files trafficintelligence/moving.py trafficintelligence/tests/moving.txt
diffstat 2 files changed, 6 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/trafficintelligence/moving.py	Wed Apr 09 15:57:50 2025 -0400
+++ b/trafficintelligence/moving.py	Fri Apr 11 16:14:51 2025 -0400
@@ -769,7 +769,7 @@
             return None, None
 
 def segmentLineIntersection(p1, p2, p3, p4):
-    '''Indicates if the line going through p1 and p2 intersects inside p3, p4'''
+    '''Indicates if the line going through p3 and p4 intersects inside p1, p2'''
     inter, ratio = intersection(p1, p2, p3, p4)
     if inter is not None and utils.inBetween(p3.x, p4.x, inter.x) and utils.inBetween(p3.y, p4.y, inter.y):
         return inter, ratio
@@ -1113,14 +1113,8 @@
         for i in range(self.length()-1):
             q1=self.__getitem__(i)
             q2=self.__getitem__(i+1)
-            p, ratio = segmentIntersection(p1, p2, q1, q2)
+            p, ratio = segmentIntersection(q1, q2, p1, p2)
             if p is not None:
-#                if q1.x != q2.x:
-#                    ratio = (p.x-q1.x)/(q2.x-q1.x)
-#                elif q1.y != q2.y:
-#                    ratio = (p.y-q1.y)/(q2.y-q1.y)
-#                else:
-#                    ratio = 0
                 indices.append(i+ratio)
                 intersections.append(p)
                 if computeOrientations:
@@ -1139,12 +1133,6 @@
             q2=self.__getitem__(i+1)
             p, ratio = segmentLineIntersection(q1, q2, p1, p2)
             if p is not None:
-                # if q1.x != q2.x:
-                #     ratio = (p.x-q1.x)/(q2.x-q1.x)
-                # elif q1.y != q2.y:
-                #     ratio = (p.y-q1.y)/(q2.y-q1.y)
-                # else:
-                #     ratio = 0
                 indices.append(i+ratio)
                 intersections.append(p)
         return indices, intersections
@@ -2006,7 +1994,7 @@
         self.startRouteID = startRouteID
         self.endRouteID = endRouteID
 
-    def getInstantsCrossingLine(self, p1, p2, computeOrientations = False):
+    def getInstantsCrossingSegment(self, p1, p2, computeOrientations = False):
         '''Returns the instant(s)
         at which the object passes from one side of the segment to the other
         empty list if there is no crossing'''
--- a/trafficintelligence/tests/moving.txt	Wed Apr 09 15:57:50 2025 -0400
+++ b/trafficintelligence/tests/moving.txt	Fri Apr 11 16:14:51 2025 -0400
@@ -110,18 +110,18 @@
 True
 
 >>> o1 = MovingObject.generate(1, Point(1.,0.), Point(1.,0.), TimeInterval(0,10))
->>> instants, intersections, rightToLeftOrientations = o1.getInstantsCrossingLine(Point(0.,3.5), Point(2.,3.5))
+>>> instants, intersections, rightToLeftOrientations = o1.getInstantsCrossingSegment(Point(0.,3.5), Point(2.,3.5))
 >>> rightToLeftOrientations == []
 True
 >>> len(instants)
 0
 >>> o1 = MovingObject.generate(1, Point(0.,1.), Point(1.,0.), TimeInterval(0,10))	
->>> instants, intersections, rightToLeftOrientations = o1.getInstantsCrossingLine(Point(3.5,0.), Point(3.5, 2.), False)
+>>> instants, intersections, rightToLeftOrientations = o1.getInstantsCrossingSegment(Point(3.5,0.), Point(3.5, 2.), False)
 >>> rightToLeftOrientations == []
 True
 >>> instants[0]
 3.5
->>> instants, intersections, rightToLeftOrientations = o1.getInstantsCrossingLine(Point(3.5,0.), Point(3.5, 2.), True)
+>>> instants, intersections, rightToLeftOrientations = o1.getInstantsCrossingSegment(Point(3.5,0.), Point(3.5, 2.), True)
 >>> len(rightToLeftOrientations)
 1
 >>> rightToLeftOrientations[0]