Fix cases where nodes were not being added at the tile boundary

This commit is contained in:
Erica Fischer
2023-09-07 16:29:35 -07:00
parent d7900c445f
commit c44ba31b26
2 changed files with 23 additions and 6 deletions
+14 -5
View File
@@ -671,6 +671,7 @@ static std::vector<std::pair<double, double>> clip_poly1(std::vector<std::pair<d
// now outside the buffer // now outside the buffer
if (prevent[P_SIMPLIFY_SHARED_NODES]) { if (prevent[P_SIMPLIFY_SHARED_NODES]) {
out.push_back(intersect(S, E, edge, ax, ay, bx, by)); // on tile boundary out.push_back(intersect(S, E, edge, ax, ay, bx, by)); // on tile boundary
edge_nodes.push_back(draw(VT_MOVETO, std::round(out.back().first), std::round(out.back().second)));
} }
out.push_back(intersect(S, E, edge, minx, miny, maxx, maxy)); // on buffer edge out.push_back(intersect(S, E, edge, minx, miny, maxx, maxy)); // on buffer edge
} else if (!inside(E, edge, ax, ay, bx, by)) { } else if (!inside(E, edge, ax, ay, bx, by)) {
@@ -714,6 +715,9 @@ static std::vector<std::pair<double, double>> clip_poly1(std::vector<std::pair<d
drawvec simple_clip_poly(drawvec &geom, long long minx, long long miny, long long maxx, long long maxy, drawvec simple_clip_poly(drawvec &geom, long long minx, long long miny, long long maxx, long long maxy,
long long ax, long long ay, long long bx, long long by, drawvec &edge_nodes) { long long ax, long long ay, long long bx, long long by, drawvec &edge_nodes) {
drawvec out; drawvec out;
if (prevent[P_SIMPLIFY_SHARED_NODES]) {
geom = remove_noop(geom, VT_POLYGON, 0);
}
for (size_t i = 0; i < geom.size(); i++) { for (size_t i = 0; i < geom.size(); i++) {
if (geom[i].op == VT_MOVETO) { if (geom[i].op == VT_MOVETO) {
@@ -917,9 +921,19 @@ int quick_check(long long *bbox, int z, long long buffer) {
long long min = 0; long long min = 0;
long long area = 1LL << (32 - z); long long area = 1LL << (32 - z);
// bbox entirely within the tile proper
if (bbox[0] > min && bbox[1] > min && bbox[2] < area && bbox[3] < area) {
return 1;
}
min -= buffer * area / 256; min -= buffer * area / 256;
area += buffer * area / 256; area += buffer * area / 256;
// bbox entirely within the tile, including its buffer
if (bbox[0] > min && bbox[1] > min && bbox[2] < area && bbox[3] < area) {
return 3;
}
// bbox entirely outside the tile // bbox entirely outside the tile
if (bbox[0] > area || bbox[1] > area) { if (bbox[0] > area || bbox[1] > area) {
return 0; return 0;
@@ -928,11 +942,6 @@ int quick_check(long long *bbox, int z, long long buffer) {
return 0; return 0;
} }
// bbox entirely within the tile
if (bbox[0] > min && bbox[1] > min && bbox[2] < area && bbox[3] < area) {
return 1;
}
// some overlap of edge // some overlap of edge
return 2; return 2;
} }
+9 -1
View File
@@ -1406,10 +1406,18 @@ bool clip_to_tile(serial_feature &sf, int z, long long buffer) {
} }
} }
if (quick == 0) { if (quick == 0) { // entirely outside the tile
return true; return true;
} }
// if quick == 3 the feature touches the buffer, not just the tile proper,
// so we need to clip to add intersection points at the tile edge.
// if quick == 2 it touches the buffer and beyond, so likewise
// if quick == 1 we should be able to get away without clipping, because
// the feature is entirely within the tile proper.
// Can't accept the quick check if guaranteeing no duplication, since the // Can't accept the quick check if guaranteeing no duplication, since the
// overlap might have been in the buffer. // overlap might have been in the buffer.
if (quick != 1 || prevent[P_DUPLICATION]) { if (quick != 1 || prevent[P_DUPLICATION]) {