40 template <
typename NumericType =
int>
51 template <
typename NumericType =
int>
56 throw std::invalid_argument(
"Zoom level " + std::to_string(zoom) +
" too high");
58 else if (coord.
lat < -85.0511 || coord.
lat > 85.0511)
60 throw std::invalid_argument(
"Latitude " + std::to_string(coord.
lat) +
" invalid");
62 else if (coord.
lon < -180 || coord.
lon > 180)
64 throw std::invalid_argument(
"Longitude " + std::to_string(coord.
lon) +
" invalid");
67 double constexpr rho = M_PI / 180;
68 double const lat_rad = coord.
lat * rho;
71 int const n = 1 << zoom;
72 ret.
x = n * ((coord.
lon + 180) / 360.0);
73 ret.
y = n * (1 - (std::log(std::tan(lat_rad) + 1 / std::cos(lat_rad)) / M_PI)) / 2;
82 template <
typename NumericType =
int>
86 ret.
lon = coord.
x / std::pow(2.0, zoom) * 360.0 - 180;
87 double n = M_PI - 2.0 * M_PI * (1 + coord.
y) / std::pow(2.0, zoom);
88 ret.lat = 180.0 / M_PI * std::atan(0.5 * (std::exp(n) - std::exp(-n)));
92 template <
typename NumericType>
95 return std::tie(
self.x,
self.y) == std::tie(other.
x, other.
y);
97 template <
typename NumericType>
100 return std::tie(
self.x,
self.y) >= std::tie(other.
x, other.
y);
102 template <
typename NumericType>
105 return std::tie(
self.x,
self.y) <= std::tie(other.x, other.y);
TileCoordinateGeneric< NumericType > fromWGSCoordinate(WGSCoordinate coord, int zoom)
bool operator>=(TileCoordinateGeneric< NumericType > self, TileCoordinateGeneric< NumericType > other)
static constexpr int MAX_ZOOM
Max zoom level to support.
WGSCoordinate toWGSCoordinate(TileCoordinateGeneric< NumericType > coord, int zoom)
bool operator==(TileCoordinateGeneric< NumericType > self, TileCoordinateGeneric< NumericType > other)