More attempts to solve failures to simplify consistently

This commit is contained in:
Erica Fischer
2023-09-07 16:36:11 -07:00
parent 6551b2cc0e
commit 8476fdf282
2 changed files with 27 additions and 19 deletions
+21 -14
View File
@@ -1009,7 +1009,7 @@ static long long square_distance_from_line(long long point_x, long long point_y,
long long p2x = segB_x - segA_x; long long p2x = segB_x - segA_x;
long long p2y = segB_y - segA_y; long long p2y = segB_y - segA_y;
long long something = p2x * p2x + p2y * p2y; long long something = p2x * p2x + p2y * p2y;
long long u = 0 == something ? 0 : ((point_x - segA_x) * p2x + (point_y - segA_y) * p2y) * scale / something; double u = 0 == something ? 0 : ((point_x - segA_x) * p2x + (point_y - segA_y) * p2y) * scale / something;
if (u > scale) { if (u > scale) {
u = scale; u = scale;
@@ -1030,19 +1030,20 @@ static long long square_distance_from_line(long long point_x, long long point_y,
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) {
e = e * e; e = e * e;
std::stack<int> recursion_stack; std::stack<int> recursion_stack;
printf("doug of %d\n", n);
{ if (!geom[start + 0].necessary || !geom[start + n - 1].necessary) {
int left_border = 0; fprintf(stderr, "endpoints not marked necessary\n");
int right_border = 1; exit(EXIT_IMPOSSIBLE);
// Sweep linerarily over array and identify those ranges that need to be checked }
do {
if (geom[start + right_border].necessary) { int prev = 0;
recursion_stack.push(left_border); for (int here = 1; here < n; here++) {
recursion_stack.push(right_border); if (geom[start + here].necessary) {
left_border = right_border; recursion_stack.push(prev);
recursion_stack.push(here);
prev = here;
} }
++right_border;
} while (right_border < n);
} }
while (!recursion_stack.empty()) { while (!recursion_stack.empty()) {
@@ -1052,6 +1053,8 @@ static void douglas_peucker(drawvec &geom, int start, int n, double e, size_t ke
int first = recursion_stack.top(); int first = recursion_stack.top();
recursion_stack.pop(); recursion_stack.pop();
printf("sub-doug of %d\n", second - first + 1);
long long max_distance = -1; long long max_distance = -1;
int farthest_element_index; int farthest_element_index;
if (geom[start + first] < geom[start + second]) { if (geom[start + first] < geom[start + second]) {
@@ -1094,10 +1097,14 @@ static void douglas_peucker(drawvec &geom, int start, int n, double e, size_t ke
if (1 < farthest_element_index - first) { if (1 < farthest_element_index - first) {
recursion_stack.push(first); recursion_stack.push(first);
recursion_stack.push(farthest_element_index); recursion_stack.push(farthest_element_index);
printf("split1: %d to %d, %d\n", first, farthest_element_index, farthest_element_index - first + 1);
} }
if (1 < second - farthest_element_index) { if (1 < second - farthest_element_index) {
recursion_stack.push(farthest_element_index); recursion_stack.push(farthest_element_index);
recursion_stack.push(second); recursion_stack.push(second);
printf("split2: %d to %d, %d\n", farthest_element_index, second, second - farthest_element_index + 1);
} }
} }
} }
@@ -1338,7 +1345,7 @@ drawvec fix_polygon(drawvec &geom) {
long long xd = ring[a].x - xtotal; long long xd = ring[a].x - xtotal;
long long yd = ring[a].y - ytotal; long long yd = ring[a].y - ytotal;
long long d2 = xd * xd + yd * yd; long long d2 = xd * xd + yd * yd;
if (d2 > dist2) { if (d2 > dist2 || (d2 == dist2 && ring[a] < ring[furthest])) {
dist2 = d2; dist2 = d2;
furthest = a; furthest = a;
} }
@@ -1351,7 +1358,7 @@ drawvec fix_polygon(drawvec &geom) {
long long xd = ring[a].x - ring[furthest].x; long long xd = ring[a].x - ring[furthest].x;
long long yd = ring[a].y - ring[furthest].y; long long yd = ring[a].y - ring[furthest].y;
long long d2 = xd * xd + yd * yd; long long d2 = xd * xd + yd * yd;
if (d2 > dist2b) { if (d2 > dist2b || (d2 == dist2b && ring[a] < ring[furthestb])) {
dist2b = d2; dist2b = d2;
furthestb = a; furthestb = a;
} }
+5 -4
View File
@@ -2318,16 +2318,17 @@ long long write_tile(decompressor *geoms, std::atomic<long long> *geompos_in, ch
// would keep next. // would keep next.
far = 0; far = 0;
double which2 = i; size_t which2 = i;
for (size_t k = i + 1; k < j - 1; k++) { for (size_t k = i + 1; k < j - 1; k++) {
double xd = sf.geometry[k].x - sf.geometry[i].x; double xd = sf.geometry[k].x - sf.geometry[i].x;
double yd = sf.geometry[k].y - sf.geometry[i].y; double yd = sf.geometry[k].y - sf.geometry[i].y;
double xd2 = sf.geometry[k].x - sf.geometry[which].x; double xd2 = sf.geometry[k].x - sf.geometry[which].x;
double yd2 = sf.geometry[k].y - sf.geometry[which].y; double yd2 = sf.geometry[k].y - sf.geometry[which].y;
double d = xd * xd + yd * yd + xd2 * xd2 + yd2 * yd2; double d1 = xd * xd + yd * yd;
if (d > far) { double d2 = xd2 * xd2 + yd2 * yd2;
far = d; if (d1 + d2 > far && d1 != 0 && d2 != 0) {
far = d1 + d2;
which2 = k; which2 = k;
} }
} }