Skip to content

Commit 116b213

Browse files
committed
1.4.0+1.5.0 tests
1 parent b3f21bd commit 116b213

File tree

5 files changed

+158
-1
lines changed

5 files changed

+158
-1
lines changed

src/main/java/clipper2/core/Rect64.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,17 @@ public boolean Contains(Rect64 rec) {
9191
return rec.left >= left && rec.right <= right && rec.top >= top && rec.bottom <= bottom;
9292
}
9393

94+
public static Rect64 opAdd(Rect64 lhs, Rect64 rhs) {
95+
if (!lhs.IsValid()) {
96+
return rhs.clone();
97+
}
98+
if (!rhs.IsValid()) {
99+
return lhs.clone();
100+
}
101+
return new Rect64(Math.min(lhs.left, rhs.left), Math.min(lhs.top, rhs.top), Math.max(lhs.right, rhs.right),
102+
Math.max(lhs.bottom, rhs.bottom));
103+
}
104+
94105
@Override
95106
public Rect64 clone() {
96107
Rect64 varCopy = new Rect64();
@@ -102,4 +113,4 @@ public Rect64 clone() {
102113

103114
return varCopy;
104115
}
105-
}
116+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package clipper2;
2+
3+
import static org.junit.jupiter.api.Assertions.assertEquals;
4+
import static org.junit.jupiter.api.Assertions.assertTrue;
5+
6+
import org.junit.jupiter.api.Test;
7+
8+
import clipper2.core.ClipType;
9+
import clipper2.core.FillRule;
10+
import clipper2.core.InternalClipper;
11+
import clipper2.core.Path64;
12+
import clipper2.core.Paths64;
13+
import clipper2.core.Point64;
14+
import clipper2.engine.Clipper64;
15+
16+
class TestIsCollinear {
17+
18+
@Test
19+
void testIsCollinear() {
20+
// A large integer not representable exactly by double.
21+
final long i = 9007199254740993L;
22+
Point64 pt1 = new Point64(0, 0);
23+
Point64 sharedPt = new Point64(i, i * 10);
24+
Point64 pt2 = new Point64(i * 10, i * 100);
25+
assertTrue(InternalClipper.IsCollinear(pt1, sharedPt, pt2));
26+
}
27+
28+
@Test
29+
void testIsCollinear2() { // see #831
30+
final long i = 0x4000000000000L;
31+
Path64 subject = new Path64(new Point64(-i, -i), new Point64(i, -i), new Point64(-i, i), new Point64(i, i));
32+
Clipper64 clipper = new Clipper64();
33+
clipper.AddSubject(new Paths64(subject));
34+
Paths64 solution = new Paths64();
35+
clipper.Execute(ClipType.Union, FillRule.EvenOdd, solution);
36+
assertEquals(2, solution.size());
37+
}
38+
}

src/test/java/clipper2/TestOffsets.java

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
import clipper2.core.Path64;
1111
import clipper2.core.Paths64;
12+
import clipper2.core.PathsD;
1213
import clipper2.core.Point64;
1314
import clipper2.core.PointD;
1415
import clipper2.offset.ClipperOffset;
@@ -237,6 +238,39 @@ void TestOffsets9() { // (#733)
237238
assertEquals(0, solution.size());
238239
}
239240

241+
@Test
242+
void TestOffsets10() { // see #715
243+
Paths64 subjects = new Paths64(List.of(Clipper.MakePath(new long[] { 508685336, -435806096, 509492982, -434729201, 509615525, -434003092, 509615525,
244+
493372891, 509206033, 494655198, 508129138, 495462844, 507403029, 495585387, -545800889, 495585387, -547083196, 495175895, -547890842,
245+
494099000, -548013385, 493372891, -548013385, -434003092, -547603893, -435285399, -546526998, -436093045, -545800889, -436215588, 507403029,
246+
-436215588 }), Clipper.MakePath(new long[] { 106954765, -62914568, 106795129, -63717113, 106340524, -64397478, 105660159, -64852084, 104857613,
247+
-65011720, 104055068, -64852084, 103374703, -64397478, 102920097, -63717113, 102760461, -62914568, 102920097, -62112022, 103374703,
248+
-61431657, 104055068, -60977052, 104857613, -60817416, 105660159, -60977052, 106340524, -61431657, 106795129, -62112022 })));
249+
250+
ClipperOffset offseter = new ClipperOffset(2, 104857.61318750000);
251+
Paths64 solution = new Paths64();
252+
offseter.AddPaths(subjects, JoinType.Round, EndType.Polygon);
253+
offseter.Execute(-2212495.6382562499, solution);
254+
assertEquals(2, solution.size());
255+
}
256+
257+
@Test
258+
void TestOffsets11() { // see #405
259+
PathsD subject = new PathsD();
260+
subject.add(Clipper.MakePath(new double[] { -1.0, -1.0, -1.0, 11.0, 11.0, 11.0, 11.0, -1.0 }));
261+
// offset polygon
262+
PathsD solution = Clipper.InflatePaths(subject, -50, JoinType.Miter, EndType.Polygon);
263+
assertTrue(solution.isEmpty());
264+
}
265+
266+
@Test
267+
void TestOffsets12() { // see #873
268+
Paths64 subject = new Paths64();
269+
subject.add(Clipper.MakePath(new long[] { 667680768, -36382704, 737202688, -87034880, 742581888, -86055680, 747603968, -84684800 }));
270+
Paths64 solution = Clipper.InflatePaths(subject, -249561088, JoinType.Miter, EndType.Polygon);
271+
assertTrue(solution.isEmpty());
272+
}
273+
240274
private static Point64 midPoint(Point64 p1, Point64 p2) {
241275
Point64 result = new Point64();
242276
result.setX((p1.x + p2.x) / 2);

src/test/java/clipper2/TestPolygons.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
11
package clipper2;
22

3+
import static org.junit.jupiter.api.Assertions.assertEquals;
34
import static org.junit.jupiter.api.Assertions.assertTrue;
45

56
import java.io.IOException;
67
import java.util.Arrays;
78
import java.util.stream.Stream;
89

10+
import org.junit.jupiter.api.Test;
911
import org.junit.jupiter.params.ParameterizedTest;
1012
import org.junit.jupiter.params.provider.Arguments;
1113
import org.junit.jupiter.params.provider.MethodSource;
1214

1315
import clipper2.ClipperFileIO.TestCase;
16+
import clipper2.core.ClipType;
17+
import clipper2.core.FillRule;
1418
import clipper2.core.Paths64;
1519
import clipper2.engine.Clipper64;
1620

@@ -75,4 +79,19 @@ final void RunPolygonsTestCase(TestCase test, int testNum, Object o, Object o1)
7579
}
7680

7781
}
82+
83+
@Test
84+
void TestCollinearOnMacOs() { // #777
85+
Paths64 subject = new Paths64();
86+
subject.add(Clipper.MakePath(new long[] { 0, -453054451, 0, -433253797, -455550000, 0 }));
87+
subject.add(Clipper.MakePath(new long[] { 0, -433253797, 0, 0, -455550000, 0 }));
88+
Clipper64 clipper = new Clipper64();
89+
clipper.setPreserveCollinear(false);
90+
clipper.AddSubject(subject);
91+
Paths64 solution = new Paths64();
92+
clipper.Execute(ClipType.Union, FillRule.NonZero, solution);
93+
assertEquals(1, solution.size());
94+
assertEquals(3, solution.get(0).size());
95+
assertEquals(Clipper.IsPositive(subject.get(0)), Clipper.IsPositive(solution.get(0)));
96+
}
7897
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package clipper2;
2+
3+
import static org.junit.jupiter.api.Assertions.assertEquals;
4+
5+
import org.junit.jupiter.api.Test;
6+
7+
import clipper2.core.Rect64;
8+
9+
class TestRect {
10+
11+
private static void assertRectEquals(Rect64 expected, Rect64 actual) {
12+
assertEquals(expected.left, actual.left);
13+
assertEquals(expected.top, actual.top);
14+
assertEquals(expected.right, actual.right);
15+
assertEquals(expected.bottom, actual.bottom);
16+
}
17+
18+
@Test
19+
void testRectOpAdd() {
20+
{
21+
Rect64 lhs = new Rect64(false);
22+
Rect64 rhs = new Rect64(-1, -1, 10, 10);
23+
Rect64 sum = Rect64.opAdd(lhs, rhs);
24+
assertRectEquals(rhs, sum);
25+
sum = Rect64.opAdd(rhs, lhs);
26+
assertRectEquals(rhs, sum);
27+
}
28+
{
29+
Rect64 lhs = new Rect64(false);
30+
Rect64 rhs = new Rect64(1, 1, 10, 10);
31+
Rect64 sum = Rect64.opAdd(lhs, rhs);
32+
assertRectEquals(rhs, sum);
33+
sum = Rect64.opAdd(rhs, lhs);
34+
assertRectEquals(rhs, sum);
35+
}
36+
{
37+
Rect64 lhs = new Rect64(0, 0, 1, 1);
38+
Rect64 rhs = new Rect64(-1, -1, 0, 0);
39+
Rect64 expected = new Rect64(-1, -1, 1, 1);
40+
Rect64 sum = Rect64.opAdd(lhs, rhs);
41+
assertRectEquals(expected, sum);
42+
sum = Rect64.opAdd(rhs, lhs);
43+
assertRectEquals(expected, sum);
44+
}
45+
{
46+
Rect64 lhs = new Rect64(-10, -10, -1, -1);
47+
Rect64 rhs = new Rect64(1, 1, 10, 10);
48+
Rect64 expected = new Rect64(-10, -10, 10, 10);
49+
Rect64 sum = Rect64.opAdd(lhs, rhs);
50+
assertRectEquals(expected, sum);
51+
sum = Rect64.opAdd(rhs, lhs);
52+
assertRectEquals(expected, sum);
53+
}
54+
}
55+
}

0 commit comments

Comments
 (0)