mirror of
https://github.com/mapbox/tippecanoe.git
synced 2025-04-08 11:34:12 +00:00
More informative return value from clipping
This commit is contained in:
parent
22732f0ceb
commit
74a2e0ab15
18
clip.hpp
18
clip.hpp
@ -23,11 +23,17 @@ static int computeOutCode(double x, double y, double xmin, double ymin, double x
|
||||
return code;
|
||||
}
|
||||
|
||||
#define CLIP_OK 0
|
||||
#define CLIP_ELIMINATED 1
|
||||
#define CLIP_CHANGED_FIRST 2
|
||||
#define CLIP_CHANGED_SECOND 4
|
||||
#define CLIP_CHANGED (CLIP_CHANGED_FIRST | CLIP_CHANGED_SECOND)
|
||||
|
||||
static int clip(double *x0, double *y0, double *x1, double *y1, double xmin, double ymin, double xmax, double ymax) {
|
||||
int outcode0 = computeOutCode(*x0, *y0, xmin, ymin, xmax, ymax);
|
||||
int outcode1 = computeOutCode(*x1, *y1, xmin, ymin, xmax, ymax);
|
||||
int changed = CLIP_OK;
|
||||
int accept = 0;
|
||||
int changed = 0;
|
||||
|
||||
while (1) {
|
||||
if (!(outcode0 | outcode1)) { // Bitwise OR is 0. Trivially accept and get out of loop
|
||||
@ -65,19 +71,19 @@ static int clip(double *x0, double *y0, double *x1, double *y1, double xmin, dou
|
||||
*x0 = x;
|
||||
*y0 = y;
|
||||
outcode0 = computeOutCode(*x0, *y0, xmin, ymin, xmax, ymax);
|
||||
changed = 1;
|
||||
changed |= CLIP_CHANGED_FIRST;
|
||||
} else {
|
||||
*x1 = x;
|
||||
*y1 = y;
|
||||
outcode1 = computeOutCode(*x1, *y1, xmin, ymin, xmax, ymax);
|
||||
changed = 1;
|
||||
changed |= CLIP_CHANGED_SECOND;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (accept == 0) {
|
||||
return 0;
|
||||
if (accept) {
|
||||
return changed;
|
||||
} else {
|
||||
return changed + 1;
|
||||
return CLIP_ELIMINATED;
|
||||
}
|
||||
}
|
||||
|
12
geometry.cpp
12
geometry.cpp
@ -663,14 +663,14 @@ drawvec clip_lines(drawvec &geom, int z, long long buffer) {
|
||||
|
||||
int c = clip(&x1, &y1, &x2, &y2, min, min, area, area);
|
||||
|
||||
if (c > 1) { // clipped
|
||||
if (c == CLIP_ELIMINATED) {
|
||||
out.push_back(draw(VT_MOVETO, geom[i].x, geom[i].y));
|
||||
} else if (c == CLIP_OK) {
|
||||
out.push_back(geom[i]);
|
||||
} else {
|
||||
out.push_back(draw(VT_MOVETO, x1, y1));
|
||||
out.push_back(draw(VT_LINETO, x2, y2));
|
||||
out.push_back(draw(VT_MOVETO, geom[i].x, geom[i].y));
|
||||
} else if (c == 1) { // unchanged
|
||||
out.push_back(geom[i]);
|
||||
} else { // clipped away entirely
|
||||
out.push_back(draw(VT_MOVETO, geom[i].x, geom[i].y));
|
||||
}
|
||||
} else {
|
||||
out.push_back(geom[i]);
|
||||
@ -776,7 +776,7 @@ drawvec impose_tile_boundaries(drawvec &geom, long long extent) {
|
||||
|
||||
int c = clip(&x1, &y1, &x2, &y2, 0, 0, extent, extent);
|
||||
|
||||
if (c > 1) { // clipped
|
||||
if (c & CLIP_CHANGED) {
|
||||
if (x1 != geom[i - 1].x || y1 != geom[i - 1].y) {
|
||||
out.push_back(draw(VT_LINETO, x1, y1));
|
||||
out[out.size() - 1].necessary = 1;
|
||||
|
Loading…
x
Reference in New Issue
Block a user