mirror of
https://github.com/felt/tippecanoe.git
synced 2026-10-05 01:45:41 +02:00
Clip the clip regions to the tile bounds to reduce their complexity
This commit is contained in:
@@ -387,8 +387,7 @@ drawvec clean_or_clip_poly(drawvec &geom, int z, int buffer, bool clip, bool try
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
drawvec clip_poly_poly(drawvec &geom, drawvec const &bounds) {
|
drawvec clip_poly_poly(drawvec const &geom, drawvec const &bounds) {
|
||||||
geom = remove_noop(geom, VT_POLYGON, 0);
|
|
||||||
mapbox::geometry::multi_polygon<long long> result;
|
mapbox::geometry::multi_polygon<long long> result;
|
||||||
|
|
||||||
{
|
{
|
||||||
@@ -450,7 +449,7 @@ drawvec clip_poly_poly(drawvec &geom, drawvec const &bounds) {
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
drawvec clip_point_poly(drawvec &geom, drawvec const &bounds) {
|
drawvec clip_point_poly(drawvec const &geom, drawvec const &bounds) {
|
||||||
drawvec out;
|
drawvec out;
|
||||||
for (auto const &p : geom) {
|
for (auto const &p : geom) {
|
||||||
if (pnpoly_mp(bounds, p.x, p.y)) {
|
if (pnpoly_mp(bounds, p.x, p.y)) {
|
||||||
|
|||||||
@@ -102,6 +102,10 @@ int pnpoly(const drawvec &vert, size_t start, size_t nvert, long long testx, lon
|
|||||||
bool pnpoly_mp(drawvec const &geom, long long x, long long y);
|
bool pnpoly_mp(drawvec const &geom, long long x, long long y);
|
||||||
double distance_from_line(long long point_x, long long point_y, long long segA_x, long long segA_y, long long segB_x, long long segB_y);
|
double distance_from_line(long long point_x, long long point_y, long long segA_x, long long segA_y, long long segB_x, long long segB_y);
|
||||||
|
|
||||||
|
drawvec clip_poly_poly(drawvec const &geom, drawvec const &bounds);
|
||||||
|
drawvec clip_lines_poly(drawvec const &geom, drawvec const &bounds);
|
||||||
|
drawvec clip_point_poly(drawvec const &geom, drawvec const &bounds);
|
||||||
|
|
||||||
struct input_tile {
|
struct input_tile {
|
||||||
std::string tile;
|
std::string tile;
|
||||||
int z;
|
int z;
|
||||||
|
|||||||
@@ -259,6 +259,34 @@ int main(int argc, char **argv) {
|
|||||||
fclose(f);
|
fclose(f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// clip the clip polygons, if any, to the tile bounds,
|
||||||
|
// to reduce their complexity
|
||||||
|
|
||||||
|
if (clipbboxes.size() > 0) {
|
||||||
|
long long wx1 = (nx - buffer / 256.0) * (1LL << (32 - nz));
|
||||||
|
long long wy1 = (ny - buffer / 256.0) * (1LL << (32 - nz));
|
||||||
|
long long wx2 = (nx + 1 + buffer / 256.0) * (1LL << (32 - nz));
|
||||||
|
long long wy2 = (ny + 1 + buffer / 256.0) * (1LL << (32 - nz));
|
||||||
|
|
||||||
|
drawvec tile_bounds;
|
||||||
|
tile_bounds.emplace_back(VT_MOVETO, wx1, wy1);
|
||||||
|
tile_bounds.emplace_back(VT_LINETO, wx2, wy1);
|
||||||
|
tile_bounds.emplace_back(VT_LINETO, wx2, wy2);
|
||||||
|
tile_bounds.emplace_back(VT_LINETO, wx1, wy2);
|
||||||
|
tile_bounds.emplace_back(VT_LINETO, wx1, wy1);
|
||||||
|
|
||||||
|
for (auto &c : clipbboxes) {
|
||||||
|
c.minx = std::max(c.minx, wx1);
|
||||||
|
c.miny = std::max(c.miny, wy1);
|
||||||
|
c.maxx = std::min(c.maxx, wx2);
|
||||||
|
c.maxy = std::min(c.maxy, wy2);
|
||||||
|
|
||||||
|
if (c.dv.size() > 0) {
|
||||||
|
c.dv = clip_poly_poly(c.dv, tile_bounds);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
json_object *json_filter = NULL;
|
json_object *json_filter = NULL;
|
||||||
if (filter.size() > 0) {
|
if (filter.size() > 0) {
|
||||||
json_filter = parse_filter(filter.c_str());
|
json_filter = parse_filter(filter.c_str());
|
||||||
|
|||||||
Reference in New Issue
Block a user