From 16cee56e3f6715a5032e3d2aaf8cb8fe2216aa76 Mon Sep 17 00:00:00 2001 From: cetvrtak <59363714+cetvrtak@users.noreply.github.com> Date: Wed, 3 Jul 2024 05:45:08 +0200 Subject: [PATCH] Use the_province_points map to get province number from point (#1709) --- src/Maps/MapData.cpp | 9 +++++---- src/Maps/MapData.h | 1 - src/Maps/ProvincePoints.h | 1 + 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/Maps/MapData.cpp b/src/Maps/MapData.cpp index 7534971e62..af4a8a2e9f 100644 --- a/src/Maps/MapData.cpp +++ b/src/Maps/MapData.cpp @@ -156,7 +156,6 @@ void Maps::MapData::ImportProvinces(const std::string& path) if (auto province = province_definitions_.getProvinceFromColor(center_color); province) { - points_to_provinces_.emplace(position, *province); if (auto specific_province_points = the_province_points_.find(*province); specific_province_points != the_province_points_.end()) { @@ -357,12 +356,14 @@ std::optional Maps::MapData::GetAnyBorderCenter(const int province) std::optional Maps::MapData::GetProvinceNumber(const Point& point) const { - const auto i = points_to_provinces_.find(point); - if (i == points_to_provinces_.end()) + const auto i = std::find_if(the_province_points_.begin(), the_province_points_.end(), [point](const auto& province) { + return province.second.hasPoint(point); + }); + if (i == the_province_points_.end()) { return std::nullopt; } - return i->second; + return i->first; } diff --git a/src/Maps/MapData.h b/src/Maps/MapData.h index 4e40df4a01..ff8295c654 100644 --- a/src/Maps/MapData.h +++ b/src/Maps/MapData.h @@ -51,7 +51,6 @@ class MapData std::map the_province_points_; ProvinceDefinitions province_definitions_; - std::map points_to_provinces_; }; } // namespace Maps diff --git a/src/Maps/ProvincePoints.h b/src/Maps/ProvincePoints.h index d22ed0abc1..240ec5aab7 100644 --- a/src/Maps/ProvincePoints.h +++ b/src/Maps/ProvincePoints.h @@ -19,6 +19,7 @@ class ProvincePoints void addPoint(const Point& thePoint); [[nodiscard]] Point getCentermostPoint() const; + [[nodiscard]] bool hasPoint(const Point& thePoint) const { return thePoints.contains(thePoint); } private: std::set thePoints;