- Notifications
You must be signed in to change notification settings - Fork 19.9k
/
Copy pathLiangBarskyTest.java
65 lines (51 loc) · 2.45 KB
/
LiangBarskyTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
packagecom.thealgorithms.lineclipping;
importstaticorg.junit.jupiter.api.Assertions.assertEquals;
importstaticorg.junit.jupiter.api.Assertions.assertNotNull;
importstaticorg.junit.jupiter.api.Assertions.assertNull;
importcom.thealgorithms.lineclipping.utils.Line;
importcom.thealgorithms.lineclipping.utils.Point;
importorg.junit.jupiter.api.Test;
/**
* @author shikarisohan
* @since 10/5/24
*/
classLiangBarskyTest {
LiangBarskylb = newLiangBarsky(1.0, 1.0, 10.0, 10.0);
@Test
voidtestLineCompletelyInside() {
Lineline = newLine(newPoint(2.0, 2.0), newPoint(8.0, 8.0));
LineclippedLine = lb.liangBarskyClip(line);
assertNotNull(clippedLine, "Line should not be null.");
assertEquals(line, clippedLine, "Line inside the window should remain unchanged.");
}
@Test
voidtestLineCompletelyOutside() {
Lineline = newLine(newPoint(12.0, 12.0), newPoint(15.0, 18.0));
LineclippedLine = lb.liangBarskyClip(line);
assertNull(clippedLine, "Line should be null because it's completely outside.");
}
@Test
voidtestLinePartiallyInside() {
Lineline = newLine(newPoint(5.0, 5.0), newPoint(12.0, 12.0));
LineexpectedClippedLine = newLine(newPoint(5.0, 5.0), newPoint(10.0, 10.0)); // Clipped at (10, 10)
LineclippedLine = lb.liangBarskyClip(line);
assertNotNull(clippedLine, "Line should not be null.");
assertEquals(expectedClippedLine, clippedLine, "Line should be clipped correctly.");
}
@Test
voidtestDiagonalLineThroughClippingWindow() {
Lineline = newLine(newPoint(0.0, 0.0), newPoint(12.0, 12.0));
LineexpectedClippedLine = newLine(newPoint(1.0, 1.0), newPoint(10.0, 10.0)); // Clipped at both boundaries
LineclippedLine = lb.liangBarskyClip(line);
assertNotNull(clippedLine, "Line should not be null.");
assertEquals(expectedClippedLine, clippedLine, "Diagonal line should be clipped correctly.");
}
@Test
voidtestVerticalLineClipping() {
Lineline = newLine(newPoint(5.0, 0.0), newPoint(5.0, 12.0));
LineexpectedClippedLine = newLine(newPoint(5.0, 1.0), newPoint(5.0, 10.0)); // Clipped at yMin and yMax
LineclippedLine = lb.liangBarskyClip(line);
assertNotNull(clippedLine, "Line should not be null.");
assertEquals(expectedClippedLine, clippedLine, "Vertical line should be clipped correctly.");
}
}