github.com/pavlo67/common@v0.5.3/common/geolib/tile_ranges_test.go (about) 1 package geolib 2 3 import ( 4 "math" 5 "testing" 6 7 "github.com/pavlo67/common/common/mathlib/plane" 8 ) 9 10 func TestPointInRanges(t *testing.T) { 11 tests := []struct { 12 name string 13 geoPoint Point 14 moving plane.Point2 15 zoom int 16 tileSide int 17 }{ 18 { 19 name: "", 20 geoPoint: Point{38, 41}, 21 moving: plane.Point2{100, 100}, 22 zoom: 18, 23 tileSide: 256, 24 }, 25 { 26 name: "", 27 geoPoint: Point{38, 41}, 28 moving: plane.Point2{100, -100}, 29 zoom: 18, 30 tileSide: 256, 31 }, 32 { 33 name: "", 34 geoPoint: Point{38, 41}, 35 moving: plane.Point2{500, 500}, 36 zoom: 18, 37 tileSide: 256, 38 }, 39 { 40 name: "", 41 geoPoint: Point{38, 41}, 42 moving: plane.Point2{500, -500}, 43 zoom: 18, 44 tileSide: 256, 45 }, 46 } 47 for _, tt := range tests { 48 t.Run(tt.name, func(t *testing.T) { 49 geoPoint1 := tt.geoPoint.MovedAt(tt.moving) 50 51 xyRanges := XYRangesAround(tt.geoPoint, tt.zoom, tt.moving.X, tt.moving.Y) 52 53 p := PointInRanges(tt.geoPoint, xyRanges, tt.tileSide) 54 p1 := PointInRanges(geoPoint1, xyRanges, tt.tileSide) 55 56 dpm := DPM(tt.geoPoint.Lat, tt.zoom) 57 58 moving1X, moving1Y := float64(p1.X-p.X)/dpm, float64(p.Y-p1.Y)/dpm 59 60 if math.Abs(moving1X-tt.moving.X) > DistanceEps { 61 t.Errorf("moving1X: %f, tt.moving.X: %f", moving1X, tt.moving.X) 62 } 63 if math.Abs(moving1X-tt.moving.X) > DistanceEps { 64 t.Errorf("moving1Y: %f, tt.moving.Y: %f", moving1Y, tt.moving.Y) 65 } 66 67 }) 68 } 69 }