-
-
Notifications
You must be signed in to change notification settings - Fork 36
/
centroid_test.go
127 lines (104 loc) · 4.12 KB
/
centroid_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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
package main
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestComputeCentroidWithEntranceNode(t *testing.T) {
var latlons = []map[string]string{
map[string]string{"lat": "1", "lon": "2", "entrance": "1"},
}
var centroid, bounds = computeCentroidAndBounds(latlons)
assert.Equal(t, "1", centroid["lat"])
assert.Equal(t, "2", centroid["lon"])
assert.Equal(t, +1.0, bounds.North())
assert.Equal(t, +1.0, bounds.South())
assert.Equal(t, +2.0, bounds.East())
assert.Equal(t, +2.0, bounds.West())
}
func TestComputeCentroidWithMainEntranceNode(t *testing.T) {
var latlons = []map[string]string{
map[string]string{"lat": "0", "lon": "0", "entrance": "1"},
map[string]string{"lat": "1", "lon": "2", "entrance": "2"},
map[string]string{"lat": "-1", "lon": "-2", "entrance": "1", "wheelchair": "2"},
}
var centroid, bounds = computeCentroidAndBounds(latlons)
assert.Equal(t, "1", centroid["lat"])
assert.Equal(t, "2", centroid["lon"])
assert.Equal(t, +1.0, bounds.North())
assert.Equal(t, -1.0, bounds.South())
assert.Equal(t, +2.0, bounds.East())
assert.Equal(t, -2.0, bounds.West())
}
func TestComputeCentroidWithAccessibleEntranceNode(t *testing.T) {
var latlons = []map[string]string{
map[string]string{"lat": "0", "lon": "0", "entrance": "1"},
map[string]string{"lat": "-1", "lon": "-2", "entrance": "1", "wheelchair": "2"},
}
var centroid, bounds = computeCentroidAndBounds(latlons)
assert.Equal(t, "-1", centroid["lat"])
assert.Equal(t, "-2", centroid["lon"])
assert.Equal(t, +0.0, bounds.North())
assert.Equal(t, -1.0, bounds.South())
assert.Equal(t, +0.0, bounds.East())
assert.Equal(t, -2.0, bounds.West())
}
func TestComputeCentroidWithRegularEntranceNode(t *testing.T) {
var latlons = []map[string]string{
map[string]string{"lat": "0", "lon": "0", "entrance": "1"},
}
var centroid, bounds = computeCentroidAndBounds(latlons)
assert.Equal(t, "0", centroid["lat"])
assert.Equal(t, "0", centroid["lon"])
assert.Equal(t, +0.0, bounds.North())
assert.Equal(t, +0.0, bounds.South())
assert.Equal(t, +0.0, bounds.East())
assert.Equal(t, +0.0, bounds.West())
}
func TestComputeCentroidForClosedPolygon(t *testing.T) {
var latlons = []map[string]string{
map[string]string{"lat": "1", "lon": "1"},
map[string]string{"lat": "-1", "lon": "1"},
map[string]string{"lat": "-1", "lon": "-1"},
map[string]string{"lat": "1", "lon": "-1"},
map[string]string{"lat": "1", "lon": "1"},
}
var centroid, bounds = computeCentroidAndBounds(latlons)
assert.Equal(t, "0.0000000", centroid["lat"])
assert.Equal(t, "0.0000000", centroid["lon"])
assert.Equal(t, +1.0, bounds.North())
assert.Equal(t, -1.0, bounds.South())
assert.Equal(t, +1.0, bounds.East())
assert.Equal(t, -1.0, bounds.West())
}
func TestComputeCentroidForHillboroPublicLibrary(t *testing.T) {
var latlons = []map[string]string{
map[string]string{"lat": "45.5424694", "lon": "-122.9356798"},
map[string]string{"lat": "45.5424261", "lon": "-122.9361523"},
map[string]string{"lat": "45.5432827", "lon": "-122.9363111"},
map[string]string{"lat": "45.5433259", "lon": "-122.9358387"},
map[string]string{"lat": "45.5430581", "lon": "-122.9357890"},
map[string]string{"lat": "45.5429060", "lon": "-122.9357608"},
map[string]string{"lat": "45.5424694", "lon": "-122.9356798"},
}
var centroid, bounds = computeCentroidAndBounds(latlons)
assert.Equal(t, "45.5428760", centroid["lat"])
assert.Equal(t, "-122.9359955", centroid["lon"])
assert.Equal(t, +45.5433259, bounds.North())
assert.Equal(t, +45.5424261, bounds.South())
assert.Equal(t, -122.9356798, bounds.East())
assert.Equal(t, -122.9363111, bounds.West())
}
func TestComputeCentroidForOpenLineString(t *testing.T) {
var latlons = []map[string]string{
map[string]string{"lat": "1", "lon": "1"},
map[string]string{"lat": "0", "lon": "0"},
map[string]string{"lat": "-1", "lon": "-1"},
}
var centroid, bounds = computeCentroidAndBounds(latlons)
assert.Equal(t, "0.0000000", centroid["lat"])
assert.Equal(t, "0.0000000", centroid["lon"])
assert.Equal(t, +1.0, bounds.North())
assert.Equal(t, -1.0, bounds.South())
assert.Equal(t, +1.0, bounds.East())
assert.Equal(t, -1.0, bounds.West())
}