OpenRoadCode
Public API reference for OpenRoadCode
Loading...
Searching...
No Matches
weather_city_selection.hpp
1// SPDX-FileCopyrightText: 2026 Mark G. Russell
2// SPDX-License-Identifier: MIT
3#pragma once
4
5#include <algorithm>
6#include <cmath>
7#include <string>
8#include <tuple>
9#include <vector>
10
11struct WeatherCityCandidate {
12 std::string name;
13 double latitude;
14 double longitude;
15 double x;
16 double y;
17 double priority;
18};
19
21inline std::vector<WeatherCityCandidate> selectWeatherCities(std::vector<WeatherCityCandidate> candidates) {
22 std::sort(candidates.begin(), candidates.end(), [](const auto& a, const auto& b) {
23 return std::tie(a.priority, a.name, a.latitude, a.longitude) <
24 std::tie(b.priority, b.name, b.latitude, b.longitude);
25 });
26 std::vector<WeatherCityCandidate> selected;
27 for (const auto& candidate : candidates) {
28 if (std::any_of(selected.begin(), selected.end(), [&candidate](const auto& other) {
29 return (std::abs(candidate.x - other.x) < 150 && std::abs(candidate.y - other.y) < 70) ||
30 (candidate.name == other.name &&
31 std::abs(candidate.latitude - other.latitude) < 0.001 &&
32 std::abs(candidate.longitude - other.longitude) < 0.001);
33 })) continue;
34 selected.push_back(candidate);
35 if (selected.size() == 12) break;
36 }
37 return selected;
38}