Commit 91639eb0 by Michael Büsch

### geo2d: Fix intersection check

`Signed-off-by: Michael Buesch <m@bues.ch>`
parent 0ab50fc2
 ... ... @@ -227,8 +227,8 @@ class LineSeg2D(Base2D): x = self.pointA.x y = (x - other.pointA.x) * other.slope + other.pointA.y return Inter2D(point=Point2D(x, y), intersects=self.__inRect( x, y, self.pointA, self.pointB)) intersects=self.__inRect(x, y, self.pointA, self.pointB) and\ self.__inRect(x, y, other.pointA, other.pointB)) def intersection(self, other): """Get the intersection of this line segment ... ... @@ -266,8 +266,8 @@ class LineSeg2D(Base2D): return self.__intersectionAligned(other) return Inter2D() return Inter2D(point=Point2D(x, y), intersects=self.__inRect( x, y, self.pointA, self.pointB)) intersects=self.__inRect(x, y, self.pointA, self.pointB) and\ self.__inRect(x, y, other.pointA, other.pointB)) except ZeroDivisionError: pass return Inter2D() ... ...
 ... ... @@ -156,6 +156,14 @@ class Test_LineSeg2D(object): assert_eq(inter.vect, Vect2D()) assert_eq(inter.lineSeg, LineSeg2D(Point2D(4, 5), Point2D(4, 5))) # AB vertical, CD horizontal, not intersecting inter = LineSeg2D(Point2D(x=180, y=130), Point2D(x=180, y=110)).intersection( LineSeg2D(Point2D(x=236, y=110), Point2D(x=240, y=110))) assert_is(inter.intersects, False) assert_eq(inter.point, Point2D(180, 110)) assert_eq(inter.vect, Vect2D()) assert_eq(inter.lineSeg, LineSeg2D(Point2D(180, 110), Point2D(180, 110))) # AB horizontal, CD vertical, not intersecting inter = LineSeg2D(Point2D(9, 5), Point2D(4, 5)).intersection( LineSeg2D(Point2D(8, 6), Point2D(8, 11))) ... ...
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!