aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/github.com/paulmach/orb/project/projections_test.go
blob: 947355ac7b93fc95721c99f6ba06b3200bb63473 (plain) (blame)
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
package project

import (
	"math"
	"testing"

	"github.com/paulmach/orb"
	"github.com/paulmach/orb/internal/mercator"
)

func TestMercator(t *testing.T) {
	for _, city := range mercator.Cities {
		g := orb.Point{
			city[1],
			city[0],
		}

		p := WGS84.ToMercator(g)
		g = Mercator.ToWGS84(p)

		if math.Abs(g[1]-city[0]) > mercator.Epsilon {
			t.Errorf("latitude miss match: %f != %f", g[1], city[0])
		}

		if math.Abs(g[0]-city[1]) > mercator.Epsilon {
			t.Errorf("longitude miss match: %f != %f", g[0], city[1])
		}
	}
}

func TestMercatorScaleFactor(t *testing.T) {
	cases := []struct {
		name   string
		point  orb.Point
		factor float64
	}{
		{
			name:   "30 deg",
			point:  orb.Point{0, 30.0},
			factor: 1.154701,
		},
		{
			name:   "45 deg",
			point:  orb.Point{0, 45.0},
			factor: 1.414214,
		},
		{
			name:   "60 deg",
			point:  orb.Point{0, 60.0},
			factor: 2,
		},
		{
			name:   "80 deg",
			point:  orb.Point{0, 80.0},
			factor: 5.758770,
		},
	}

	for _, tc := range cases {
		t.Run(tc.name, func(t *testing.T) {
			if f := MercatorScaleFactor(tc.point); math.Abs(tc.factor-f) > mercator.Epsilon {
				t.Errorf("incorrect factor: %v != %v", f, tc.factor)
			}
		})
	}
}