|
1 | | -@testset "Clipping" begin |
2 | | - @testset "SutherlandHodgman" begin |
3 | | - # triangle |
4 | | - poly = Triangle(cart(6, 2), cart(3, 5), cart(0, 2)) |
5 | | - other = Quadrangle(cart(5, 0), cart(5, 4), cart(0, 4), cart(0, 0)) |
6 | | - clipped = clip(poly, other, SutherlandHodgman()) |
7 | | - @test issimple(clipped) |
8 | | - @test all(vertices(clipped) .≈ [cart(5, 3), cart(4, 4), cart(2, 4), cart(0, 2), cart(5, 2)]) |
| 1 | +@testitem "SutherlandHodgman" setup = [Setup] begin |
| 2 | + # triangle |
| 3 | + poly = Triangle(cart(6, 2), cart(3, 5), cart(0, 2)) |
| 4 | + other = Quadrangle(cart(5, 0), cart(5, 4), cart(0, 4), cart(0, 0)) |
| 5 | + clipped = clip(poly, other, SutherlandHodgman()) |
| 6 | + @test issimple(clipped) |
| 7 | + @test all(vertices(clipped) .≈ [cart(5, 3), cart(4, 4), cart(2, 4), cart(0, 2), cart(5, 2)]) |
9 | 8 |
|
10 | | - # octagon |
11 | | - poly = Octagon(cart(8, -2), cart(8, 5), cart(2, 5), cart(4, 3), cart(6, 3), cart(4, 1), cart(2, 1), cart(2, -2)) |
12 | | - other = Quadrangle(cart(5, 0), cart(5, 4), cart(0, 4), cart(0, 0)) |
13 | | - clipped = clip(poly, other, SutherlandHodgman()) |
14 | | - @test !issimple(clipped) |
15 | | - @test all( |
16 | | - vertices(clipped) .≈ |
17 | | - [cart(3, 4), cart(4, 3), cart(5, 3), cart(5, 2), cart(4, 1), cart(2, 1), cart(2, 0), cart(5, 0), cart(5, 4)] |
18 | | - ) |
| 9 | + # octagon |
| 10 | + poly = Octagon(cart(8, -2), cart(8, 5), cart(2, 5), cart(4, 3), cart(6, 3), cart(4, 1), cart(2, 1), cart(2, -2)) |
| 11 | + other = Quadrangle(cart(5, 0), cart(5, 4), cart(0, 4), cart(0, 0)) |
| 12 | + clipped = clip(poly, other, SutherlandHodgman()) |
| 13 | + @test !issimple(clipped) |
| 14 | + @test all( |
| 15 | + vertices(clipped) .≈ |
| 16 | + [cart(3, 4), cart(4, 3), cart(5, 3), cart(5, 2), cart(4, 1), cart(2, 1), cart(2, 0), cart(5, 0), cart(5, 4)] |
| 17 | + ) |
19 | 18 |
|
20 | | - # inside |
21 | | - poly = Quadrangle(cart(1, 0), cart(1, 1), cart(0, 1), cart(0, 0)) |
22 | | - other = Quadrangle(cart(5, 0), cart(5, 4), cart(0, 4), cart(0, 0)) |
23 | | - clipped = clip(poly, other, SutherlandHodgman()) |
24 | | - @test issimple(clipped) |
25 | | - @test all(vertices(clipped) .≈ vertices(poly)) |
| 19 | + # inside |
| 20 | + poly = Quadrangle(cart(1, 0), cart(1, 1), cart(0, 1), cart(0, 0)) |
| 21 | + other = Quadrangle(cart(5, 0), cart(5, 4), cart(0, 4), cart(0, 0)) |
| 22 | + clipped = clip(poly, other, SutherlandHodgman()) |
| 23 | + @test issimple(clipped) |
| 24 | + @test all(vertices(clipped) .≈ vertices(poly)) |
26 | 25 |
|
27 | | - # outside |
28 | | - poly = Quadrangle(cart(7, 6), cart(7, 7), cart(6, 7), cart(6, 6)) |
29 | | - other = Quadrangle(cart(5, 0), cart(5, 4), cart(0, 4), cart(0, 0)) |
30 | | - clipped = clip(poly, other, SutherlandHodgman()) |
31 | | - @test isnothing(clipped) |
| 26 | + # outside |
| 27 | + poly = Quadrangle(cart(7, 6), cart(7, 7), cart(6, 7), cart(6, 6)) |
| 28 | + other = Quadrangle(cart(5, 0), cart(5, 4), cart(0, 4), cart(0, 0)) |
| 29 | + clipped = clip(poly, other, SutherlandHodgman()) |
| 30 | + @test isnothing(clipped) |
32 | 31 |
|
33 | | - # surrounded |
34 | | - poly = Hexagon(cart(0, 2), cart(-2, 2), cart(-2, 0), cart(0, -2), cart(2, -2), cart(2, 0)) |
35 | | - other = Hexagon(cart(1, 0), cart(0, 1), cart(-1, 1), cart(-1, 0), cart(0, -1), cart(1, -1)) |
36 | | - clipped = clip(poly, other, SutherlandHodgman()) |
37 | | - @test issimple(clipped) |
38 | | - @test all(vertices(clipped) .≈ vertices(other)) |
| 32 | + # surrounded |
| 33 | + poly = Hexagon(cart(0, 2), cart(-2, 2), cart(-2, 0), cart(0, -2), cart(2, -2), cart(2, 0)) |
| 34 | + other = Hexagon(cart(1, 0), cart(0, 1), cart(-1, 1), cart(-1, 0), cart(0, -1), cart(1, -1)) |
| 35 | + clipped = clip(poly, other, SutherlandHodgman()) |
| 36 | + @test issimple(clipped) |
| 37 | + @test all(vertices(clipped) .≈ vertices(other)) |
39 | 38 |
|
40 | | - # PolyArea with box |
41 | | - outer = Ring(cart(8, 0), cart(4, 8), cart(2, 8), cart(-2, 0), cart(0, 0), cart(1, 2), cart(5, 2), cart(6, 0)) |
42 | | - inner = Ring(cart(4, 4), cart(2, 4), cart(3, 6)) |
43 | | - poly = PolyArea([outer, inner]) |
44 | | - other = Box(cart(0, 1), cart(3, 7)) |
45 | | - clipped = clip(poly, other, SutherlandHodgman()) |
46 | | - crings = rings(clipped) |
47 | | - @test !issimple(clipped) |
48 | | - @test all( |
49 | | - vertices(crings[1]) .≈ |
50 | | - [cart(1.5, 7.0), cart(0.0, 4.0), cart(0.0, 1.0), cart(0.5, 1.0), cart(1.0, 2.0), cart(3.0, 2.0), cart(3.0, 7.0)] |
51 | | - ) |
52 | | - @test all(vertices(crings[2]) .≈ [cart(3.0, 4.0), cart(2.0, 4.0), cart(3.0, 6.0)]) |
| 39 | + # PolyArea with box |
| 40 | + outer = Ring(cart(8, 0), cart(4, 8), cart(2, 8), cart(-2, 0), cart(0, 0), cart(1, 2), cart(5, 2), cart(6, 0)) |
| 41 | + inner = Ring(cart(4, 4), cart(2, 4), cart(3, 6)) |
| 42 | + poly = PolyArea([outer, inner]) |
| 43 | + other = Box(cart(0, 1), cart(3, 7)) |
| 44 | + clipped = clip(poly, other, SutherlandHodgman()) |
| 45 | + crings = rings(clipped) |
| 46 | + @test !issimple(clipped) |
| 47 | + @test all( |
| 48 | + vertices(crings[1]) .≈ |
| 49 | + [cart(1.5, 7.0), cart(0.0, 4.0), cart(0.0, 1.0), cart(0.5, 1.0), cart(1.0, 2.0), cart(3.0, 2.0), cart(3.0, 7.0)] |
| 50 | + ) |
| 51 | + @test all(vertices(crings[2]) .≈ [cart(3.0, 4.0), cart(2.0, 4.0), cart(3.0, 6.0)]) |
53 | 52 |
|
54 | | - # PolyArea with outer ring outside and inner ring inside |
55 | | - outer = Ring(cart(8, 0), cart(2, 6), cart(-4, 0)) |
56 | | - inner = Ring(cart(1, 3), cart(3, 3), cart(3, 1), cart(1, 1)) |
57 | | - poly = PolyArea([outer, inner]) |
58 | | - other = Quadrangle(cart(4, 4), cart(0, 4), cart(0, 0), cart(4, 0)) |
59 | | - clipped = clip(poly, other, SutherlandHodgman()) |
60 | | - @test !issimple(clipped) |
61 | | - crings = rings(clipped) |
62 | | - @test all(vertices(crings[1]) .≈ vertices(other)) |
63 | | - @test all(vertices(crings[2]) .≈ vertices(inner)) |
| 53 | + # PolyArea with outer ring outside and inner ring inside |
| 54 | + outer = Ring(cart(8, 0), cart(2, 6), cart(-4, 0)) |
| 55 | + inner = Ring(cart(1, 3), cart(3, 3), cart(3, 1), cart(1, 1)) |
| 56 | + poly = PolyArea([outer, inner]) |
| 57 | + other = Quadrangle(cart(4, 4), cart(0, 4), cart(0, 0), cart(4, 0)) |
| 58 | + clipped = clip(poly, other, SutherlandHodgman()) |
| 59 | + @test !issimple(clipped) |
| 60 | + crings = rings(clipped) |
| 61 | + @test all(vertices(crings[1]) .≈ vertices(other)) |
| 62 | + @test all(vertices(crings[2]) .≈ vertices(inner)) |
64 | 63 |
|
65 | | - # PolyArea with one inner ring inside `other` and another inner ring outside `other` |
66 | | - outer = Ring(cart(6, 4), cart(6, 7), cart(1, 6), cart(1, 1), cart(5, 2)) |
67 | | - inner₁ = Ring(cart(3, 3), cart(3, 4), cart(4, 3)) |
68 | | - inner₂ = Ring(cart(2, 5), cart(2, 6), cart(3, 5)) |
69 | | - poly = PolyArea([outer, inner₁, inner₂]) |
70 | | - other = PolyArea(Ring(cart(6, 1), cart(7, 2), cart(6, 5), cart(0, 2), cart(1, 1))) |
71 | | - clipped = clip(poly, other, SutherlandHodgman()) |
72 | | - crings = rings(clipped) |
73 | | - @test !issimple(clipped) |
74 | | - @test length(crings) == 2 |
75 | | - @test all(vertices(crings[1]) .≈ [cart(6, 4), cart(6, 5), cart(1, 2.5), cart(1, 1), cart(5, 2)]) |
76 | | - @test all(vertices(crings[2]) .≈ [cart(3.0, 3.0), cart(3.0, 3.5), cart(10 / 3, 11 / 3), cart(4.0, 3.0)]) |
77 | | - end |
| 64 | + # PolyArea with one inner ring inside `other` and another inner ring outside `other` |
| 65 | + outer = Ring(cart(6, 4), cart(6, 7), cart(1, 6), cart(1, 1), cart(5, 2)) |
| 66 | + inner₁ = Ring(cart(3, 3), cart(3, 4), cart(4, 3)) |
| 67 | + inner₂ = Ring(cart(2, 5), cart(2, 6), cart(3, 5)) |
| 68 | + poly = PolyArea([outer, inner₁, inner₂]) |
| 69 | + other = PolyArea(Ring(cart(6, 1), cart(7, 2), cart(6, 5), cart(0, 2), cart(1, 1))) |
| 70 | + clipped = clip(poly, other, SutherlandHodgman()) |
| 71 | + crings = rings(clipped) |
| 72 | + @test !issimple(clipped) |
| 73 | + @test length(crings) == 2 |
| 74 | + @test all(vertices(crings[1]) .≈ [cart(6, 4), cart(6, 5), cart(1, 2.5), cart(1, 1), cart(5, 2)]) |
| 75 | + @test all(vertices(crings[2]) .≈ [cart(3.0, 3.0), cart(3.0, 3.5), cart(10 / 3, 11 / 3), cart(4.0, 3.0)]) |
78 | 76 | end |
0 commit comments