mirror of
https://github.com/felt/tippecanoe.git
synced 2026-10-04 17:35:42 +02:00
Silently drop zero-area polygons instead of showing Clipper errors
This commit is contained in:
+17
@@ -241,6 +241,8 @@ static void decode_clipped(ClipperLib::PolyNode *t, drawvec &out) {
|
|||||||
drawvec clean_or_clip_poly(drawvec &geom, int z, int detail, int buffer, bool clip) {
|
drawvec clean_or_clip_poly(drawvec &geom, int z, int detail, int buffer, bool clip) {
|
||||||
ClipperLib::Clipper clipper(ClipperLib::ioStrictlySimple);
|
ClipperLib::Clipper clipper(ClipperLib::ioStrictlySimple);
|
||||||
|
|
||||||
|
bool has_area = false;
|
||||||
|
|
||||||
for (unsigned i = 0; i < geom.size(); i++) {
|
for (unsigned i = 0; i < geom.size(); i++) {
|
||||||
if (geom[i].op == VT_MOVETO) {
|
if (geom[i].op == VT_MOVETO) {
|
||||||
unsigned j;
|
unsigned j;
|
||||||
@@ -250,6 +252,16 @@ drawvec clean_or_clip_poly(drawvec &geom, int z, int detail, int buffer, bool cl
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
double area = 0;
|
||||||
|
for (unsigned k = i; k < j; k++) {
|
||||||
|
area += (long double) geom[k].x * (long double) geom[i + ((k - i + 1) % (j - i))].y;
|
||||||
|
area -= (long double) geom[k].y * (long double) geom[i + ((k - i + 1) % (j - i))].x;
|
||||||
|
}
|
||||||
|
area = area / 2;
|
||||||
|
if (area != 0) {
|
||||||
|
has_area = true;
|
||||||
|
}
|
||||||
|
|
||||||
ClipperLib::Path path;
|
ClipperLib::Path path;
|
||||||
|
|
||||||
drawvec tmp;
|
drawvec tmp;
|
||||||
@@ -297,6 +309,11 @@ drawvec clean_or_clip_poly(drawvec &geom, int z, int detail, int buffer, bool cl
|
|||||||
fprintf(stderr, "Polygon clip failed\n");
|
fprintf(stderr, "Polygon clip failed\n");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
if (!has_area) {
|
||||||
|
drawvec out;
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
if (!clipper.Execute(ClipperLib::ctUnion, clipped)) {
|
if (!clipper.Execute(ClipperLib::ctUnion, clipped)) {
|
||||||
fprintf(stderr, "Polygon clean failed\n");
|
fprintf(stderr, "Polygon clean failed\n");
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user