forked from go-spatial/tegola
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tile_test.go
110 lines (97 loc) · 2.38 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
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 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)
}