From 58ab638f20b13a00b05b579e8f8f4783ebdbf9a1 Mon Sep 17 00:00:00 2001 From: Eric Fischer Date: Mon, 18 Jun 2018 09:41:26 -0700 Subject: [PATCH] Debugging code to find where I am leaving empty linetos --- vt3.cpp | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 71 insertions(+), 3 deletions(-) diff --git a/vt3.cpp b/vt3.cpp index 19e8fcf..5434e09 100644 --- a/vt3.cpp +++ b/vt3.cpp @@ -23,6 +23,15 @@ #include "vt3.hpp" #include "clip.hpp" +bool check_empty_lineto(std::vector &geom) { + for (size_t i = 1; i < geom.size(); i++) { + if (geom[i].op == mvt_lineto && geom[i - 1].x == geom[i].x && geom[i - 1].y == geom[i].y) { + return true; + } + } + return false; +} + std::vector clip_lines(std::vector &geom, long left, long top, long right, long bottom) { std::vector out; @@ -64,6 +73,10 @@ std::vector clip_lines(std::vector &geom, long left, phantom.id = 0; out.push_back(phantom); out.push_back(geom[i]); + + if (phantom == geom[i]) { + fprintf(stderr, "clip out to in made empty lineto\n"); + } } inside = true; @@ -88,9 +101,20 @@ std::vector clip_lines(std::vector &geom, long left, // out.push_back(geom[i - 1]); mvt_geometry phantom(mvt_lineto, round(x2), round(y2)); - phantom.phantom = true; - phantom.id = 0; - out.push_back(phantom); + + if (phantom == out[out.size() - 1]) { + if (out[out.size() - 1].id == 0) { + fprintf(stderr, "In to out is clipped away but has no id %lld,%lld\n", phantom.x, phantom.y); + } + } else { + phantom.phantom = true; + phantom.id = 0; + out.push_back(phantom); + } + + if (out[out.size() - 2] == out[out.size() - 1]) { + fprintf(stderr, "clip in to out made empty lineto\n"); + } } else { // Outside to outside, so discardable on both sides @@ -112,6 +136,10 @@ std::vector clip_lines(std::vector &geom, long left, phantom2.phantom = true; phantom2.id = 0; out.push_back(phantom2); + + if (phantom1 == phantom2) { + fprintf(stderr, "clip in discardable made empty lineto\n"); + } } } @@ -120,6 +148,11 @@ std::vector clip_lines(std::vector &geom, long left, } } + if (check_empty_lineto(out)) { + fprintf(stderr, "empty lineto in clip\n"); + exit(EXIT_FAILURE); + } + return out; } @@ -149,6 +182,11 @@ static std::vector remove_noop(std::vector geom, std } } + if (check_empty_lineto(out)) { + fprintf(stderr, "empty lineto in remove noop\n"); + exit(EXIT_FAILURE); + } + return out; } @@ -285,6 +323,11 @@ void split_feature(mvt_layer const &layer, mvt_feature const &feature, std::vect ngeom.push_back(ogeom[i]); } + if (check_empty_lineto(ngeom)) { + fprintf(stderr, "empty lineto in adding crossings\n"); + exit(EXIT_FAILURE); + } + // Part 1a: same, but for Y axis crossings ogeom = ngeom; @@ -320,6 +363,11 @@ void split_feature(mvt_layer const &layer, mvt_feature const &feature, std::vect ngeom.push_back(ogeom[i]); } + if (check_empty_lineto(ngeom)) { + fprintf(stderr, "empty lineto in adding crossings\n"); + exit(EXIT_FAILURE); + } + // Part 2: Assign (real) point IDs for any points that are on a sub-tile edge for (size_t i = 0; i < ngeom.size(); i++) { if (ngeom[i].x % nextent == 0 || ngeom[i].y % nextent == 0) { @@ -427,6 +475,11 @@ void merge_partials(std::vector &partials, size_t start, size_t end, mv out.push_back(geom[k]); } + if (check_empty_lineto(out)) { + fprintf(stderr, "empty lineto in buffer removal 1\n"); + exit(EXIT_FAILURE); + } + // Now need to discard anything that happens in the buffer, // because it should all be duplicated. @@ -453,6 +506,11 @@ void merge_partials(std::vector &partials, size_t start, size_t end, mv } } + if (check_empty_lineto(out2)) { + fprintf(stderr, "empty lineto in buffer removal\n"); + exit(EXIT_FAILURE); + } + revised.push_back(out2); j = k - 1; } @@ -498,6 +556,11 @@ void merge_partials(std::vector &partials, size_t start, size_t end, mv } } + if (check_empty_lineto(arc)) { + fprintf(stderr, "empty lineto in arc making\n"); + exit(EXIT_FAILURE); + } + // Don't insert anything that was clipped down to just one moveto if (arc.size() > 1) { arcs.insert(std::pair>(id, arc)); @@ -560,6 +623,11 @@ void merge_partials(std::vector &partials, size_t start, size_t end, mv } } + if (check_empty_lineto(out)) { + fprintf(stderr, "empty lineto in reassembly\n"); + exit(EXIT_FAILURE); + } + for (size_t i = 0; i < out.size(); i++) { nf->geometry.push_back(out[i]); }