Skip to content

Commit

Permalink
Copy the geometric binning code to serve as intersection-finding code
Browse files Browse the repository at this point in the history
  • Loading branch information
e-n-f committed Nov 22, 2024
1 parent 0170dd8 commit f82a868
Showing 1 changed file with 69 additions and 0 deletions.
69 changes: 69 additions & 0 deletions clip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1934,6 +1934,75 @@ mvt_tile assign_to_bins(mvt_tile &features,
return ret;
}

drawvec clip_lines(drawvec const &geom, drawvec const &region) {
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,
Expand Down

0 comments on commit f82a868

Please sign in to comment.