Skip to content

Commit d3e8eb2

Browse files
committed
test(geometry): cover more line intersection edge cases
1 parent f01ad41 commit d3e8eb2

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

src/test/java/com/thealgorithms/geometry/LineIntersectionTest.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,29 @@ void testCollinearOverlapHasNoUniquePoint() {
5959
assertTrue(LineIntersection.intersects(p1, p2, q1, q2));
6060
assertTrue(LineIntersection.intersectionPoint(p1, p2, q1, q2).isEmpty());
6161
}
62+
63+
@Test
64+
void testCollinearDisjointSegments() {
65+
Point p1 = new Point(0, 0);
66+
Point p2 = new Point(2, 2);
67+
Point q1 = new Point(3, 3);
68+
Point q2 = new Point(5, 5);
69+
70+
assertFalse(LineIntersection.intersects(p1, p2, q1, q2));
71+
assertTrue(LineIntersection.intersectionPoint(p1, p2, q1, q2).isEmpty());
72+
}
73+
74+
@Test
75+
void testVerticalAndHorizontalCrossingSegments() {
76+
Point p1 = new Point(2, 0);
77+
Point p2 = new Point(2, 5);
78+
Point q1 = new Point(0, 3);
79+
Point q2 = new Point(4, 3);
80+
81+
assertTrue(LineIntersection.intersects(p1, p2, q1, q2));
82+
Optional<Point2D.Double> intersection = LineIntersection.intersectionPoint(p1, p2, q1, q2);
83+
assertTrue(intersection.isPresent());
84+
assertEquals(2.0, intersection.orElseThrow().getX(), 1e-9);
85+
assertEquals(3.0, intersection.orElseThrow().getY(), 1e-9);
86+
}
6287
}

0 commit comments

Comments
 (0)