diff --git a/geometry.cpp b/geometry.cpp index b5c1836c..280182b1 100644 --- a/geometry.cpp +++ b/geometry.cpp @@ -832,7 +832,7 @@ static double square_distance_from_line(long long point_x, long long point_y, lo } // https://github.com/Project-OSRM/osrm-backend/blob/733d1384a40f/Algorithms/DouglasePeucker.cpp -static void douglas_peucker(drawvec &geom, int start, int n, double e, size_t kept, size_t retain) { +static void douglas_peucker(drawvec &geom, int start, int n, double e, size_t kept, size_t retain, double res) { e = e * e; std::stack recursion_stack; @@ -875,7 +875,10 @@ static void douglas_peucker(drawvec &geom, int start, int n, double e, size_t ke if (max_distance >= 0) { // mark idx as necessary - geom[start + farthest_element_index].necessary = 1; + size_t k = start + farthest_element_index; + geom[k].necessary = 1; + geom[k].x = res * std::round((double) geom[k].x / res); + geom[k].y = res * std::round((double) geom[k].y / res); kept++; if (1 < farthest_element_index - first) { @@ -961,6 +964,13 @@ drawvec simplify_lines(drawvec &geom, int z, int detail, bool mark_tile_bounds, geom[i].necessary = 1; geom[j - 1].necessary = 1; + for (size_t k = i; k < j; k++) { + if (geom[k].necessary) { + geom[k].x = res * std::round((double) geom[k].x / res); + geom[k].y = res * std::round((double) geom[k].y / res); + } + } + // empirical mapping from douglas-peucker simplifications // to visvalingam simplifications that yield similar // output sizes @@ -972,7 +982,7 @@ drawvec simplify_lines(drawvec &geom, int z, int detail, bool mark_tile_bounds, if (additional[A_VISVALINGAM]) { visvalingam(geom, i, j, scale, retain); } else { - douglas_peucker(geom, i, j - i, res * simplification, 2, retain); + douglas_peucker(geom, i, j - i, res * simplification, 2, retain, res); } } i = j - 1; diff --git a/main.cpp b/main.cpp index dc71b16e..7ce29bc5 100644 --- a/main.cpp +++ b/main.cpp @@ -34,7 +34,7 @@ #include #include -#if defined(__APPLE__) || defined(__FreeBSD__) +#if defined(__APPLE__) || defined(__FreeBSD__) #include #include #include @@ -3521,7 +3521,7 @@ int main(int argc, char **argv) { long long file_bbox[4] = {UINT_MAX, UINT_MAX, 0, 0}; - long long file_bbox1[4] = {0xFFFFFFFF, 0xFFFFFFFF, 0, 0}; // standard -180 to 180 world plane + long long file_bbox1[4] = {0xFFFFFFFF, 0xFFFFFFFF, 0, 0}; // standard -180 to 180 world plane long long file_bbox2[4] = {0x1FFFFFFFF, 0xFFFFFFFF, 0x100000000, 0}; // 0 to 360 world plane auto input_ret = read_input(sources, name ? name : out_mbtiles ? out_mbtiles diff --git a/serial.hpp b/serial.hpp index 129b8ddc..778456d3 100644 --- a/serial.hpp +++ b/serial.hpp @@ -88,7 +88,7 @@ struct reader { long long file_bbox[4] = {0, 0, 0, 0}; - long long file_bbox1[4] = {0xFFFFFFFF, 0xFFFFFFFF, 0, 0}; // standard -180 to 180 world plane + long long file_bbox1[4] = {0xFFFFFFFF, 0xFFFFFFFF, 0, 0}; // standard -180 to 180 world plane long long file_bbox2[4] = {0x1FFFFFFFF, 0xFFFFFFFF, 0x100000000, 0}; // 0 to 360 world plane struct stat geomst {}; diff --git a/tile-join.cpp b/tile-join.cpp index 5372b959..cbc2b418 100644 --- a/tile-join.cpp +++ b/tile-join.cpp @@ -1178,7 +1178,7 @@ int main(int argc, char **argv) { std::string sa; filearg = 1; while (getline(read_file, sa)) { - char* c = const_cast(sa.c_str()); + char *c = const_cast(sa.c_str()); reader *r = begin_reading(c); struct reader **rr; for (rr = &readers; *rr != NULL; rr = &((*rr)->next)) { @@ -1191,7 +1191,6 @@ int main(int argc, char **argv) { } read_file.close(); } - } case 'q': @@ -1262,7 +1261,6 @@ int main(int argc, char **argv) { std::string description; std::string name; - if (filearg == 0) { for (i = optind; i < argc; i++) { reader *r = begin_reading(argv[i]); diff --git a/tile.cpp b/tile.cpp index 8d824f51..ec2a0080 100644 --- a/tile.cpp +++ b/tile.cpp @@ -573,6 +573,7 @@ double simplify_partial(partial *p, drawvec &shared_nodes) { } // continues to simplify to line_detail even if we have extra detail + // should this change since we are now snapping as part of simplifying? drawvec ngeom = simplify_lines(geom, z, line_detail, !(prevent[P_CLIPPING] || prevent[P_DUPLICATION]), p->simplification, t == VT_POLYGON ? 4 : 0, shared_nodes); if (t != VT_POLYGON || ngeom.size() >= 3) { @@ -2301,7 +2302,7 @@ long long write_tile(decompressor *geoms, std::atomic *geompos_in, ch std::string layername = (*layer_unmaps)[p.segment][p.layer]; serial_val sv, sv2, sv3, sv4; long long point_count = p.clustered + 1; - char abbrev[17]; // to_string(LLONG_MAX).length() / 1000 + 1; + char abbrev[17]; // to_string(LLONG_MAX).length() / 1000 + 1; p.full_keys.push_back("clustered"); sv.type = mvt_bool;