@@ -10,25 +10,70 @@ p2 = GI.Polygon([[(1.0, 0.0), (2.0, 0.0), (2.0, 1.0), (1.0, 1.0), (1.0, 0.0)]])
10
10
p3 = GI. Polygon ([[(1.0 , 0.0 ), (2.0 , 0.0 ), (2.0 , - 1.0 ), (1.0 , - 1.0 ), (1.0 , 0.0 )]])
11
11
# (p1, p4) -> polygons are completly disjoint (no holes)
12
12
p4 = GI. Polygon ([[(1.0 , - 1.0 ), (2.0 , - 1.0 ), (2.0 , - 2.0 ), (1.0 , - 2.0 ), (1.0 , - 1.0 )]])
13
+ # (p1, p5) -> polygons cut through one another
14
+ p5 = GI. Polygon ([[(1.0 , - 1.0 ), (2.0 , - 1.0 ), (2.0 , 4.0 ), (1.0 , 4.0 ), (1.0 , - 1.0 )]])
13
15
14
16
mp1 = GI. MultiPolygon ([p1])
15
17
mp2 = GI. MultiPolygon ([p1, p1])
16
18
mp3 = GI. MultiPolygon ([p1, p2, p3])
17
19
mp4 = GI. MultiPolygon ([p1, p4])
20
+ mp5 = GI. MultiPolygon ([p1, p5])
21
+ mp6 = GI. MultiPolygon ([ # four interlocking polygons forming a hole
22
+ [[(- 5.0 , 10.0 ), (- 5.0 , 15.0 ), (15.0 , 15.0 ), (15.0 , 10.0 ), (- 5.0 , 10.0 )]],
23
+ [[(- 5.0 , - 5.0 ), (- 5.0 , 0.0 ), (15.0 , 0.0 ), (15.0 , - 5.0 ), (- 5.0 , - 5.0 )]],
24
+ [[(10.0 , - 5.0 ), (10.0 , 15.0 ), (15.0 , 15.0 ), (15.0 , - 5.0 ), (10.0 , - 5.0 )]],
25
+ [[(- 5.0 , - 5.0 ), (- 5.0 , 15.0 ), (0.0 , 15.0 ), (0.0 , - 5.0 ), (- 5.0 , - 5.0 )]],
26
+ ])
18
27
19
- fixed_mp1 = GO. UnionIntersectingPolygons ()(mp1)
20
- @test GI. npolygon (fixed_mp1 ) == 1
21
- @test GO. equals (GI. getpolygon (fixed_mp1 , 1 ), p1)
28
+ union_fixed_mp1 = GO. UnionIntersectingPolygons ()(mp1)
29
+ @test GI. npolygon (union_fixed_mp1 ) == 1
30
+ @test GO. equals (GI. getpolygon (union_fixed_mp1 , 1 ), p1)
22
31
23
- fixed_mp2 = GO. UnionIntersectingPolygons ()(mp2)
24
- @test GI. npolygon (fixed_mp2) == 1
25
- @test GO. equals (GI. getpolygon (fixed_mp2, 1 ), p1)
32
+ diff_fixed_mp1 = GO. DiffIntersectingPolygons ()(mp1)
33
+ @test GO. equals (diff_fixed_mp1, union_fixed_mp1)
26
34
27
- fixed_mp3 = GO. UnionIntersectingPolygons ()(mp3 )
28
- @test GI. npolygon (fixed_mp3 ) == 1
29
- @test GO. coveredby (p1, fixed_mp3) && GO . coveredby (p2, fixed_mp3) && GO . coveredby (p3, fixed_mp3 )
35
+ union_fixed_mp2 = GO. UnionIntersectingPolygons ()(mp2 )
36
+ @test GI. npolygon (union_fixed_mp2 ) == 1
37
+ @test GO. equals (GI . getpolygon (union_fixed_mp2, 1 ), p1 )
30
38
31
- fixed_mp4 = GO. UnionIntersectingPolygons ()(mp4)
32
- @test GI. npolygon (fixed_mp4) == 2
33
- @test (GO. equals (GI. getpolygon (fixed_mp4, 1 ), p1) && GO. equals (GI. getpolygon (fixed_mp4, 2 ), p4)) ||
34
- (GO. equals (GI. getpolygon (fixed_mp4, 2 ), p1) && GO. equals (GI. getpolygon (fixed_mp4, 1 ), p4))
39
+ diff_fixed_mp2 = GO. DiffIntersectingPolygons ()(mp2)
40
+ @test GO. equals (diff_fixed_mp2, union_fixed_mp2)
41
+
42
+ union_fixed_mp3 = GO. UnionIntersectingPolygons ()(mp3)
43
+ @test GI. npolygon (union_fixed_mp3) == 1
44
+ @test all ((GO. coveredby (p, union_fixed_mp3) for p in GI. getpolygon (mp3)))
45
+ diff_polys = GO. difference (union_fixed_mp3, mp3; target = GI. PolygonTrait (), fix_multipoly = nothing )
46
+ @test sum (GO. area, diff_polys; init = 0.0 ) == 0
47
+
48
+ diff_fixed_mp3 = GO. DiffIntersectingPolygons ()(mp3)
49
+ @test GI. npolygon (diff_fixed_mp3) == 3
50
+ @test all ((GO. coveredby (p, union_fixed_mp3) for p in GI. getpolygon (diff_fixed_mp3)))
51
+
52
+ union_fixed_mp4 = GO. UnionIntersectingPolygons ()(mp4)
53
+ @test GI. npolygon (union_fixed_mp4) == 2
54
+ @test (GO. equals (GI. getpolygon (union_fixed_mp4, 1 ), p1) && GO. equals (GI. getpolygon (union_fixed_mp4, 2 ), p4)) ||
55
+ (GO. equals (GI. getpolygon (union_fixed_mp4, 2 ), p1) && GO. equals (GI. getpolygon (union_fixed_mp4, 1 ), p4))
56
+
57
+ diff_fixed_mp4 = GO. DiffIntersectingPolygons ()(mp4)
58
+ @test GO. equals (diff_fixed_mp4, union_fixed_mp4)
59
+
60
+ union_fixed_mp5 = GO. UnionIntersectingPolygons ()(mp5)
61
+ @test GI. npolygon (union_fixed_mp5) == 1
62
+ @test all ((GO. coveredby (p, union_fixed_mp5) for p in GI. getpolygon (mp5)))
63
+ diff_polys = GO. difference (union_fixed_mp5, mp5; target = GI. PolygonTrait (), fix_multipoly = nothing )
64
+ @test sum (GO. area, diff_polys; init = 0.0 ) == 0
65
+
66
+ diff_fixed_mp5 = GO. DiffIntersectingPolygons ()(mp5)
67
+ @test GI. npolygon (diff_fixed_mp5) == 3
68
+ @test all ((GO. coveredby (p, union_fixed_mp5) for p in GI. getpolygon (diff_fixed_mp5)))
69
+
70
+ union_fixed_mp6 = GO. UnionIntersectingPolygons ()(mp6)
71
+ @test GI. npolygon (union_fixed_mp6) == 1
72
+ @test GI. nhole (GI. getpolygon (union_fixed_mp6, 1 )) == 1
73
+ @test all ((GO. coveredby (p, union_fixed_mp6) for p in GI. getpolygon (mp6)))
74
+ diff_polys = GO. difference (union_fixed_mp6, mp6; target = GI. PolygonTrait (), fix_multipoly = nothing )
75
+ @test sum (GO. area, diff_polys; init = 0.0 ) == 0
76
+
77
+ diff_fixed_mp6 = GO. DiffIntersectingPolygons ()(mp6)
78
+ @test GI. npolygon (diff_fixed_mp6) == 4
79
+ @test all ((GO. coveredby (p, union_fixed_mp6) for p in GI. getpolygon (diff_fixed_mp6)))
0 commit comments