# HG changeset patch # User Nicolas Saunier # Date 1744402491 14400 # Node ID f3574e43c238221f2e701b4b998a0355795efe2a # Parent c4bef099d0a233e0009e8f9f4a8b4d62e23b7ef3 correcting bug on line crossings (and renaming method) diff -r c4bef099d0a2 -r f3574e43c238 trafficintelligence/moving.py --- 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''' diff -r c4bef099d0a2 -r f3574e43c238 trafficintelligence/tests/moving.txt --- 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]