This repository has been archived by the owner on Jul 19, 2021. It is now read-only.
forked from paulmach/orb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
multi_polygon_test.go
109 lines (101 loc) · 2.32 KB
/
multi_polygon_test.go
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
package orb
import (
"testing"
)
func TestMultiPolygon_Bound(t *testing.T) {
// should be union of polygons
mp := MultiPolygon{
{{{0, 0}, {0, 2}, {2, 2}, {2, 0}, {0, 0}}},
{{{1, 1}, {1, 3}, {3, 3}, {3, 1}, {1, 1}}},
}
b := mp.Bound()
if !b.Equal(Bound{Min: Point{0, 0}, Max: Point{3, 3}}) {
t.Errorf("incorrect bound: %v", b)
}
}
func TestMultiPolygon_Equal(t *testing.T) {
cases := []struct {
name string
mp1 MultiPolygon
mp2 MultiPolygon
expected bool
}{
{
name: "same multipolygon",
mp1: MultiPolygon{
{{{0, 0}, {0, 2}, {2, 2}, {2, 0}, {0, 0}}},
{{{1, 1}, {1, 3}, {3, 3}, {3, 1}, {1, 1}}},
},
mp2: MultiPolygon{
{{{0, 0}, {0, 2}, {2, 2}, {2, 0}, {0, 0}}},
{{{1, 1}, {1, 3}, {3, 3}, {3, 1}, {1, 1}}},
},
expected: true,
},
{
name: "different number or rings",
mp1: MultiPolygon{
{{{0, 0}, {0, 2}, {2, 2}, {2, 0}, {0, 0}}},
{{{1, 1}, {1, 3}, {3, 3}, {3, 1}, {1, 1}}},
},
mp2: MultiPolygon{
{{{0, 0}, {0, 2}, {2, 2}, {2, 0}, {0, 0}}},
},
expected: false,
},
{
name: "inner rings are different",
mp1: MultiPolygon{
{{{0, 0}, {0, 2}, {2, 2}, {2, 0}, {0, 0}}},
{{{1, 1}, {1, 3}, {3, 3}, {3, 1}, {1, 1}}},
},
mp2: MultiPolygon{
{{{0, 0}, {0, 2}, {2, 2}, {2, 0}, {0, 0}}},
{{{1, 1}, {1, 2}, {2, 2}, {2, 1}, {1, 1}}},
},
expected: false,
},
}
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
if v := tc.mp1.Equal(tc.mp2); v != tc.expected {
t.Errorf("mp1 != mp2: %v != %v", v, tc.expected)
}
if v := tc.mp2.Equal(tc.mp1); v != tc.expected {
t.Errorf("mp2 != mp1: %v != %v", v, tc.expected)
}
})
}
}
func TestMultiPolygon_Clone(t *testing.T) {
cases := []struct {
name string
mp MultiPolygon
expected MultiPolygon
}{
{
name: "normal multipolygon",
mp: MultiPolygon{
{{{0, 0}, {0, 2}, {2, 2}, {2, 0}, {0, 0}}},
{{{1, 1}, {1, 3}, {3, 3}, {3, 1}, {1, 1}}},
},
expected: MultiPolygon{
{{{0, 0}, {0, 2}, {2, 2}, {2, 0}, {0, 0}}},
{{{1, 1}, {1, 3}, {3, 3}, {3, 1}, {1, 1}}},
},
},
{
name: "nil should return nil",
mp: nil,
expected: nil,
},
}
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
c := tc.mp.Clone()
if !c.Equal(tc.expected) {
t.Errorf("not cloned correctly: %v", c)
}
})
}
}