-
Notifications
You must be signed in to change notification settings - Fork 0
/
oblique_test.go
63 lines (53 loc) · 1.56 KB
/
oblique_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
package flatsphere
import (
"math"
"testing"
)
func FuzzObliqueNoOp(f *testing.F) {
obliqEq := NewObliqueProjection(NewPlateCarree(), math.Pi/2, 0, 0)
cassini := NewPlateCarree()
f.Add(0.0, 0.0)
f.Add(math.Pi/4, math.Pi/4)
f.Add(math.Pi/2, 0.0)
f.Add(0.0, math.Pi/2)
f.Fuzz(func(t *testing.T, lat float64, lon float64) {
if math.Abs(lat) > math.Pi/2 {
lat = math.Mod(lat, math.Pi/2)
}
if math.Abs(lon) > math.Pi {
lon = math.Mod(lon, math.Pi)
}
xo, yo := obliqEq.Project(lat, lon)
xc, yc := cassini.Project(lat, lon)
if !withinTolerance(xo, xc, 0.000001) || !withinTolerance(yo, yc, 0.000001) {
t.Errorf("expected %e,%e, but got %e,%e", xc, yc, xo, yo)
}
})
}
func rotatePoint(x, y float64, rad float64) (float64, float64) {
rotX := x*math.Cos(rad) - y*math.Sin(rad)
rotY := x*math.Sin(rad) + y*math.Cos(rad)
return rotX, rotY
}
func FuzzObliquePlateCarreeVsCassiniProject(f *testing.F) {
obliqEq := NewObliqueProjection(NewPlateCarree(), 0, math.Pi/2, -math.Pi/2)
cassini := NewCassini()
f.Add(0.0, 0.0)
f.Add(math.Pi/4, math.Pi/4)
f.Add(math.Pi/2, 0.0)
f.Add(0.0, math.Pi/2)
f.Fuzz(func(t *testing.T, lat float64, lon float64) {
if math.Abs(lat) > math.Pi/2 {
lat = math.Mod(lat, math.Pi/2)
}
if math.Abs(lon) > math.Pi {
lon = math.Mod(lon, math.Pi)
}
xo, yo := obliqEq.Project(lat, lon)
xc, yc := cassini.Project(lat, lon)
xr, yr := rotatePoint(xc, yc, math.Pi/2)
if !withinTolerance(xo, xr, 0.000001) || !withinTolerance(yo, yr, 0.000001) {
t.Errorf("expected %e,%e, but got %e,%e", xr, yr, xo, yo)
}
})
}