mirror of
https://github.com/felt/tippecanoe.git
synced 2026-10-02 08:25:40 +02:00
Copy the geometric binning code to serve as intersection-finding code
This commit is contained in:
@@ -1934,6 +1934,75 @@ mvt_tile assign_to_bins(mvt_tile &features,
|
||||
return ret;
|
||||
}
|
||||
|
||||
drawvec clip_lines(drawvec const &geom, drawvec const ®ion) {
|
||||
std::vector<index_event> events;
|
||||
|
||||
if (region.size() == 0) {
|
||||
return drawvec();
|
||||
}
|
||||
|
||||
// Index region segments
|
||||
for (size_t i = 1; i < region.size(); i++) {
|
||||
if (region[i].op == VT_LINETO) {
|
||||
long long xmin = std::min(region[i - 1].x, region[i].x);
|
||||
long long ymin = std::min(region[i - 1].y, region[i].y);
|
||||
long long xmax = std::max(region[i - 1].x, region[i].x);
|
||||
long long ymax = std::max(region[i - 1].y, region[i].y);
|
||||
unsigned long long start, end;
|
||||
|
||||
get_quadkey_bounds(xmin, ymin, xmax, ymax, &start, &end);
|
||||
events.emplace_back(start, index_event::ENTER, i, 0, xmin, ymin, xmax, ymax);
|
||||
events.emplace_back(end, index_event::EXIT, i, 0, xmin, ymin, xmax, ymax);
|
||||
}
|
||||
}
|
||||
|
||||
// Index linestring segments
|
||||
for (size_t i = 1; i < geom.size(); i++) {
|
||||
if (geom[i].op == VT_LINETO) {
|
||||
long long xmin = std::min(geom[i - 1].x, geom[i].x);
|
||||
long long ymin = std::min(geom[i - 1].y, geom[i].y);
|
||||
long long xmax = std::max(geom[i - 1].x, geom[i].x);
|
||||
long long ymax = std::max(geom[i - 1].y, geom[i].y);
|
||||
unsigned long long start, end;
|
||||
|
||||
get_quadkey_bounds(xmin, ymin, xmax, ymax, &start, &end);
|
||||
events.emplace_back(start, index_event::CHECK, i, 0, xmin, ymin, xmax, ymax);
|
||||
}
|
||||
}
|
||||
|
||||
std::sort(events.begin(), events.end());
|
||||
std::set<active_bin> active;
|
||||
|
||||
for (auto &e : events) {
|
||||
if (e.kind == index_event::ENTER) {
|
||||
active_bin a(e.layer, e.feature);
|
||||
a.xmin = e.xmin;
|
||||
a.ymin = e.ymin;
|
||||
a.xmax = e.xmax;
|
||||
a.ymax = e.ymax;
|
||||
|
||||
active.insert(std::move(a));
|
||||
} else if (e.kind == index_event::CHECK) {
|
||||
for (auto const &a : active) {
|
||||
if (bbox_intersects(e.xmin, e.ymin, e.xmax, e.ymax,
|
||||
a.xmin, a.ymin, a.xmax, a.ymax)) {
|
||||
// compare
|
||||
}
|
||||
}
|
||||
} else /* EXIT */ {
|
||||
auto const &found = active.find({e.layer, e.feature});
|
||||
if (found != active.end()) {
|
||||
active.erase(found);
|
||||
} else {
|
||||
fprintf(stderr, "event mismatch: can't happen\n");
|
||||
exit(EXIT_IMPOSSIBLE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return drawvec();
|
||||
}
|
||||
|
||||
std::string overzoom(std::vector<source_tile> const &tiles, int nz, int nx, int ny,
|
||||
int detail_or_unspecified, int buffer,
|
||||
std::set<std::string> const &keep,
|
||||
|
||||
Reference in New Issue
Block a user