Skip to content

Commit

Permalink
Use the_province_points map to get province number from point (#1709)
Browse files Browse the repository at this point in the history
  • Loading branch information
cetvrtak authored Jul 3, 2024
1 parent 1b0c7c4 commit 16cee56
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
9 changes: 5 additions & 4 deletions src/Maps/MapData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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())
{
Expand Down Expand Up @@ -357,12 +356,14 @@ std::optional<Maps::Point> Maps::MapData::GetAnyBorderCenter(const int province)

std::optional<int> 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;
}


Expand Down
1 change: 0 additions & 1 deletion src/Maps/MapData.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ class MapData
std::map<int, ProvincePoints> the_province_points_;

ProvinceDefinitions province_definitions_;
std::map<Point, int> points_to_provinces_;
};

} // namespace Maps
Expand Down
1 change: 1 addition & 0 deletions src/Maps/ProvincePoints.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<Point> thePoints;
Expand Down

0 comments on commit 16cee56

Please sign in to comment.