Snap to the tile grid as each simplified point is chosen

This commit is contained in:
Erica Fischer
2023-05-04 14:37:19 -07:00
parent 605640e138
commit ae6eed17c1
5 changed files with 19 additions and 10 deletions
+13 -3
View File
@@ -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<int> 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;
-2
View File
@@ -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]);
+1
View File
@@ -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) {