-
Notifications
You must be signed in to change notification settings - Fork 27
/
planar.jl
119 lines (114 loc) · 5.04 KB
/
planar.jl
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
using Test
using StaticArrays
using Polyhedra
function test_planar_square(VT, d)
ei = ntuple(i -> Polyhedra.basis(VT, d, i), 2)
so = -ei[1] + ei[2]
no = -ei[1] - ei[2]
ne = ei[1] - ei[2]
se = ei[1] + ei[2]
expected = [ne, no, so, se]
for ps in [
[no, so, ne, se],
[no, se, so, ne],
[se, so, no, ne],
expected
]
hull = Polyhedra.planar_hull(vrep(ps))
@test collect(points(hull)) == expected
@test !hasallrays(hull)
v = vrep(ps) + conichull(se)
hull = Polyhedra.planar_hull(v)
@test collect(points(hull)) == [ne, no, so]
@test collect(rays(hull)) == [Ray(se)]
@test !haslines(hull)
v = vrep(ps) + conichull(se, se)
hull = Polyhedra.planar_hull(v)
@test collect(points(hull)) == [ne, no, so]
@test collect(rays(hull)) == [Ray(se)]
@test !haslines(hull)
ne = ei[1] - ei[2]
for v in [vrep(ps) + conichull(se, ne),
vrep(ps) + conichull(se, ne, ei[1])]
hull = Polyhedra.planar_hull(v)
@test collect(points(hull)) == [no, so]
@test collect(rays(hull)) == [Ray(ne), Ray(se)]
@test !haslines(hull)
end
v = vrep(ps) + conichull(se, ne, -se)
hull = Polyhedra.planar_hull(v)
@test collect(points(hull)) == [ne]
@test collect(rays(hull)) == [Ray(ne)]
@test collect(lines(hull)) == [Line(se)]
for v in [vrep(ps) + conichull(se, ne, -ne),
vrep(ps) + conichull(se, Line(ne)),
vrep(ps) + conichull(ne, se, -ne)]
hull = Polyhedra.planar_hull(v)
@test collect(points(hull)) == [no]
@test collect(rays(hull)) == [Ray(se)]
@test collect(lines(hull)) == [Line(ne)]
end
for v in [vrep(ps) + conichull(se, ne, -ne, -se),
vrep(ps) + conichull(se, ne, -ei[1])]
hull = Polyhedra.planar_hull(v)
@test collect(points(hull)) == [no]
@test !hasrays(hull)
@test collect(lines(hull)) == [Line(ne), Line(se)]
end
end
end
# Square + redundant points + [+-1.5, -+0.25]
function test_planar_square_with_more()
expected = [[1.0, -1.0], [-1.0, -1.0], [-1.0, 1.0], [1.0, 1.0]]
v0 = convexhull([-1.0, -1.0], [1.0, -1.0], [-1.0, 1.0], [1.0, 1.0], [0.0, 1.0])
v1 = Polyhedra.planar_hull(v0)
@test collect(points(v1)) == expected
v0 = convexhull([-1.0, -1.0], [1.0, -1.0], [-1.0, 1.0], [1.0, 1.0], [0.0, 1.0 + 1e-10])
v1 = Polyhedra.planar_hull(v0)
@test collect(points(v1)) == expected
v0 = convexhull([0.0, 1.0 + 1e-10], [-1.0, -1.0], [1.0, -1.0], [-1.0, 1.0], [1.0, 1.0])
v1 = Polyhedra.planar_hull(v0)
@test collect(points(v1)) == expected
expected = [[1.0, -1.0], [-1.0, -1.0], [-1.0, 1.0], [0.0, 1.0 + 1e-4], [1.0, 1.0]]
v0 = convexhull([-1.0, -1.0], [1.0, -1.0], [-1.0, 1.0], [1.0, 1.0], [0.0, 1.0 + 1e-4])
v1 = Polyhedra.planar_hull(v0)
@test collect(points(v1)) == expected
expected = [[1.0, -1.0], [-1.0, -1.0], [-1.5, 0.25], [-1.0, 1.0], [1.0, 1.0], [1.5, -0.25]]
v0 = convexhull([-1.0, -1.0], [1.0, -1.0], [-1.0, 1.0], [1.0, 1.0], [0.0, 1.0], [-1.5, 0.25], [1.5, -0.25])
v1 = Polyhedra.planar_hull(v0)
@test collect(points(v1)) == expected
v0 = convexhull([-1.0, -1.0], [1.0, -1.0], [-1.0, 1.0], [1.0, 1.0], [0.0, 1.0], [-0.5, -1.0], [-1.5, 0.25], [0.0, -0.75], [0.0, 0.75], [1.5, -0.25])
v1 = Polyhedra.planar_hull(v0)
@test collect(points(v1)) == expected
v0 = convexhull([-1.0, -1.0], [1.0, -1.0], [-1.0, 1.0], [1.0, 1.0], [0.0, -1.0], [0.0, 1.0], [-0.5, -1.0], [-1.5, 0.25], [0.0, -0.75], [0.0, 0.75], [1.5, -0.25])
v1 = Polyhedra.planar_hull(v0)
@test collect(points(v1)) == expected
v0 = convexhull([-1.0, -1.0], [1.0, -1.0], [-1.0, 1.0], [1.0, 1.0], [0.5, 1.0], [0.0, -1.0], [0.0, 1.0], [-0.5, -1.0], [-1.5, 0.25], [0.0, -0.75], [0.0, 0.75], [1.5, -0.25])
v1 = Polyhedra.planar_hull(v0)
@test collect(points(v1)) == expected
end
function test_issue_271()
expected = [[1.0, 0.0], [-0.5, 0.0], [0.5, 0.5]]
v = convexhull([0.0, 0.0], [1, 0], [0.5, 0.0], [-0.5, 0.0], [0.5, 0.5])
p = Polyhedra.planar_hull(v)
@test collect(points(p)) == expected
v = convexhull([1, 0], [0.0, 0.0], [0.5, 0.0], [-0.5, 0.0], [0.5, 0.5])
p = Polyhedra.planar_hull(v)
@test collect(points(p)) == expected
expected = [[1.0, 0.0], [-0.5, 0.0], [0.0, 0.5], [1.0, 0.5]]
v = vrep([[1, 0], [0.0, 0.0], [0.5, 0.0], [-0.5, 0.0], [0.5, 0.5], [1.0, 0.5], [0.0, 0.5], [0.2, 0.5]])
p = Polyhedra.planar_hull(v)
@test collect(points(p)) == expected
v = vrep([[1, 0], [0.0, 0.0], [0.5, 0.0], [-0.5, 0.0], [1.0, 0.5], [0.2, 0.5], [0.5, 0.5], [0.0, 0.5]])
p = Polyhedra.planar_hull(v)
@test collect(points(p)) == expected
end
@testset "Planar" begin
for T in [Float64, Int]
for (VT, d) in [(Vector{T}, 2), (SVector{2, T}, StaticArrays.Size(2))]
test_planar_square(VT, d)
end
end
test_planar_square_with_more()
test_issue_271()
end