2019-01-11 18:00:40 +03:00
|
|
|
package coords
|
|
|
|
|
|
|
|
import (
|
2019-01-13 18:37:03 +03:00
|
|
|
"math"
|
2019-01-11 18:00:40 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
type TileCoords struct {
|
2019-01-13 18:37:03 +03:00
|
|
|
X, Y int
|
|
|
|
Zoom int
|
2019-01-11 18:00:40 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
type TileQuadrants struct {
|
2019-01-13 18:37:03 +03:00
|
|
|
UpperLeft, UpperRight, LowerLeft, LowerRight TileCoords
|
2019-01-11 18:00:40 +03:00
|
|
|
}
|
|
|
|
|
2019-01-13 18:37:03 +03:00
|
|
|
func NewTileCoords(x, y, zoom int) TileCoords {
|
|
|
|
return TileCoords{X: x, Y: y, Zoom: zoom}
|
2019-01-11 18:00:40 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func (tc TileCoords) GetZoomedOutTile() TileCoords {
|
2019-01-13 18:37:03 +03:00
|
|
|
return TileCoords{
|
|
|
|
X: int(math.Floor(float64(tc.X) / 2.0)),
|
|
|
|
Y: int(math.Floor(float64(tc.Y) / 2.0)),
|
|
|
|
Zoom: tc.Zoom - 1}
|
2019-01-11 18:00:40 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func (tc TileCoords) GetZoomedQuadrantsFromTile() TileQuadrants {
|
2019-01-13 18:37:03 +03:00
|
|
|
nextZoom := tc.Zoom + 1
|
|
|
|
|
|
|
|
nextZoomX := tc.X * 2
|
|
|
|
nextZoomY := tc.Y * 2
|
|
|
|
|
|
|
|
upperLeft := TileCoords{X: nextZoomX, Y: nextZoomY, Zoom: nextZoom}
|
|
|
|
upperRight := TileCoords{X: nextZoomX + 1, Y: nextZoomY, Zoom: nextZoom}
|
|
|
|
lowerLeft := TileCoords{X: nextZoomX, Y: nextZoomY + 1, Zoom: nextZoom}
|
|
|
|
lowerRight := TileCoords{X: nextZoomX + 1, Y: nextZoomY + 1, Zoom: nextZoom}
|
|
|
|
|
|
|
|
return TileQuadrants{
|
|
|
|
UpperLeft: upperLeft,
|
|
|
|
UpperRight: upperRight,
|
|
|
|
LowerLeft: lowerLeft,
|
|
|
|
LowerRight: lowerRight,
|
|
|
|
}
|
2019-01-11 18:00:40 +03:00
|
|
|
}
|