Skip to content

Commit 770bfec

Browse files
authored
Merge pull request #38 from mapbox/close-polygons
Close polygons with closepath instead of lineto
2 parents eff7932 + d9d415b commit 770bfec

File tree

1 file changed

+2
-61
lines changed

1 file changed

+2
-61
lines changed

tile.cpp

Lines changed: 2 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -91,65 +91,6 @@ struct tiler {
9191
std::string layername;
9292
};
9393

94-
std::vector<mvt_geometry> merge_rings(std::vector<mvt_geometry> g) {
95-
std::multimap<mvt_geometry, mvt_geometry> trimmed;
96-
97-
for (size_t i = 1; i < g.size(); i++) {
98-
if (g[i].op == mvt_lineto) {
99-
bool found = false;
100-
101-
auto r = trimmed.equal_range(g[i]);
102-
for (auto a = r.first; a != r.second; a++) {
103-
if (a->second == g[i - 1]) {
104-
found = true;
105-
trimmed.erase(a);
106-
break;
107-
}
108-
}
109-
110-
if (!found) {
111-
trimmed.insert(std::pair<mvt_geometry, mvt_geometry>(g[i - 1], g[i]));
112-
}
113-
}
114-
}
115-
116-
std::vector<mvt_geometry> out;
117-
118-
while (trimmed.size() != 0) {
119-
auto a = trimmed.begin();
120-
mvt_geometry start = a->first;
121-
mvt_geometry here = a->second;
122-
trimmed.erase(a);
123-
out.push_back(mvt_geometry(mvt_moveto, start.x, start.y));
124-
out.push_back(mvt_geometry(mvt_lineto, here.x, here.y));
125-
126-
while (1) {
127-
auto there = trimmed.find(here);
128-
if (there == trimmed.end()) {
129-
fprintf(stderr, "Internal error: no path");
130-
for (size_t i = 0; i < g.size(); i++) {
131-
if (g[i].op == mvt_moveto) {
132-
fprintf(stderr, "\n");
133-
}
134-
fprintf(stderr, "%d,%d ", g[i].x, g[i].y);
135-
}
136-
fprintf(stderr, "\n");
137-
exit(EXIT_FAILURE);
138-
}
139-
140-
here = there->second;
141-
trimmed.erase(there);
142-
out.push_back(mvt_geometry(mvt_lineto, here.x, here.y));
143-
144-
if (here == start) {
145-
break;
146-
}
147-
}
148-
}
149-
150-
return out;
151-
}
152-
15394
void gather_quantile(tile const &tile, int detail, long long &max) {
15495
for (size_t y = 0; y < (1U << detail); y++) {
15596
for (size_t x = 0; x < (1U << detail); x++) {
@@ -312,7 +253,7 @@ void make_tile(sqlite3 *outdb, tile &otile, int z, int detail, long long zoom_ma
312253
feature.geometry.push_back(mvt_geometry(mvt_lineto, (x + 1), (y + 0)));
313254
feature.geometry.push_back(mvt_geometry(mvt_lineto, (x + 1), (y + 1)));
314255
feature.geometry.push_back(mvt_geometry(mvt_lineto, (x + 0), (y + 1)));
315-
feature.geometry.push_back(mvt_geometry(mvt_lineto, (x + 0), (y + 0)));
256+
feature.geometry.push_back(mvt_geometry(mvt_closepath, 0, 0));
316257
}
317258

318259
if (include_density) {
@@ -351,7 +292,7 @@ void make_tile(sqlite3 *outdb, tile &otile, int z, int detail, long long zoom_ma
351292
feature.geometry.push_back(mvt_geometry(mvt_lineto, (x + 1), (y + 0)));
352293
feature.geometry.push_back(mvt_geometry(mvt_lineto, (x + 1), (y + 1)));
353294
feature.geometry.push_back(mvt_geometry(mvt_lineto, (x + 0), (y + 1)));
354-
feature.geometry.push_back(mvt_geometry(mvt_lineto, (x + 0), (y + 0)));
295+
feature.geometry.push_back(mvt_geometry(mvt_closepath, 0, 0));
355296
}
356297
}
357298
}

0 commit comments

Comments
 (0)