Created
June 7, 2022 13:17
-
-
Save afabri/68caff224232b7bc0815b8c4ba948877 to your computer and use it in GitHub Desktop.
Join two polygons
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/Exact_predicates_exact_constructions_kernel.h> | |
#include <CGAL/Boolean_set_operations_2.h> | |
#include <list> | |
#include <CGAL/Polygon_2.h> | |
#include <CGAL/IO/WKT.h> | |
#include <iostream> | |
#include <fstream> | |
typedef CGAL::Exact_predicates_exact_constructions_kernel K; | |
typedef K::Point_2 Point; | |
typedef CGAL::Polygon_2<K> Polygon_2; | |
typedef CGAL::Polygon_with_holes_2<K> Polygon_with_holes_2; | |
typedef std::vector<Polygon_with_holes_2> Pwh_list_2; | |
int main(int argc, char* argv[]) | |
{ | |
std::ifstream is(argv[1]); | |
Pwh_list_2 polys; | |
do { | |
Polygon_with_holes_2 p; | |
CGAL::IO::read_polygon_WKT(is, p); | |
if (!p.outer_boundary().is_empty()) { | |
assert(p.outer_boundary().is_counterclockwise_oriented()); | |
assert(p.outer_boundary().is_simple()); | |
polys.push_back(p); | |
} | |
}while(is.good() && !is.eof()); | |
Pwh_list_2 unionR; | |
CGAL::join(std::begin(polys), std::end(polys), std::back_inserter(unionR)); | |
CGAL::IO::write_multi_polygon_WKT(std::cout, unionR); | |
return 0; | |
} |
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
POLYGON(( 0 0, 1 0, 1 1, 0 1 )) | |
POLYGON(( 1 1, 2 1, 2 2, 1 2 )) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The output is a single polygon. We pass two times at (1,1) but is is a pinching point, but not an intersection
