File indexing completed on 2025-02-16 04:48:29
0001 /* 0002 SPDX-FileCopyrightText: 2018 Volker Krause <vkrause@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #ifndef WEATHERTILE_H 0008 #define WEATHERTILE_H 0009 0010 #include <QMetaType> 0011 0012 #include <cmath> 0013 #include <cstdint> 0014 #include <functional> 0015 0016 /** Weather forecast data tile coordinates */ 0017 struct WeatherTile 0018 { 0019 // tile size in 1/nth of a degree 0020 static const constexpr auto Size = 10.0; 0021 0022 inline constexpr WeatherTile() = default; 0023 inline WeatherTile(float latitude, float longitude) 0024 : lat(int16_t(::round(latitude * WeatherTile::Size))) 0025 , lon(int16_t(::round(longitude * WeatherTile::Size))) 0026 {} 0027 0028 inline bool operator<(WeatherTile other) const 0029 { 0030 return std::tie(lat, lon) < std::tie(other.lat, other.lon); 0031 } 0032 0033 inline constexpr bool operator==(WeatherTile other) const 0034 { 0035 return lat == other.lat && lon == other.lon; 0036 } 0037 0038 inline constexpr float latitude() const 0039 { 0040 return lat / Size; 0041 } 0042 0043 inline constexpr float longitude() const 0044 { 0045 return lon / Size; 0046 } 0047 0048 int16_t lat = 0; 0049 int16_t lon = 0; 0050 }; 0051 0052 Q_DECLARE_METATYPE(WeatherTile) 0053 0054 namespace std 0055 { 0056 template<> struct hash<WeatherTile> 0057 { 0058 inline std::size_t operator()(const WeatherTile &t) const noexcept 0059 { 0060 return std::hash<uint32_t>{}(t.lat << 16 | t.lon); 0061 } 0062 }; 0063 } 0064 0065 #endif // WEATHERTILE_H 0066