forked from go-spatial/tegola
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tile_test.go
149 lines (133 loc) · 3.33 KB
/
tile_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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
package tegola_test
import (
"testing"
"github.com/gdey/tbltest"
"github.com/go-spatial/tegola"
)
func TestTileNum2Deg(t *testing.T) {
testcases := []struct {
tile tegola.Tile
expectedLat float64
expectedLng float64
}{
{
tile: *tegola.NewTile(2, 1, 1),
expectedLat: 66.51326044311185,
expectedLng: -90,
},
}
for i, test := range testcases {
lat, lng := test.tile.Num2Deg()
if lat != test.expectedLat {
t.Errorf("Failed test %v. Expected lat (%v), got (%v)", i, test.expectedLat, lat)
}
if lng != test.expectedLng {
t.Errorf("Failed test %v. Expected lng (%v), got (%v)", i, test.expectedLng, lng)
}
}
}
func TestTileDeg2Num(t *testing.T) {
testcases := []struct {
tile tegola.Tile
expectedX int
expectedY int
}{
{
tile: *tegola.NewTileLatLong(0, -85, -180),
expectedX: 0,
expectedY: 0,
},
}
for i, tc := range testcases {
x, y := tc.tile.Deg2Num()
if tc.expectedX != x {
t.Errorf("testcase (%v) failed. expected X value (%v) does not match output (%v)", i, tc.expectedX, x)
}
if tc.expectedY != y {
t.Errorf("testcase (%v) failed. expected Y value (%v) does not match output (%v)", i, tc.expectedY, y)
}
}
}
func TestTileBBox(t *testing.T) {
testcases := []struct {
tile tegola.Tile
minx, miny, maxx, maxy float64
}{
{
tile: *tegola.NewTile(2, 1, 1),
minx: -10018754.17,
miny: 10018754.17,
maxx: 0,
maxy: 0,
},
{
tile: *tegola.NewTile(16, 11436, 26461),
minx: -13044437.497219238996,
miny: 3856706.6986199953,
maxx: -13043826.000993041,
maxy: 3856095.202393799,
},
}
for i, test := range testcases {
bbox := test.tile.BoundingBox()
if bbox.Minx != test.minx {
t.Errorf("Failed test %v. Expected minx (%v), got (%v)", i, test.minx, bbox.Minx)
}
if bbox.Miny != test.miny {
t.Errorf("Failed test %v. Expected miny (%v), got (%v)", i, test.miny, bbox.Miny)
}
if bbox.Maxx != test.maxx {
t.Errorf("Failed test %v. Expected maxx (%v), got (%v)", i, test.maxx, bbox.Maxx)
}
if bbox.Maxy != test.maxy {
t.Errorf("Failed test %v. Expected maxy (%v), got (%v)", i, test.maxy, bbox.Maxy)
}
}
}
func TestTileZRes(t *testing.T) {
testcases := []struct {
tile tegola.Tile
zres float64
}{
{
tile: *tegola.NewTile(2, 1, 1),
// this is for 4096x4096
zres: 2445.984905125641,
// this is for 256x256
// zres: 39135.75848201026,
},
}
for i, test := range testcases {
zres := test.tile.ZRes()
if zres != test.zres {
t.Errorf("Failed test %v. Expected zres (%v), got (%v)", i, test.zres, zres)
}
}
}
func TestTileToFromPixel(t *testing.T) {
tile := tegola.NewTile(20, 0, 0)
fn := func(idx int, pt [2]float64) {
npt, err := tile.FromPixel(tegola.WebMercator, pt)
if err != nil {
t.Errorf("[%v] Error, Expected nil Got %v", idx, err)
return
}
gpt, err := tile.ToPixel(tegola.WebMercator, npt)
if err != nil {
t.Errorf("[%v] Error, Expected nil Got %v", idx, err)
return
}
// TODO: gdey need to find the utility math function for comparing floats.
if pt[0] != gpt[0] {
t.Errorf("[%v] unequal x value, Expected %v Got %v", idx, pt[0], gpt[0])
}
if pt[1] != gpt[1] {
t.Errorf("[%v] unequal y value, Expected %v Got %v", idx, pt[0], gpt[0])
}
}
tbltest.Cases(
[2]float64{1, 1},
[2]float64{0, 0},
[2]float64{4000, 4000},
).Run(fn)
}