Created
September 21, 2023 06:43
-
-
Save ruslo/7e722a5fdd323925a07955d20a3148da to your computer and use it in GitHub Desktop.
CGAL::intersection failed with "Holes of the PWH intersect amongst themselves or with outer boundary" error
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <CGAL/Boolean_set_operations_2.h> // CGAL::intersection | |
#include <CGAL/Polygon_2.h> | |
#include <CGAL/Polygon_with_holes_2.h> | |
using kernel = CGAL::Exact_predicates_exact_constructions_kernel; | |
using polygon_2 = CGAL::Polygon_2<kernel>; | |
using traits = CGAL::Polygon_set_2<kernel>::Traits_2; | |
using point_2 = kernel::Point_2; | |
using polygon_with_holes = CGAL::Polygon_with_holes_2<kernel>; | |
point_2 from_str(const char* str) { | |
point_2 p; | |
std::stringstream s(str); | |
s >> p; | |
return p; | |
} | |
int main() { | |
polygon_2 a; | |
a.push_back(from_str("-5847875/512 -2101699/32")); | |
a.push_back(from_str("-2039797364177/178598912 -1466249919425/22324864")); | |
a.push_back(from_str("-1998583996511/174995456 -179580968161/2734304")); | |
assert(a.is_simple()); | |
assert(a.is_counterclockwise_oriented()); | |
polygon_2 b; | |
b.push_back(from_str("-11691223/1024 -4202777/64")); | |
b.push_back(from_str("-5848211/512 -4203373/64")); | |
b.push_back(from_str("-21454899149/1878528 -15422555627/234816")); | |
b.push_back(from_str("-5847875/512 -2101699/32")); | |
b.push_back(from_str("-150856560285421/13212382720 -108474006520657/1651547840")); | |
b.push_back(from_str("-103520643402947/9066887168 -9303884293825/141670112")); | |
b.push_back(from_str("-132688333675829/11618271232 -2980671421407/45383872")); | |
b.push_back(from_str("-11694829/1024 -8406645/128")); | |
b.push_back(from_str("-100615459819743/8812350464 -72340893017481/1101543808")); | |
b.push_back(from_str("-152081528156177/13320144896 -13668185445517/208127264")); | |
assert(b.is_simple()); | |
assert(b.is_counterclockwise_oriented()); | |
polygon_2 c; | |
c.push_back(from_str("-2039797364177/178598912 -1466249919425/22324864")); | |
c.push_back(from_str("-11695249/1024 -8406781/128")); | |
c.push_back(from_str("-5847875/512 -2101699/32")); | |
c.push_back(from_str("-11694829/1024 -8406645/128")); | |
c.push_back(from_str("-73208853094865/6410208768 -26312662327241/400638048")); | |
c.push_back(from_str("-1998583996511/174995456 -179580968161/2734304")); | |
assert(c.is_simple()); | |
assert(!c.is_counterclockwise_oriented()); | |
polygon_with_holes b_c{b}; | |
b_c.add_hole(c); | |
traits t; | |
assert(CGAL::is_valid_unknown_polygon(a, t)); | |
assert(CGAL::is_valid_unknown_polygon(b_c, t)); | |
std::list<polygon_with_holes> result; | |
std::cout << "Run CGAL::intersection" << std::endl; | |
CGAL::intersection(a, b_c, std::back_inserter(result)); | |
std::cout << "Done" << std::endl; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment