// Boost.Geometry (aka GGL, Generic Geometry Library) // Robustness Test // Copyright (c) 2013-2015 Barend Gehrels, Amsterdam, the Netherlands. // Use, modification and distribution is subject to the Boost Software License, // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // Adapted from: the attachment of ticket 9081 #define CHECK_SELF_INTERSECTIONS #define LIST_WKT #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include typedef boost::geometry::model::d2::point_xy pt; typedef boost::geometry::model::polygon polygon; typedef boost::geometry::model::segment segment; typedef boost::geometry::model::multi_polygon multi_polygon; template inline void debug_with_svg(int index, char method, Geometry const& a, Geometry const& b, std::string const& headera, std::string const& headerb) { multi_polygon output; try { switch(method) { case 'i': boost::geometry::intersection(a, b, output); break; case 'u': boost::geometry::union_(a, b, output); break; case 'd': boost::geometry::difference(a, b, output); break; case 'v': boost::geometry::difference(b, a, output); break; default : return; } } catch(...) {} std::ostringstream filename; filename << "ticket_9081_" << method << "_" << (1000000 + index) << ".svg"; std::ofstream svg(filename.str().c_str()); boost::geometry::svg_mapper mapper(svg, 400, 400); mapper.add(a); mapper.add(b); mapper.map(a, "fill-opacity:0.5;fill:rgb(153,204,0);stroke:rgb(153,204,0);stroke-width:2"); mapper.map(b, "fill-opacity:0.3;fill:rgb(51,51,153);stroke:rgb(51,51,153);stroke-width:2"); BOOST_FOREACH(polygon const& g, output) { mapper.map(g, "opacity:0.8;fill:none;stroke:rgb(255,128,0);stroke-width:4;stroke-dasharray:1,7;stroke-linecap:round"); } std::ostringstream out; out << headera << std::endl << headerb; mapper.map(boost::geometry::return_centroid(a), "fill:rgb(152,204,0);stroke:rgb(153,204,0);stroke-width:0.1", 3); mapper.map(boost::geometry::return_centroid(b), "fill:rgb(51,51,153);stroke:rgb(153,204,0);stroke-width:0.1", 3); mapper.text(boost::geometry::return_centroid(a), headera, "fill:rgb(0,0,0);font-family:Arial;font-size:10px"); mapper.text(boost::geometry::return_centroid(b), headerb, "fill:rgb(0,0,0);font-family:Arial;font-size:10px"); } int main() { int num_orig = 50; int num_rounds = 30000; srand(1234); std::cout << std::setprecision(16); std::map genesis; int pj; std::string wkt1, wkt2, operation; try { boost::timer t; std::vector poly_list; for(int i=0;i 0) { std::ostringstream out; out << j << " intersection(" << genesis[a] << " , " << genesis[b] << ")"; genesis[poly_list.size()] = out.str(); poly_list.push_back(mp_i); } if(boost::geometry::area(mp_d) > 0) { std::ostringstream out; out << j << " difference(" << genesis[a] << " - " << genesis[b] << ")"; genesis[poly_list.size()] = out.str(); poly_list.push_back(mp_d); } if(boost::geometry::area(mp_e) > 0) { std::ostringstream out; out << j << " difference(" << genesis[b] << " - " << genesis[a] << ")"; genesis[poly_list.size()] = out.str(); poly_list.push_back(mp_e); } } std::cout << "FINISHED " << t.elapsed() << std::endl; } catch(std::exception const& e) { std::cout << e.what() << " in " << operation << " at " << pj << std::endl << wkt1 << std::endl << wkt2 << std::endl << std::endl; } catch(...) { std::cout << "Other exception" << std::endl; } return 0; }