]> git.proxmox.com Git - ceph.git/blobdiff - ceph/src/boost/libs/geometry/test/robustness/overlay/buffer/recursive_polygons_buffer.cpp
import quincy beta 17.1.0
[ceph.git] / ceph / src / boost / libs / geometry / test / robustness / overlay / buffer / recursive_polygons_buffer.cpp
index cd7f57ac260b1cba2ed258b95dc4985f4b7e66cc..f7843434791b2896ff95543810d4982d4c4d58bf 100644 (file)
@@ -1,7 +1,7 @@
 // Boost.Geometry (aka GGL, Generic Geometry Library)
 // Robustness Test
 
-// Copyright (c) 2012-2015 Barend Gehrels, Amsterdam, the Netherlands.
+// Copyright (c) 2012-2020 Barend Gehrels, Amsterdam, the Netherlands.
 
 // This file was modified by Oracle on 2015.
 // Modifications copyright (c) 2015 Oracle and/or its affiliates.
 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
 // http://www.boost.org/LICENSE_1_0.txt)
 
+#define BOOST_GEOMETRY_NO_BOOST_TEST
+
 #if defined(_MSC_VER)
 #  pragma warning( disable : 4244 )
 #  pragma warning( disable : 4267 )
 #endif
 
+#include <chrono>
 #include <fstream>
 #include <sstream>
 
@@ -26,7 +29,6 @@
 #include <boost/random/uniform_int.hpp>
 #include <boost/random/uniform_real.hpp>
 #include <boost/random/variate_generator.hpp>
-#include <boost/timer.hpp>
 
 #include <boost/geometry.hpp>
 #include <boost/geometry/geometries/geometries.hpp>
@@ -36,6 +38,7 @@
 
 #include <boost/geometry/strategies/buffer.hpp>
 
+#include <geometry_test_common.hpp>
 #include <common/common_settings.hpp>
 #include <common/make_square_polygon.hpp>
 
@@ -87,14 +90,15 @@ bool verify(std::string const& caseid, MultiPolygon const& mp, MultiPolygon cons
     bool result = true;
 
     // Area of buffer must be larger than of original polygon
-    double area_mp = bg::area(mp);
-    double area_buf = bg::area(buffer);
+    auto const area_mp = bg::area(mp);
+    auto const area_buf = bg::area(buffer);
 
     if (area_buf < area_mp)
     {
         result = false;
     }
 
+    // Verify if all points are IN the buffer
     if (result)
     {
         typedef typename boost::range_value<MultiPolygon const>::type polygon_type;
@@ -109,12 +113,13 @@ bool verify(std::string const& caseid, MultiPolygon const& mp, MultiPolygon cons
         }
     }
 
-    if (result)
+    if (result && settings.check_validity)
     {
-        std::string message;
-        if (! bg::is_valid(buffer, message))
+        bg::validity_failure_type failure;
+        if (! bg::is_valid(buffer, failure)
+            && failure != bg::failure_intersecting_interiors)
         {
-            std::cout << "Buffer is not valid: " << message << std::endl;
+            std::cout << "Buffer is not valid: " << bg::validity_failure_type_message(failure) << std::endl;
             result = false;
         }
     }
@@ -123,23 +128,19 @@ bool verify(std::string const& caseid, MultiPolygon const& mp, MultiPolygon cons
     bool wkt = settings.wkt;
     if (! result)
     {
-        std::cout << "ERROR " << caseid << std::endl;
-        //std::cout << bg::wkt(mp) << std::endl;
-        //std::cout << bg::wkt(buffer) << std::endl;
+        // The result is wrong, override settings to create a SVG and WKT
         svg = true;
         wkt = true;
     }
 
-    if (svg || wkt)
-    {
-        //std::cout << caseid << std::endl;
-    }
-
     if (svg)
     {
         std::ostringstream filename;
         filename << caseid << "_"
-            << typeid(typename bg::coordinate_type<MultiPolygon>::type).name()
+            << string_from_type<typename bg::coordinate_type<MultiPolygon>::type>::name()
+#if defined(BOOST_GEOMETRY_USE_RESCALING)
+            << "_rescaled"
+#endif
             << ".svg";
         create_svg(filename.str(), mp, buffer);
     }
@@ -252,7 +253,7 @@ bool test_buffer(MultiPolygon& result, int& index,
 template <typename T, bool Clockwise, bool Closed, typename Settings>
 void test_all(int seed, int count, int level, Settings const& settings)
 {
-    boost::timer t;
+    auto const t0 = std::chrono::high_resolution_clock::now();
 
     typedef boost::minstd_rand base_generator_type;
 
@@ -270,23 +271,32 @@ void test_all(int seed, int count, int level, Settings const& settings)
 
 
     int index = 0;
+    int errors = 0;
     for(int i = 0; i < count; i++)
     {
         mp p;
-        test_buffer<mp>(p, index, coordinate_generator, level, settings);
+        if (! test_buffer<mp>(p, index, coordinate_generator, level, settings))
+        {
+            errors++;
+        }
     }
+
+    auto const t = std::chrono::high_resolution_clock::now();
+    auto const elapsed_ms = std::chrono::duration_cast<std::chrono::milliseconds>(t - t0).count();
     std::cout
         << "geometries: " << index
-        << " type: " << typeid(T).name()
-        << " time: " << t.elapsed()  << std::endl;
+        << " errors: " << errors
+        << " type: " << string_from_type<T>::name()
+        << " time: " << elapsed_ms / 1000.0 << std::endl;
 }
 
 int main(int argc, char** argv)
 {
+    BoostGeometryWriteTestConfiguration();
     try
     {
         namespace po = boost::program_options;
-        po::options_description description("=== recursive_polygons_linear_areal ===\nAllowed options");
+        po::options_description description("=== recursive_polygons_buffer ===\nAllowed options");
 
         int count = 1;
         int seed = static_cast<unsigned int>(std::time(0));
@@ -301,6 +311,7 @@ int main(int argc, char** argv)
             ("help", "Help message")
             ("seed", po::value<int>(&seed), "Initialization seed for random generator")
             ("count", po::value<int>(&count)->default_value(1), "Number of tests")
+            ("validity", po::value<bool>(&settings.check_validity)->default_value(true), "Include testing on validity")
             ("level", po::value<int>(&level)->default_value(3), "Level to reach (higher->slower)")
             ("distance", po::value<double>(&settings.distance)->default_value(1.0), "Distance (1.0)")
             ("form", po::value<std::string>(&form)->default_value("box"), "Form of the polygons (box, triangle)")
@@ -330,24 +341,20 @@ int main(int argc, char** argv)
 
         if (ccw && open)
         {
-            test_all<double, false, false>(seed, count, level, settings);
+            test_all<default_test_type, false, false>(seed, count, level, settings);
         }
         else if (ccw)
         {
-            test_all<double, false, true>(seed, count, level, settings);
+            test_all<default_test_type, false, true>(seed, count, level, settings);
         }
         else if (open)
         {
-            test_all<double, true, false>(seed, count, level, settings);
+            test_all<default_test_type, true, false>(seed, count, level, settings);
         }
         else
         {
-            test_all<double, true, true>(seed, count, level, settings);
+            test_all<default_test_type, true, true>(seed, count, level, settings);
         }
-
-#if defined(HAVE_TTMATH)
-        // test_all<ttmath_big, true, true>(seed, count, max, svg, level);
-#endif
     }
     catch(std::exception const& e)
     {