From 829c765d5d62f45f98650fbc42b8db99dec9ad80 Mon Sep 17 00:00:00 2001 From: Erica Fischer Date: Wed, 4 Jan 2023 14:51:20 -0800 Subject: [PATCH] Somewhat less shardy --- geometry.cpp | 8 +++++++- geometry.hpp | 3 ++- tile.cpp | 17 +++++++++++------ 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/geometry.cpp b/geometry.cpp index 623acd30..66445c99 100644 --- a/geometry.cpp +++ b/geometry.cpp @@ -926,7 +926,7 @@ drawvec impose_tile_boundaries(drawvec &geom, long long extent) { return out; } -drawvec simplify_lines(drawvec &geom, int z, int detail, bool mark_tile_bounds, double simplification, size_t retain, drawvec const &shared_nodes) { +drawvec simplify_lines(drawvec &geom, int z, int detail, bool mark_tile_bounds, double simplification, size_t retain, drawvec const &shared_nodes, std::set> &kept) { int res = 1 << (32 - detail - z); long long area = 1LL << (32 - z); @@ -939,6 +939,11 @@ drawvec simplify_lines(drawvec &geom, int z, int detail, bool mark_tile_bounds, geom[i].necessary = 1; } + auto found = kept.find(std::pair((long long) geom[i].x, (long long) geom[i].y)); + if (found != kept.end()) { + geom[i].necessary = 1; + } + if (prevent[P_SIMPLIFY_SHARED_NODES]) { auto pt = std::lower_bound(shared_nodes.begin(), shared_nodes.end(), geom[i]); if (pt != shared_nodes.end() && *pt == geom[i]) { @@ -985,6 +990,7 @@ drawvec simplify_lines(drawvec &geom, int z, int detail, bool mark_tile_bounds, for (size_t i = 0; i < geom.size(); i++) { if (geom[i].necessary) { out.push_back(geom[i]); + kept.insert(std::pair((long long) geom[i].x, (long long) geom[i].y)); } } diff --git a/geometry.hpp b/geometry.hpp index f3dc78d8..ae120f54 100644 --- a/geometry.hpp +++ b/geometry.hpp @@ -2,6 +2,7 @@ #define GEOMETRY_HPP #include +#include #include #include #include @@ -71,7 +72,7 @@ drawvec clip_lines(drawvec &geom, int z, long long buffer); drawvec stairstep(drawvec &geom, int z, int detail); bool point_within_tile(long long x, long long y, int z); int quick_check(long long *bbox, int z, long long buffer); -drawvec simplify_lines(drawvec &geom, int z, int detail, bool mark_tile_bounds, double simplification, size_t retain, drawvec const &shared_nodes); +drawvec simplify_lines(drawvec &geom, int z, int detail, bool mark_tile_bounds, double simplification, size_t retain, drawvec const &shared_nodes, std::set> &kept); drawvec reorder_lines(drawvec &geom); drawvec fix_polygon(drawvec &geom); std::vector chop_polygon(std::vector &geoms); diff --git a/tile.cpp b/tile.cpp index f1a5db62..4a10018d 100644 --- a/tile.cpp +++ b/tile.cpp @@ -517,7 +517,7 @@ drawvec revive_polygon(drawvec &geom, double area, int z, int detail) { } } -double simplify_partial(partial *p, drawvec &shared_nodes) { +double simplify_partial(partial *p, drawvec &shared_nodes, std::set> &kept) { drawvec geom; for (size_t j = 0; j < p->geoms.size(); j++) { @@ -566,7 +566,7 @@ double simplify_partial(partial *p, drawvec &shared_nodes) { } // continues to simplify to line_detail even if we have extra detail - drawvec ngeom = simplify_lines(geom, z, line_detail, !(prevent[P_CLIPPING] || prevent[P_DUPLICATION]), p->simplification, t == VT_POLYGON ? 4 : 0, shared_nodes); + drawvec ngeom = simplify_lines(geom, z, line_detail, !(prevent[P_CLIPPING] || prevent[P_DUPLICATION]), p->simplification, t == VT_POLYGON ? 4 : 0, shared_nodes, kept); if (t != VT_POLYGON || ngeom.size() >= 3) { geom = ngeom; @@ -586,9 +586,10 @@ double simplify_partial(partial *p, drawvec &shared_nodes) { void *partial_feature_worker(void *v) { struct partial_arg *a = (struct partial_arg *) v; std::vector *partials = a->partials; + std::set> kept; for (size_t i = a->task; i < (*partials).size(); i += a->tasks) { - double area = simplify_partial(&((*partials)[i]), *(a->shared_nodes)); + double area = simplify_partial(&((*partials)[i]), *(a->shared_nodes), kept); signed char t = (*partials)[i].t; int z = (*partials)[i].z; @@ -1001,6 +1002,7 @@ bool find_common_edges(std::vector &partials, int z, int line_detail, d // Simplify each arc std::vector simplified_arcs; + std::set> kept; size_t count = 0; for (auto ai = arcs.begin(); ai != arcs.end(); ++ai) { @@ -1017,7 +1019,7 @@ bool find_common_edges(std::vector &partials, int z, int line_detail, d } } if (!(prevent[P_SIMPLIFY] || (z == maxzoom && prevent[P_SIMPLIFY_LOW]) || (z < maxzoom && additional[A_GRID_LOW_ZOOMS]))) { - simplified_arcs[ai->second] = simplify_lines(dv, z, line_detail, !(prevent[P_CLIPPING] || prevent[P_DUPLICATION]), simplification, 4, drawvec()); + simplified_arcs[ai->second] = simplify_lines(dv, z, line_detail, !(prevent[P_CLIPPING] || prevent[P_DUPLICATION]), simplification, 4, drawvec(), kept); } else { simplified_arcs[ai->second] = dv; } @@ -2215,9 +2217,10 @@ long long write_tile(FILE *geoms, std::atomic *geompos_in, char *meta unsimplified_geometry_size += sf.geometry.size() * sizeof(draw); if (unsimplified_geometry_size > 10 * 1024 * 1024 && !additional[A_DETECT_SHARED_BORDERS]) { drawvec dv; + std::set> keptp; for (; simplified_geometry_through < partials.size(); simplified_geometry_through++) { - simplify_partial(&partials[simplified_geometry_through], dv); + simplify_partial(&partials[simplified_geometry_through], dv, keptp); for (auto &g : partials[simplified_geometry_through].geoms) { if (partials[simplified_geometry_through].t == VT_POLYGON) { @@ -2327,6 +2330,7 @@ long long write_tile(FILE *geoms, std::atomic *geompos_in, char *meta if (tasks < 1) { tasks = 1; } + tasks = 1; pthread_t pthreads[tasks]; std::vector args; @@ -2445,12 +2449,13 @@ long long write_tile(FILE *geoms, std::atomic *geompos_in, char *meta layer_features = out; + std::set> keptp; out.clear(); for (size_t x = 0; x < layer_features.size(); x++) { if (layer_features[x].coalesced && layer_features[x].type == VT_LINE) { layer_features[x].geom = remove_noop(layer_features[x].geom, layer_features[x].type, 0); layer_features[x].geom = simplify_lines(layer_features[x].geom, 32, 0, - !(prevent[P_CLIPPING] || prevent[P_DUPLICATION]), simplification, layer_features[x].type == VT_POLYGON ? 4 : 0, shared_nodes); + !(prevent[P_CLIPPING] || prevent[P_DUPLICATION]), simplification, layer_features[x].type == VT_POLYGON ? 4 : 0, shared_nodes, keptp); } if (layer_features[x].type == VT_POLYGON) {