diff trafficintelligence/moving.py @ 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 9012fb72d79a
children 4bc0651d91f9
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'''