mirror of https://github.com/tidwall/tile38.git
Merge branch 'master' into memoptz
This commit is contained in:
commit
e286663e23
index
|
@ -1,13 +1,16 @@
|
||||||
package index
|
package index
|
||||||
|
|
||||||
|
import "math"
|
||||||
|
|
||||||
// normPoint takes the latitude and longitude of one point and return the x,y position on a world map.
|
// normPoint takes the latitude and longitude of one point and return the x,y position on a world map.
|
||||||
// The map bounds are minimum -180,-90 and maximum 180,90. These values are x,y; not lat,lon.
|
// The map bounds are minimum -180,-90 and maximum 180,90. These values are x,y; not lat,lon.
|
||||||
func normPoint(lat, lon float64) (x float64, y float64, normd bool) {
|
func normPoint(lat, lon float64) (x, y float64, normd bool) {
|
||||||
// Check if the rect is completely in bounds. This is likely to be the vast majority of cases.
|
// Check if the rect is completely in bounds.
|
||||||
|
// This is likely to be the vast majority of cases.
|
||||||
if lon >= -180 && lon <= 180 && lat >= -90 && lat <= 90 {
|
if lon >= -180 && lon <= 180 && lat >= -90 && lat <= 90 {
|
||||||
return lon, lat, false
|
return lon, lat, false
|
||||||
}
|
}
|
||||||
// TODO: replace loops with math/mod.
|
lat = math.Mod(lat, 360)
|
||||||
for lat < -90 || lat > 90 {
|
for lat < -90 || lat > 90 {
|
||||||
if lat < -90 {
|
if lat < -90 {
|
||||||
lat = -90 - (90 + lat)
|
lat = -90 - (90 + lat)
|
||||||
|
@ -18,6 +21,7 @@ func normPoint(lat, lon float64) (x float64, y float64, normd bool) {
|
||||||
lon = 180 + lon
|
lon = 180 + lon
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
lon = math.Mod(lon, 360)
|
||||||
for lon < -180 {
|
for lon < -180 {
|
||||||
lon += 360
|
lon += 360
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue