correcting bug on line crossings (and renaming method)

Commit f3574e43c238 · Nicolas Saunier · 2025-04-11 16:14 -0400

Changeset
f3574e43c238221f2e701b4b998a0355795efe2a

View source at this commit

Comments

No comments yet.

Log in to comment

Diff

diff --git a/trafficintelligence/moving.py b/trafficintelligence/moving.py
--- a/trafficintelligence/moving.py
+++ b/trafficintelligence/moving.py
@@ -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'''
diff --git a/trafficintelligence/tests/moving.txt b/trafficintelligence/tests/moving.txt
--- a/trafficintelligence/tests/moving.txt
+++ b/trafficintelligence/tests/moving.txt
@@ -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]