I am attempting to find the intersections of many polygons_with_holes
to check the topology of a map. However, when using the CGAL::intersection()
defined here (under 2D Regularized Boolean Set-Operations
), the run time for one check exceeds 1 minute, sometimes reaching close to 2 minutes. I have about 60-70 polygons with holes, with a total of 584697 vertices. I check whether their bounding boxes overlap before checking whether they intersect (I isolated the bounding box check, and that did not take long), but that still did not speed it up much. Is there any way I could get the runtime down to a couple seconds? I'm using Epick
as my kernel. This is the code I have:
// Comparing polygons pair-wise and calculating intersections, if any.
for (size_t i = 0; i < all_pgwhs_in_inset.size(); ++i) {
const Polygon_with_holes pgnwh1 = all_pgwhs_in_inset[i];
const Bbox pgnwh1_bb = pgnwh1.bbox();
for (size_t j = i + 1; j < all_pgwhs_in_inset.size(); ++j) {
const Polygon_with_holes pgnwh2 = all_pgwhs_in_inset[j];
const Bbox pgnwh2_bb = pgnwh2.bbox();
// Calculating intersections only if bounding boxes overlap.
// For condition, look at:
// https://stackoverflow.com/questions/306316/determine-if-
// two-rectangles-overlap-each-other
if (pgnwh1_bb.xmin() < pgnwh2_bb.xmax()
&& pgnwh1_bb.xmax() > pgnwh2_bb.xmin()
&& pgnwh1_bb.ymin() < pgnwh2_bb.ymax()
&& pgnwh2_bb.ymax() > pgnwh1_bb.ymin()) {
unsigned int size = intersections.size();
CGAL::intersection(pgnwh1, pgnwh2, std::back_inserter(intersections));
}
}
}
This is the kind of data I am dealing with:
Finally, I noticed that the function recognises and adds the entire polygon with holes as an intersection; when would this be the case and why would it happen? In these cases, I can not find any intersections using tools like https://mapshaper.org. Thus, are these indicating something else? Some of the added 'intersections' seem to be the exact same as the original polygon with holes.