Imported Upstream version 1.57.0
[platform/upstream/boost.git] / libs / geometry / test / robustness / overlay / buffer / recursive_polygons_buffer.cpp
index e54260f..737f22c 100644 (file)
 #include <boost/geometry/geometries/point_xy.hpp>
 #include <boost/geometry/multi/geometries/multi_geometries.hpp>
 
-#include <boost/geometry/extensions/io/svg/svg_mapper.hpp>
-#include <boost/geometry/extensions/algorithms/midpoints.hpp>
-
-#include <boost/geometry/extensions/algorithms/buffer/buffer_inserter.hpp>
-
-#include <boost/geometry/multi/multi.hpp> // TODO: more specific
-#include <boost/geometry/extensions/algorithms/buffer/multi_buffer_inserter.hpp>
-
-#include <boost/geometry/extensions/strategies/buffer.hpp>
+#include <boost/geometry/algorithms/detail/buffer/buffer_inserter.hpp>
 
+#include <boost/geometry/strategies/buffer.hpp>
 
 #include <common/common_settings.hpp>
 #include <common/make_square_polygon.hpp>
@@ -45,8 +38,8 @@
 
 struct buffer_settings : public common_settings
 {
-       int join_code;
-       double distance;
+    int join_code;
+    double distance;
 };
 
 namespace bg = boost::geometry;
@@ -89,28 +82,28 @@ bool verify(std::string const& caseid, MultiPolygon const& mp, MultiPolygon cons
 {
     bool result = true;
 
-       // Area of buffer must be larger than of original polygon
-       BOOST_AUTO(area_mp, bg::area(mp));
-       BOOST_AUTO(area_buf, bg::area(buffer));
-
-       if (area_buf < area_mp)
-       {
-               result = false;
-       }
-
-       if (result)
-       {
-               typedef boost::range_value<MultiPolygon const>::type polygon_type;
-               BOOST_FOREACH(polygon_type const& polygon, mp)
-               {
-                       typename bg::point_type<polygon_type>::type point;
-                       bg::point_on_border(point, polygon);
-                       if (! bg::within(point, buffer))
-                       {
-                               result = false;
-                       }
-               }
-       }
+    // Area of buffer must be larger than of original polygon
+    BOOST_AUTO(area_mp, bg::area(mp));
+    BOOST_AUTO(area_buf, bg::area(buffer));
+
+    if (area_buf < area_mp)
+    {
+        result = false;
+    }
+
+    if (result)
+    {
+        typedef typename boost::range_value<MultiPolygon const>::type polygon_type;
+        BOOST_FOREACH(polygon_type const& polygon, mp)
+        {
+            typename bg::point_type<polygon_type>::type point;
+            bg::point_on_border(point, polygon);
+            if (! bg::within(point, buffer))
+            {
+                result = false;
+            }
+        }
+    }
 
     bool svg = settings.svg;
     bool wkt = settings.wkt;
@@ -123,10 +116,10 @@ bool verify(std::string const& caseid, MultiPolygon const& mp, MultiPolygon cons
         wkt = true;
     }
 
-       if (svg || wkt)
-       {
-               //std::cout << caseid << std::endl;
-       }
+    if (svg || wkt)
+    {
+        //std::cout << caseid << std::endl;
+    }
 
     if (svg)
     {
@@ -190,48 +183,53 @@ bool test_buffer(MultiPolygon& result, int& index,
     bg::unique(mp);
     bg::unique(mp);
     bg::correct(mp);
-       result = mp;
+    result = mp;
 
 
     typedef typename bg::coordinate_type<MultiPolygon>::type coordinate_type;
     typedef typename bg::point_type<MultiPolygon>::type point_type;
-    typedef bg::strategy::buffer::distance_assymetric<coordinate_type> distance_strategy_type;
+    typedef bg::strategy::buffer::distance_asymmetric<coordinate_type> distance_strategy_type;
     distance_strategy_type distance_strategy(settings.distance, settings.distance);
 
-    typedef bg::strategy::buffer::join_round<point_type, point_type> join_strategy_type;
-    join_strategy_type join_strategy;
-
     typedef typename boost::range_value<MultiPolygon>::type polygon_type;
     MultiPolygon buffered;
 
     std::ostringstream out;
     out << "recursive_polygons_buffer_" << index++ << "_" << level;
 
-       try
-       {
-               switch(settings.join_code)
-               {
-                       case 1 :
-                               bg::buffer_inserter<polygon_type>(mp, std::back_inserter(buffered),
-                                                               distance_strategy, 
-                                                               bg::strategy::buffer::join_round<point_type, point_type>());
-                               break;
-                       case 2 :
-                               bg::buffer_inserter<polygon_type>(mp, std::back_inserter(buffered),
-                                                               distance_strategy, 
-                                                               bg::strategy::buffer::join_miter<point_type, point_type>());
-                               break;
-                       default :
-                               return false;
-               }
-       }
+    bg::strategy::buffer::end_round end_strategy;
+    bg::strategy::buffer::point_circle point_strategy;
+    bg::strategy::buffer::side_straight side_strategy;
+    bg::strategy::buffer::join_round join_round_strategy(100); // Compatible with unit tests
+    bg::strategy::buffer::join_miter join_miter_strategy;
+
+    try
+    {
+        switch(settings.join_code)
+        {
+            case 1 :
+                bg::buffer(mp, buffered,
+                                distance_strategy, side_strategy,
+                                join_round_strategy,
+                                end_strategy, point_strategy);
+                break;
+            case 2 :
+                bg::buffer(mp, buffered,
+                                distance_strategy, side_strategy,
+                                join_miter_strategy,
+                                end_strategy, point_strategy);
+                break;
+            default :
+                return false;
+        }
+    }
     catch(std::exception const& e)
     {
-               MultiPolygon empty;
-               std::cout << out.str() << std::endl;
+        MultiPolygon empty;
+        std::cout << out.str() << std::endl;
         std::cout << "Exception " << e.what() << std::endl;
-           verify(out.str(), mp, empty, settings);
-               return false;
+        verify(out.str(), mp, empty, settings);
+        return false;
     }
 
 
@@ -309,14 +307,14 @@ int main(int argc, char** argv)
         if (varmap.count("help")
             || (form != "box" && form != "triangle")
             || (join != "round" && join != "miter")
-                       )
+            )
         {
             std::cout << description << std::endl;
             return 1;
         }
 
         settings.triangular = form != "box";
-               settings.join_code = join == "round" ? 1 : 2;
+        settings.join_code = join == "round" ? 1 : 2;
 
         if (ccw && open)
         {