From e4f31182d78c58b7ca4aa720d07cb748cdcfe8a1 Mon Sep 17 00:00:00 2001 From: Ben Lubar Date: Sun, 18 Mar 2018 20:47:54 -0500 Subject: [PATCH] Fix site maps being incorrectly scaled. Optimize SVGs to combine columns that are the same height. --- helpers.cpp | 12 +++++++++--- helpers.h | 2 +- render_site.cpp | 2 +- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/helpers.cpp b/helpers.cpp index 27f93c1..57ff3b5 100644 --- a/helpers.cpp +++ b/helpers.cpp @@ -1229,18 +1229,24 @@ void born_died(std::ostream & s, df::historical_figure *hf) s << ")"; } -void render_map_coords(std::ostream &s, const df::coord2d_path &coords) +void render_map_coords(std::ostream &s, const df::coord2d_path &coords, int32_t mul) { - s << "world_data->world_width << " " << world->world_data->world_height << "\">"; + s << "world_data->world_width * mul) << " " << (world->world_data->world_height * mul) << "\">"; for (size_t i = 0; i < coords.size(); i++) { + int width = 1; int height = 1; while (i + 1 < coords.size() && coords.x.at(i) == coords.x.at(i + 1) && coords.y.at(i) + 1 == coords.y.at(i + 1)) { height++; i++; } - s << ""; + while (i + height < coords.size() && coords.x.at(i) + 1 == coords.x.at(i + height) && coords.y.at(i) == coords.y.at(i + height)) + { + width++; + i += height; + } + s << ""; } s << ""; } diff --git a/helpers.h b/helpers.h index ad549c0..fb64659 100644 --- a/helpers.h +++ b/helpers.h @@ -134,7 +134,7 @@ void spheres(std::ostream & s, df::historical_figure *hf); void year(std::ostream & s, int32_t year, int32_t tick); void born_died(std::ostream & s, df::historical_figure *hf); -void render_map_coords(std::ostream &s, const df::coord2d_path &coords); +void render_map_coords(std::ostream &s, const df::coord2d_path &coords, int32_t mul = 1); // https://stackoverflow.com/a/24315631/2664560 static inline void replace_all(std::string & str, const std::string & from, const std::string & to) diff --git a/render_site.cpp b/render_site.cpp index cb8930a..319aaac 100644 --- a/render_site.cpp +++ b/render_site.cpp @@ -29,7 +29,7 @@ bool WebLegends::render_site(std::ostream & s, int32_t id, int32_t page) coords.push_back(df::coord2d(uint16_t(x), uint16_t(y))); } } - render_map_coords(s, coords); + render_map_coords(s, coords, 16); s << "

"; categorize(s, site);