2019-01-20 22:10:48 +03:00
|
|
|
package coords
|
|
|
|
|
|
|
|
import (
|
2023-12-29 18:00:11 +03:00
|
|
|
"mapserver/types"
|
2019-01-21 15:45:35 +03:00
|
|
|
"testing"
|
2023-12-29 18:00:11 +03:00
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
2019-01-20 22:10:48 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestConvertMapblockToTile1(t *testing.T) {
|
2023-12-29 18:00:11 +03:00
|
|
|
mbc := types.NewMapBlockCoords(0, 0, 0)
|
|
|
|
layers := []*types.Layer{
|
|
|
|
{
|
2019-01-21 15:27:36 +03:00
|
|
|
Id: 0,
|
|
|
|
Name: "Base",
|
|
|
|
From: -16,
|
|
|
|
To: 160,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
tc := GetTileCoordsFromMapBlock(mbc, layers)
|
2019-01-20 22:10:48 +03:00
|
|
|
|
|
|
|
if tc.X != 0 {
|
|
|
|
t.Fatal("x does not match")
|
|
|
|
}
|
|
|
|
|
|
|
|
if tc.Y != -1 {
|
|
|
|
t.Fatal("y does not match")
|
|
|
|
}
|
|
|
|
|
|
|
|
if tc.Zoom != 13 {
|
|
|
|
t.Fatal("zoom does not match")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestGetMapBlockRangeFromTile(t *testing.T) {
|
|
|
|
r := GetMapBlockRangeFromTile(NewTileCoords(0, 0, 13, 0), 0)
|
|
|
|
assert.Equal(t, r.Pos1.X, 0)
|
|
|
|
assert.Equal(t, r.Pos1.Z, -1)
|
|
|
|
assert.Equal(t, r.Pos2.X, 0)
|
|
|
|
assert.Equal(t, r.Pos2.Z, -1)
|
|
|
|
|
|
|
|
r = GetMapBlockRangeFromTile(NewTileCoords(-1, -1, 13, 0), 0)
|
|
|
|
assert.Equal(t, r.Pos1.X, -1)
|
|
|
|
assert.Equal(t, r.Pos1.Z, 0)
|
|
|
|
assert.Equal(t, r.Pos2.X, -1)
|
|
|
|
assert.Equal(t, r.Pos2.Z, 0)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestConvertMapblockToTile2(t *testing.T) {
|
2023-12-29 18:00:11 +03:00
|
|
|
mbc := types.NewMapBlockCoords(1, 0, 1)
|
|
|
|
layers := []*types.Layer{
|
|
|
|
{
|
2019-01-21 15:27:36 +03:00
|
|
|
Id: 0,
|
|
|
|
Name: "Base",
|
|
|
|
From: -16,
|
|
|
|
To: 160,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
tc := GetTileCoordsFromMapBlock(mbc, layers)
|
2019-01-20 22:10:48 +03:00
|
|
|
|
|
|
|
if tc.X != 1 {
|
|
|
|
t.Fatal("x does not match")
|
|
|
|
}
|
|
|
|
|
|
|
|
if tc.Y != -2 {
|
|
|
|
t.Fatal("y does not match")
|
|
|
|
}
|
|
|
|
|
|
|
|
if tc.Zoom != 13 {
|
|
|
|
t.Fatal("zoom does not match")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestConvertMapblockToTile3(t *testing.T) {
|
2023-12-29 18:00:11 +03:00
|
|
|
mbc := types.NewMapBlockCoords(-1, 0, -1)
|
|
|
|
layers := []*types.Layer{
|
|
|
|
{
|
2019-01-21 15:27:36 +03:00
|
|
|
Id: 0,
|
|
|
|
Name: "Base",
|
|
|
|
From: -16,
|
|
|
|
To: 160,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
tc := GetTileCoordsFromMapBlock(mbc, layers)
|
2019-01-20 22:10:48 +03:00
|
|
|
|
|
|
|
if tc.X != -1 {
|
|
|
|
t.Fatal("x does not match")
|
|
|
|
}
|
|
|
|
|
|
|
|
if tc.Y != 0 {
|
|
|
|
t.Fatal("y does not match")
|
|
|
|
}
|
|
|
|
|
|
|
|
if tc.Zoom != 13 {
|
|
|
|
t.Fatal("zoom does not match")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestZoomedQuadrantsFromTile(t *testing.T) {
|
|
|
|
tc := NewTileCoords(0, 0, 12, 0)
|
|
|
|
q := tc.GetZoomedQuadrantsFromTile()
|
|
|
|
|
|
|
|
assert.Equal(t, q.UpperLeft.X, 0)
|
|
|
|
assert.Equal(t, q.UpperLeft.Y, 0)
|
|
|
|
assert.Equal(t, q.UpperLeft.Zoom, 13)
|
|
|
|
|
|
|
|
assert.Equal(t, q.UpperRight.X, 1)
|
|
|
|
assert.Equal(t, q.UpperRight.Y, 0)
|
|
|
|
assert.Equal(t, q.UpperRight.Zoom, 13)
|
|
|
|
|
|
|
|
assert.Equal(t, q.LowerLeft.X, 0)
|
|
|
|
assert.Equal(t, q.LowerLeft.Y, 1)
|
|
|
|
assert.Equal(t, q.LowerLeft.Zoom, 13)
|
|
|
|
|
|
|
|
assert.Equal(t, q.LowerRight.X, 1)
|
|
|
|
assert.Equal(t, q.LowerRight.Y, 1)
|
|
|
|
assert.Equal(t, q.LowerRight.Zoom, 13)
|
|
|
|
|
|
|
|
}
|
2019-01-25 10:15:34 +03:00
|
|
|
|
|
|
|
func TestZoomedOutTile(t *testing.T) {
|
|
|
|
tc := NewTileCoords(0, 0, 12, 0)
|
|
|
|
nt := tc.GetZoomedOutTile()
|
|
|
|
assert.Equal(t, nt.X, 0)
|
|
|
|
assert.Equal(t, nt.X, 0)
|
|
|
|
assert.Equal(t, nt.Zoom, 11)
|
|
|
|
|
|
|
|
tc = NewTileCoords(1, 0, 12, 0)
|
|
|
|
nt = tc.GetZoomedOutTile()
|
|
|
|
assert.Equal(t, nt.X, 0)
|
|
|
|
assert.Equal(t, nt.X, 0)
|
|
|
|
assert.Equal(t, nt.Zoom, 11)
|
|
|
|
|
|
|
|
tc = NewTileCoords(0, 1, 12, 0)
|
|
|
|
nt = tc.GetZoomedOutTile()
|
|
|
|
assert.Equal(t, nt.X, 0)
|
|
|
|
assert.Equal(t, nt.X, 0)
|
|
|
|
assert.Equal(t, nt.Zoom, 11)
|
|
|
|
|
|
|
|
tc = NewTileCoords(1, 1, 12, 0)
|
|
|
|
nt = tc.GetZoomedOutTile()
|
|
|
|
assert.Equal(t, nt.X, 0)
|
|
|
|
assert.Equal(t, nt.X, 0)
|
|
|
|
assert.Equal(t, nt.Zoom, 11)
|
|
|
|
|
|
|
|
tc = NewTileCoords(2, 2, 12, 0)
|
|
|
|
nt = tc.GetZoomedOutTile()
|
|
|
|
assert.Equal(t, nt.X, 1)
|
|
|
|
assert.Equal(t, nt.X, 1)
|
|
|
|
assert.Equal(t, nt.Zoom, 11)
|
|
|
|
|
|
|
|
tc = NewTileCoords(3, 3, 12, 0)
|
|
|
|
nt = tc.GetZoomedOutTile()
|
|
|
|
assert.Equal(t, nt.X, 1)
|
|
|
|
assert.Equal(t, nt.X, 1)
|
|
|
|
assert.Equal(t, nt.Zoom, 11)
|
|
|
|
|
|
|
|
tc = NewTileCoords(4, 4, 12, 0)
|
|
|
|
nt = tc.GetZoomedOutTile()
|
|
|
|
assert.Equal(t, nt.X, 2)
|
|
|
|
assert.Equal(t, nt.X, 2)
|
|
|
|
assert.Equal(t, nt.Zoom, 11)
|
|
|
|
|
|
|
|
}
|