|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r86237 - trunk/libs/geometry/test/algorithms/overlay/robustness
From: barend.gehrels_at_[hidden]
Date: 2013-10-11 16:39:28
Author: barendgehrels
Date: 2013-10-11 16:39:28 EDT (Fri, 11 Oct 2013)
New Revision: 86237
URL: http://svn.boost.org/trac/boost/changeset/86237
Log:
[geometry] added robustness test for ticket 9081
Added:
trunk/libs/geometry/test/algorithms/overlay/robustness/ticket_9081.cpp (contents, props changed)
Text files modified:
trunk/libs/geometry/test/algorithms/overlay/robustness/Jamfile.v2 | 2
trunk/libs/geometry/test/algorithms/overlay/robustness/recursive_polygons.cpp | 2
trunk/libs/geometry/test/algorithms/overlay/robustness/star_comb.cpp | 4
trunk/libs/geometry/test/algorithms/overlay/robustness/ticket_9081.cpp | 211 ++++++++++++++++++++++++++++++++++++++++
4 files changed, 216 insertions(+), 3 deletions(-)
Modified: trunk/libs/geometry/test/algorithms/overlay/robustness/Jamfile.v2
==============================================================================
--- trunk/libs/geometry/test/algorithms/overlay/robustness/Jamfile.v2 Fri Oct 11 10:32:02 2013 (r86236)
+++ trunk/libs/geometry/test/algorithms/overlay/robustness/Jamfile.v2 2013-10-11 16:39:28 EDT (Fri, 11 Oct 2013) (r86237)
@@ -24,3 +24,5 @@
exe recursive_polygons : recursive_polygons.cpp ;
exe star_comb : star_comb.cpp ;
+exe ticket_9081 : ticket_9081.cpp ;
+
Modified: trunk/libs/geometry/test/algorithms/overlay/robustness/recursive_polygons.cpp
==============================================================================
--- trunk/libs/geometry/test/algorithms/overlay/robustness/recursive_polygons.cpp Fri Oct 11 10:32:02 2013 (r86236)
+++ trunk/libs/geometry/test/algorithms/overlay/robustness/recursive_polygons.cpp 2013-10-11 16:39:28 EDT (Fri, 11 Oct 2013) (r86237)
@@ -1,5 +1,5 @@
// Boost.Geometry (aka GGL, Generic Geometry Library)
-// Unit Test
+// Robustness Test
// Copyright (c) 2009-2012 Barend Gehrels, Amsterdam, the Netherlands.
Modified: trunk/libs/geometry/test/algorithms/overlay/robustness/star_comb.cpp
==============================================================================
--- trunk/libs/geometry/test/algorithms/overlay/robustness/star_comb.cpp Fri Oct 11 10:32:02 2013 (r86236)
+++ trunk/libs/geometry/test/algorithms/overlay/robustness/star_comb.cpp 2013-10-11 16:39:28 EDT (Fri, 11 Oct 2013) (r86237)
@@ -8,9 +8,9 @@
// http://www.boost.org/LICENSE_1_0.txt)
-#define BOOST_GEOMETRY_REPORT_OVERLAY_ERROR
+// #define BOOST_GEOMETRY_REPORT_OVERLAY_ERROR
#define BOOST_GEOMETRY_NO_BOOST_TEST
-#define BOOST_GEOMETRY_TIME_OVERLAY
+// #define BOOST_GEOMETRY_TIME_OVERLAY
#include <test_overlay_p_q.hpp>
Added: trunk/libs/geometry/test/algorithms/overlay/robustness/ticket_9081.cpp
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ trunk/libs/geometry/test/algorithms/overlay/robustness/ticket_9081.cpp 2013-10-11 16:39:28 EDT (Fri, 11 Oct 2013) (r86237)
@@ -0,0 +1,211 @@
+// Boost.Geometry (aka GGL, Generic Geometry Library)
+// Robustness Test
+
+// Copyright (c) 2013 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 BOOST_GEOMETRY_DEBUG_HAS_SELF_INTERSECTIONS
+#define BOOST_GEOMETRY_DEBUG_SEGMENT_IDENTIFIER
+//#define BOOST_GEOMETRY_DEBUG_INTERSECTION
+//#define CHECK_SELF_INTERSECTIONS
+
+ #include <iomanip>
+ #include <iostream>
+ #include <vector>
+ #include <boost/geometry.hpp>
+ #include <boost/geometry/geometries/point_xy.hpp>
+ #include <boost/geometry/geometries/polygon.hpp>
+ #include <boost/geometry/geometries/register/point.hpp>
+ #include <boost/geometry/geometries/register/ring.hpp>
+ #include <boost/geometry/io/wkt/wkt.hpp>
+ #include <boost/geometry/multi/geometries/multi_polygon.hpp>
+
+#include <boost/foreach.hpp>
+#include <boost/timer.hpp>
+#include <boost/algorithm/string.hpp>
+#include <boost/geometry/io/svg/svg_mapper.hpp>
+#include <fstream>
+
+
+typedef boost::geometry::model::d2::point_xy<double> pt;
+typedef boost::geometry::model::polygon<pt> polygon;
+typedef boost::geometry::model::segment<pt> segment;
+typedef boost::geometry::model::multi_polygon<polygon> multi_polygon;
+
+template <typename Geometry>
+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<pt> 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.text(boost::geometry::return_centroid<pt>(a), out.str(),
+ "fill:rgb(0,0,0);font-family:Arial;font-size:10px");
+}
+
+int main()
+{
+ int num_orig=50;
+ int num_rounds=20000;
+ //int num_rounds=16000;
+ srand(1234);
+ std::cout<<std::setprecision(16);
+ std::map<int, std::string> genesis;
+ int pj;
+
+ try
+ {
+
+
+ boost::timer t;
+ std::vector<multi_polygon> poly_list;
+
+ for(int i=0;i<num_orig;i++)
+ {
+ multi_polygon mp;
+ polygon p;
+ for(int j=0;j<3;j++)
+ {
+ double x=(double)rand()/RAND_MAX;
+ double y=(double)rand()/RAND_MAX;
+ p.outer().push_back(pt(x,y));
+ }
+ boost::geometry::correct(p);
+ mp.push_back(p);
+ boost::geometry::detail::overlay::has_self_intersections(mp);
+
+ std::ostringstream out;
+ out << "original " << poly_list.size();
+ genesis[poly_list.size()] = out.str();
+ poly_list.push_back(mp);
+ }
+
+
+ for(int j=0;j<num_rounds;j++)
+ {
+ std::cout << " " << j;
+ pj = j;
+ int a = rand() % poly_list.size();
+ int b = rand() % poly_list.size();
+ multi_polygon mp_i,mp_d,mp_e;
+ //debug_with_svg(j, 'i', poly_list[a], poly_list[b], genesis[a], genesis[b]);
+ boost::geometry::intersection(poly_list[a],poly_list[b],mp_i);
+ boost::geometry::difference(poly_list[a],poly_list[b],mp_d);
+ boost::geometry::difference(poly_list[b],poly_list[a],mp_e);
+#ifdef CHECK_SELF_INTERSECTIONS
+ try
+ {
+ boost::geometry::detail::overlay::has_self_intersections(mp_i);
+ }
+ catch(...)
+ {
+ std::cout<<"FAILED TO INTERSECT " << j << std::endl;
+ std::cout<<boost::geometry::wkt(poly_list[a])<<std::endl;
+ std::cout<<boost::geometry::wkt(poly_list[b])<<std::endl;
+ std::cout<<boost::geometry::wkt(mp_i)<<std::endl;
+ try
+ {
+ boost::geometry::detail::overlay::has_self_intersections(mp_i);
+ }
+ catch(...)
+ {
+ }
+ break;
+ }
+
+ try
+ {
+ boost::geometry::detail::overlay::has_self_intersections(mp_d);
+ }
+ catch(...)
+ {
+ std::cout<<"FAILED TO SUBTRACT " << j << std::endl;
+ std::cout<<boost::geometry::wkt(poly_list[a])<<std::endl;
+ std::cout<<boost::geometry::wkt(poly_list[b])<<std::endl;
+ std::cout<<boost::geometry::wkt(mp_d)<<std::endl;
+ break;
+ }
+ try
+ {
+ boost::geometry::detail::overlay::has_self_intersections(mp_e);
+ }
+ catch(...)
+ {
+ std::cout<<"FAILED TO SUBTRACT " << j << std::endl;
+ std::cout<<boost::geometry::wkt(poly_list[b])<<std::endl;
+ std::cout<<boost::geometry::wkt(poly_list[a])<<std::endl;
+ std::cout<<boost::geometry::wkt(mp_e)<<std::endl;
+ break;
+ }
+#endif
+
+ if(boost::geometry::area(mp_i)>0)
+ {
+ std::ostringstream out;
+ out << "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 << "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 << "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() << " at " << pj << std::endl;
+ }
+ catch(...)
+ {
+ std::cout << "Other exception" << std::endl;
+ }
+
+ return 0;
+}
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk