#include <iostream>
#include <CGAL/Simple_cartesian.h>
#include <CGAL/Polygon_2.h>
#include <CGAL/Polygon_with_holes_2.h>
#include <CGAL/Boolean_set_operations_2.h>
#include <CGAL/Polygon_2_algorithms.h>
typedef CGAL::Simple_cartesian<double> K;
typedef K::Point_2 Point;
typedef CGAL::Polygon_2<K> Polygon_2;
typedef CGAL::Polygon_with_holes_2<K> Polygon_with_holes_2;
using std::cout; using std::endl;
int main() {
Point points2[] = { Point(360293.013295,3428412.418094), Point(360314.890157,3428412.777879), Point(360314.974975,3428395.960976), Point(360293.039998,3428395.555309) };
Point points[] = { Point(360269.493565,3428377.901884), Point(360269.116636,3428395.112870), Point(360317.620334,3428396.009899), Point(360317.856205,3428378.555433) };
//this data set is oK.
//Point points[] = { Point(0,0), Point(1,0), Point(1,1), Point(0,1) };
//Point points2[] = { Point(0.5,0.5), Point(1.5,0.5), Point(1.5,1.5), Point(0.5,1.5) };
Polygon_2 poly1(points, points + 4);
Polygon_2 poly2(points2, points2 + 4);
std::list<Polygon_with_holes_2> polyI;
if (!CGAL::do_intersect(poly1, poly2))return 0;
CGAL::intersection(poly1, poly2, std::back_inserter(polyI));
double totalArea = 0;
typedef std::list<Polygon_with_holes_2>::iterator LIT;
for (LIT lit = polyI.begin(); lit != polyI.end(); lit++) {
totalArea += lit->outer_boundary().area();
cout << "TotalArea::" << totalArea;
return 0;
Environment
Operating system (Windows 10):Windows 10
Compiler: VC2015
Release or debug mode: debug
Specific flags used (if any):
CGAL version:4.11
Boost version:1.6
Other libraries versions if used (Eigen, TBB, etc.):
CGAL version:4.11
We no longer support CGAL-4.11.x, since October 2018 when CGAL-4.13 was released.
Do you reproduce that issue with CGAL-5.0.4, CGAL-5.1.1, or CGAL-5.2-beta1? MSVC 2015 is a supported compiler for those versions of CGAL.
do_intersection()
function for polygons requires a kernel with exact constructions such as CGAL::Exact_predicates_exact_constructions_kernel
(instead of CGAL::Simple_cartesian<double>
in your code). I'm closing the issue. Also note that your polygons must be counterclockwise oriented. I'm closing the issue, please reopen it in case we did not answer your question.
Side note: we are working on a version of the do_intersect()
function that requires only exact predicates and it should be available soon.