From e493c8500735c785a3d8da6c7bdfbbd9366c6dbc Mon Sep 17 00:00:00 2001 From: nihalzp <81457724+nihalzp@users.noreply.github.com> Date: Mon, 18 Nov 2024 04:04:21 +0800 Subject: [PATCH] Calculate inset area on transformed original coordinates --- include/inset_state.hpp | 2 +- src/inset_state/inset_state.cpp | 5 +++-- src/inset_state/rescale_map.cpp | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/include/inset_state.hpp b/include/inset_state.hpp index 07502771..86f1f8c9 100644 --- a/include/inset_state.hpp +++ b/include/inset_state.hpp @@ -240,7 +240,7 @@ class InsetState void store_original_geo_divs(); double target_area_at(const std::string &) const; bool target_area_is_missing(const std::string &) const; - double total_inset_area() const; + double total_inset_area(bool = false) const; double total_target_area() const; Polygon transform_to_equal_area_projection_coor(Polygon edge_points); std::array transformed_triangle( diff --git a/src/inset_state/inset_state.cpp b/src/inset_state/inset_state.cpp index 7dc05a6c..0252f38b 100644 --- a/src/inset_state/inset_state.cpp +++ b/src/inset_state/inset_state.cpp @@ -895,10 +895,11 @@ double InsetState::target_area_at(const std::string &id) const } } -double InsetState::total_inset_area() const +double InsetState::total_inset_area(bool original_area) const { + auto &geo_divs = original_area ? geo_divs_original_transformed_ : geo_divs_; double total_inset_area = 0.0; - for (const auto &gd : geo_divs_) { + for (const auto &gd : geo_divs) { total_inset_area += gd.area(); } return total_inset_area; diff --git a/src/inset_state/rescale_map.cpp b/src/inset_state/rescale_map.cpp index b0cf5ac2..9c342356 100644 --- a/src/inset_state/rescale_map.cpp +++ b/src/inset_state/rescale_map.cpp @@ -94,7 +94,7 @@ void InsetState::normalize_inset_area( const double inset_area_prop = initial_target_area() / total_cart_target_area; const double scale_factor = - equal_area ? 1.0 : sqrt(inset_area_prop / total_inset_area()); + equal_area ? 1.0 : sqrt(inset_area_prop / total_inset_area(normalize_original)); // Rescale and translate all GeoDiv coordinates const Transformation translate(