$include_dir="/home/hyper-archives/boost-commit/include"; include("$include_dir/msg-header.inc") ?>
Subject: [Boost-commit] svn:boost r67397 - in sandbox/geometry/libs/geometry/test: algorithms algorithms/overlay/robustness geometries multi/algorithms
From: barend.gehrels_at_[hidden]
Date: 2010-12-21 16:44:40
Author: barendgehrels
Date: 2010-12-21 16:44:38 EST (Tue, 21 Dec 2010)
New Revision: 67397
URL: http://svn.boost.org/trac/boost/changeset/67397
Log:
Added multi/closure.hpp
Added point_order/closure/difference to robustness tests (partly)
Text files modified: 
   sandbox/geometry/libs/geometry/test/algorithms/overlay/robustness/intersection_pies.cpp  |    29 +++++++++++-----                        
   sandbox/geometry/libs/geometry/test/algorithms/overlay/robustness/recursive_polygons.cpp |    18 ++++++----                              
   sandbox/geometry/libs/geometry/test/algorithms/overlay/robustness/test_overlay_p_q.hpp   |    67 ++++++++++++++++++++------------------- 
   sandbox/geometry/libs/geometry/test/algorithms/test_overlay.hpp                          |     3 +                                       
   sandbox/geometry/libs/geometry/test/algorithms/union.cpp                                 |     6 +++                                     
   sandbox/geometry/libs/geometry/test/geometries/custom_linestring.cpp                     |     4 +                                       
   sandbox/geometry/libs/geometry/test/multi/algorithms/multi_intersection.cpp              |     2                                         
   7 files changed, 78 insertions(+), 51 deletions(-)
Modified: sandbox/geometry/libs/geometry/test/algorithms/overlay/robustness/intersection_pies.cpp
==============================================================================
--- sandbox/geometry/libs/geometry/test/algorithms/overlay/robustness/intersection_pies.cpp	(original)
+++ sandbox/geometry/libs/geometry/test/algorithms/overlay/robustness/intersection_pies.cpp	2010-12-21 16:44:38 EST (Tue, 21 Dec 2010)
@@ -58,6 +58,7 @@
         bg::exterior_ring(polygon).push_back(bg::make<p>(int(x), int(y)));
     }
     bg::exterior_ring(polygon).push_back(bg::make<p>(int(cx), int(cy)));
+    bg::correct(polygon);
 }
 
 
@@ -132,13 +133,13 @@
 
 
 
-template <typename T>
+template <typename T, bool Clockwise, bool Closed>
 void test_pie(int total_segment_count, T factor_p, T factor_q,
-            bool multi, bool multi_st, bool svg)
+            bool multi, bool single_selftangent, bool svg)
 {
     boost::timer t;
     typedef bg::model::d2::point_xy<T> point_type;
-    typedef bg::model::polygon<point_type> polygon;
+    typedef bg::model::polygon<point_type, Clockwise, Closed> polygon;
     typedef bg::model::multi_polygon<polygon> multi_polygon;
 
     int good_count = 0;
@@ -193,7 +194,7 @@
                             bool good = false;
 
                             // Represent as either multi-polygon, or as single-self-touching-polygon (INVALID)
-                            if (multi_st)
+                            if (single_selftangent)
                             {
                                 polygon q1 = q;
                                 for (unsigned int i = 1; i < q2.outer().size(); i++)
@@ -233,10 +234,10 @@
 }
 
 
-template <typename T>
-void test_all(bool multi, bool multi_st, bool svg)
+template <typename T, bool Clockwise, bool Closed>
+void test_all(bool multi, bool single_selftangent, bool svg)
 {
-    test_pie<T>(24, 0.55, 0.45, multi, multi_st, svg);
+    test_pie<T, Clockwise, Closed>(24, 0.55, 0.45, multi, single_selftangent, svg);
 }
 
 int main(int argc, char** argv)
@@ -244,9 +245,19 @@
     try
     {
         bool svg = argc > 1 && std::string(argv[1]) == std::string("svg");
+        bool multi = argc > 2 && std::string(argv[2]) == std::string("multi");
+        bool ccw = argc > 3 && std::string(argv[3]) == std::string("ccw");
+        bool single_selftangent = false; // keep false, true does not work!
 
-        //test_all<float>();
-        test_all<double>(true, false, svg);
+        // template par's are: CoordinateType, Clockwise, Closed
+        if (ccw)
+        {
+            test_all<double, false, true>(multi, single_selftangent, svg);
+        }
+        else
+        {
+            test_all<double, true, true>(multi, single_selftangent, svg);
+        }
         //test_all<long double>();
     }
     catch(std::exception const& e)
Modified: sandbox/geometry/libs/geometry/test/algorithms/overlay/robustness/recursive_polygons.cpp
==============================================================================
--- sandbox/geometry/libs/geometry/test/algorithms/overlay/robustness/recursive_polygons.cpp	(original)
+++ sandbox/geometry/libs/geometry/test/algorithms/overlay/robustness/recursive_polygons.cpp	2010-12-21 16:44:38 EST (Tue, 21 Dec 2010)
@@ -26,14 +26,13 @@
 
 #include <boost/geometry/geometry.hpp>
 #include <boost/geometry/multi/multi.hpp>
-//#include <boost/geometry/multi/algorithms/detail/overlay/assemble.hpp>
 #include <boost/geometry/multi/geometries/multi_polygon.hpp>
 #include <boost/geometry/extensions/gis/io/wkt/wkt.hpp>
 #include <boost/geometry/extensions/io/svg/svg_mapper.hpp>
 
 
 template <typename Polygon, typename Generator>
-inline void make_box(Polygon& polygon, Generator& generator)
+inline void make_polygon(Polygon& polygon, Generator& generator)
 {
     typedef typename bg::point_type<Polygon>::type point_type;
     typedef typename bg::coordinate_type<Polygon>::type coordinate_type;
@@ -76,8 +75,10 @@
     {
         p.resize(1);
         q.resize(1);
-        make_box(p.front(), generator);
-        make_box(q.front(), generator);
+        make_polygon(p.front(), generator);
+        make_polygon(q.front(), generator);
+        bg::correct(p);
+        bg::correct(q);
     }
     else
     {
@@ -112,11 +113,12 @@
     bg::unique(mp);
     //result = mp;
     bg::simplify(mp, result, 0.01);
+    bg::correct(mp);
     return true;
 }
 
 
-template <typename T>
+template <typename T, bool Clockwise>
 void test_all(int seed, int count, bool svg, int level)
 {
     boost::timer t;
@@ -131,7 +133,7 @@
 
     typedef bg::model::polygon
         <
-            bg::model::d2::point_xy<T>
+            bg::model::d2::point_xy<T>, Clockwise
             //, true, false
         > polygon;
     typedef bg::model::multi_polygon<polygon> mp;
@@ -153,6 +155,8 @@
 {
     try
     {
+        // Arguments:
+        // {count} {seed} {"svg"} {level}
         int count = argc > 1 ? boost::lexical_cast<int>(argv[1]) : 10;
         int seed = (argc > 2 && std::string(argv[2]) != std::string("#"))
             ? boost::lexical_cast<int>(argv[2])
@@ -162,7 +166,7 @@
             ? boost::lexical_cast<int>(argv[4]): 3;
 
         //test_all<float>(seed, count, svg, 1e-3);
-        test_all<double>(seed, count, svg, level);
+        test_all<double, false>(seed, count, svg, level);
 
 #if defined(HAVE_TTMATH)
    // test_recursive_boxes<ttmath_big>(selection, "t");
Modified: sandbox/geometry/libs/geometry/test/algorithms/overlay/robustness/test_overlay_p_q.hpp
==============================================================================
--- sandbox/geometry/libs/geometry/test/algorithms/overlay/robustness/test_overlay_p_q.hpp	(original)
+++ sandbox/geometry/libs/geometry/test/algorithms/overlay/robustness/test_overlay_p_q.hpp	2010-12-21 16:44:38 EST (Tue, 21 Dec 2010)
@@ -37,42 +37,35 @@
 
     typedef typename bg::coordinate_type<G1>::type coordinate_type;
     typedef typename bg::point_type<G1>::type point_type;
-    typedef bg::detail::overlay::turn_info<point_type> turn_type;
 
-    typedef bg::strategy_intersection
-        <
-            typename bg::cs_tag<point_type>::type,
-            G1,
-            G2,
-            turn_type,
-            CalculationType
-        > strategy;
-
-    std::vector<OutputType> out_i, out_u;
+    bg::model::multi_polygon<OutputType> out_i, out_u, out_d;
 
     CalculationType area_p = bg::area(p);
     CalculationType area_q = bg::area(q);
 
-    CalculationType area_i = 0;
-    CalculationType area_u = 0;
+    bg::intersection(p, q, out_i);
+    CalculationType area_i = bg::area(out_i);
 
-    bg::intersection_inserter<OutputType>(p, q, std::back_inserter(out_i), strategy());
-    for (typename std::vector<OutputType>::iterator it = out_i.begin();
-            it != out_i.end();
-            ++it)
-    {
-        area_i += bg::area(*it);
-    }
-    bg::union_inserter<OutputType>(p, q, std::back_inserter(out_u), strategy());
-    for (typename std::vector<OutputType>::iterator it = out_u.begin();
-            it != out_u.end();
-            ++it)
+    bg::union_(p, q, out_u);
+    CalculationType area_u = bg::area(out_u);
+
+    double sum = (area_p + area_q) - area_u - area_i;
+
+    bool wrong = std::abs(sum) > tolerance;
+
+#ifdef USE_DIFFERENCE
+    bg::difference(p, q, out_d);
+    CalculationType area_d = bg::area(out_d);
+    double sum_d = (area_u - area_q) - area_d;
+    bool wrong_d = std::abs(sum_d) > tolerance;
+    
+    if (wrong_d)
     {
-        area_u += bg::area(*it);
+        wrong = true;
     }
+#endif
+
 
-    double diff = (area_p + area_q) - area_u - area_i;
-    bool wrong = std::abs(diff) > tolerance;
     if (wrong || force_output)
     {
         if (wrong)
@@ -88,7 +81,11 @@
             << " area u: " << area_u
             << " area p: " << area_p
             << " area q: " << area_q
-            << " diff: " << diff
+            << " sum: " << sum
+#ifdef USE_DIFFERENCE
+            << " area d: " << area_d
+            << " sum d: " << sum_d
+#endif
             << std::endl
             << std::setprecision(20)
             << " p: " << bg::wkt(p) << std::endl
@@ -119,19 +116,23 @@
         mapper.map(q, "fill-opacity:0.3;fill:rgb(51,51,153);"
                 "stroke:rgb(51,51,153);stroke-width:3");
 
-        for (typename std::vector<OutputType>::const_iterator it = out_i.begin();
-                it != out_i.end(); ++it)
+        for (BOOST_AUTO(it, out_i.begin()); it != out_i.end(); ++it)
         {
             mapper.map(*it, "fill-opacity:0.1;stroke-opacity:0.4;fill:rgb(255,0,0);"
                     "stroke:rgb(255,0,0);stroke-width:4");
         }
-        for (typename std::vector<OutputType>::const_iterator it = out_u.begin();
-                it != out_u.end(); ++it)
+        for (BOOST_AUTO(it, out_u.begin()); it != out_u.end(); ++it)
         {
             mapper.map(*it, "fill-opacity:0.1;stroke-opacity:0.4;fill:rgb(255,0,0);"
                     "stroke:rgb(255,0,255);stroke-width:4");
-
         }
+#ifdef USE_DIFFERENCE
+        for (BOOST_AUTO(it, out_d.begin()); it != out_d.end(); ++it)
+        {
+            mapper.map(*it, "fill-opacity:0.1;stroke-opacity:0.4;fill:rgb(255,255,0);"
+                    "stroke:rgb(255,255,0);stroke-width:4");
+        }
+#endif
     }
     return result;
 }
Modified: sandbox/geometry/libs/geometry/test/algorithms/test_overlay.hpp
==============================================================================
--- sandbox/geometry/libs/geometry/test/algorithms/test_overlay.hpp	(original)
+++ sandbox/geometry/libs/geometry/test/algorithms/test_overlay.hpp	2010-12-21 16:44:38 EST (Tue, 21 Dec 2010)
@@ -27,6 +27,9 @@
     {"POLYGON((0 0,0 1,1 1,1 0,0 0))",
     "POLYGON((1 1,1 0,0 0,0 1,1 1))"};
 
+static std::string disjoint[2] =
+    {"POLYGON((3 0,3 1,4 1,4 0,3 0))",
+    "POLYGON((3 4,3 5,4 5,4 4,3 4))"};
 
 static std::string new_hole[2] =
     {"POLYGON((2 2,2 5,5 5,5 2,2 2))",
Modified: sandbox/geometry/libs/geometry/test/algorithms/union.cpp
==============================================================================
--- sandbox/geometry/libs/geometry/test/algorithms/union.cpp	(original)
+++ sandbox/geometry/libs/geometry/test/algorithms/union.cpp	2010-12-21 16:44:38 EST (Tue, 21 Dec 2010)
@@ -61,6 +61,10 @@
     test_one<Polygon, Polygon, Polygon>("identical",
         identical[0], identical[1], 1, 0, 5, 1.0);
 
+    // disjoint
+    test_one<Polygon, Polygon, Polygon>("disjoint",
+        disjoint[0], disjoint[1], 2, 0, 10, 2.0);
+
     // inside each other, having intersections; holes separate intersections
     test_one<Polygon, Polygon, Polygon>("intersect_holes_intersect",
         intersect_holes_intersect[0], intersect_holes_intersect[1],
@@ -223,8 +227,10 @@
     typedef bg::model::box<P> box;
 
     test_areal<ring, polygon>();
+
     // Open
     test_areal<bg::model::linear_ring<P, true, false>, bg::model::polygon<P, true, false> >();
+
     // Counter clockwise
     test_areal<bg::model::linear_ring<P, false>, bg::model::polygon<P, false> >();
 
Modified: sandbox/geometry/libs/geometry/test/geometries/custom_linestring.cpp
==============================================================================
--- sandbox/geometry/libs/geometry/test/geometries/custom_linestring.cpp	(original)
+++ sandbox/geometry/libs/geometry/test/geometries/custom_linestring.cpp	2010-12-21 16:44:38 EST (Tue, 21 Dec 2010)
@@ -45,7 +45,9 @@
 // by specializing the "use_std" traits to false.
 // It should therefore implement the traits:: clear / append_point
 template <typename P>
-struct custom_linestring2 : std::deque<P> {};
+struct custom_linestring2 : std::deque<P> // std::pair<typename std::vector<P>::const_iterator, typename std::vector<P>::const_iterator> 
+{
+};
 
 namespace boost { namespace geometry { namespace traits {
     template <typename P>
Modified: sandbox/geometry/libs/geometry/test/multi/algorithms/multi_intersection.cpp
==============================================================================
--- sandbox/geometry/libs/geometry/test/multi/algorithms/multi_intersection.cpp	(original)
+++ sandbox/geometry/libs/geometry/test/multi/algorithms/multi_intersection.cpp	2010-12-21 16:44:38 EST (Tue, 21 Dec 2010)
@@ -150,7 +150,7 @@
     typedef bg::model::linear_ring<P, true, false> ring_open;
     typedef bg::model::polygon<P, true, false> polygon_open;
     typedef bg::model::multi_polygon<polygon_open> multi_polygon_open;
-    // TODO: enable next combination (bug somewhere in get_turns with open polygon)
+    // TODO: fix next combination (bug somewhere in probably assemble, with open polygon)
     //test_areal<ring_open, polygon_open, multi_polygon_open>();
     
     test_areal_clip<polygon, multi_polygon, box>();