Imported Upstream version 1.57.0
[platform/upstream/boost.git] / libs / geometry / test / algorithms / overlay / traverse.cpp
index cebd8b0..1fb7123 100644 (file)
@@ -7,9 +7,10 @@
 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
 // http://www.boost.org/LICENSE_1_0.txt)
 
-#define BOOST_GEOMETRY_TEST_ONLY_ONE_TYPE
-// #define BOOST_GEOMETRY_OVERLAY_NO_THROW
-// #define TEST_WITH_SVG
+#define BOOST_GEOMETRY_DEFINE_STREAM_OPERATOR_SEGMENT_RATIO
+//#define BOOST_GEOMETRY_TEST_ONLY_ONE_TYPE
+//#define BOOST_GEOMETRY_OVERLAY_NO_THROW
+//#define HAVE_TTMATH
 
 #include <iostream>
 #include <iomanip>
@@ -20,7 +21,7 @@
 #include <boost/type_traits/is_same.hpp>
 
 #ifdef HAVE_TTMATH
-#  include <boost/geometry/extensions/contrib/ttmath_stub.hpp>
+#  include <boost/geometry/contrib/ttmath_stub.hpp>
 #endif
 
 #include <geometry_test_common.hpp>
@@ -42,7 +43,6 @@
 #include <boost/geometry/algorithms/detail/overlay/turn_info.hpp>
 #include <boost/geometry/algorithms/detail/overlay/enrichment_info.hpp>
 #include <boost/geometry/algorithms/detail/overlay/traversal_info.hpp>
-#include <boost/geometry/algorithms/detail/overlay/calculate_distance_policy.hpp>
 
 #include <boost/geometry/algorithms/detail/overlay/get_turns.hpp>
 #include <boost/geometry/algorithms/detail/overlay/enrich_intersection_points.hpp>
@@ -50,6 +50,7 @@
 
 #include <boost/geometry/algorithms/detail/overlay/debug_turn_info.hpp>
 
+#include <boost/geometry/policies/robustness/get_rescale_policy.hpp>
 
 #include <boost/geometry/algorithms/area.hpp>
 #include <boost/geometry/algorithms/correct.hpp>
@@ -61,7 +62,7 @@
 
 
 #if defined(TEST_WITH_SVG)
-#  include <boost/geometry/extensions/io/svg/svg_mapper.hpp>
+#  include <boost/geometry/io/svg/svg_mapper.hpp>
 #endif
 
 #include <boost/geometry/strategies/strategies.hpp>
@@ -73,6 +74,7 @@ static inline std::string operation(int d)
     return d == 1 ? "union" : "intersection";
 }
 
+
 namespace detail
 {
 
@@ -144,19 +146,26 @@ struct test_traverse
             typename bg::cs_tag<G1>::type
         >::type side_strategy_type;
 
+        typedef typename bg::point_type<G2>::type point_type;
+        typedef typename bg::rescale_policy_type<point_type>::type
+            rescale_policy_type;
+
+        rescale_policy_type rescale_policy
+                = bg::get_rescale_policy<rescale_policy_type>(g1, g2);
 
         typedef bg::detail::overlay::traversal_turn_info
-            <
-                typename bg::point_type<G2>::type
-            > turn_info;
+        <
+            point_type,
+            typename bg::segment_ratio_type<point_type, rescale_policy_type>::type
+        > turn_info;
         std::vector<turn_info> turns;
 
         bg::detail::get_turns::no_interrupt_policy policy;
-        bg::get_turns<Reverse1, Reverse2, bg::detail::overlay::calculate_distance_policy>(g1, g2, turns, policy);
+        bg::get_turns<Reverse1, Reverse2, bg::detail::overlay::assign_null_policy>(g1, g2, rescale_policy, turns, policy);
         bg::enrich_intersection_points<Reverse1, Reverse2>(turns,
                     Direction == 1 ? bg::detail::overlay::operation_union
                     : bg::detail::overlay::operation_intersection,
-            g1, g2, side_strategy_type());
+            g1, g2, rescale_policy, side_strategy_type());
 
         typedef bg::model::ring<typename bg::point_type<G2>::type> ring_type;
         typedef std::vector<ring_type> out_vector;
@@ -167,11 +176,12 @@ struct test_traverse
             <
                 Reverse1, Reverse2,
                 G1, G2
-            >::apply(g1, g2, Direction, turns, v);
+            >::apply(g1, g2, Direction, rescale_policy, turns, v);
 
         // Check number of resulting rings
         BOOST_CHECK_MESSAGE(expected_count == boost::size(v),
                 "traverse: " << id
+                << " (" << operation(Direction) << ")"
                 << " #shapes expected: " << expected_count
                 << " detected: " << boost::size(v)
                 << " type: " << string_from_type
@@ -225,7 +235,7 @@ struct test_traverse
 
             BOOST_FOREACH(turn_info const& turn, turns)
             {
-                int lineheight = 10;
+                int lineheight = 8;
                 mapper.map(turn.point, "fill:rgb(255,128,0);"
                         "stroke:rgb(0,0,0);stroke-width:1", 3);
 
@@ -241,7 +251,7 @@ struct test_traverse
                             boost::numeric_cast<int>(half
                                 + ten * bg::get<1>(turn.point))
                             );
-                std::string style =  "fill:rgb(0,0,0);font-family:Arial;font-size:10px";
+                std::string style =  "fill:rgb(0,0,0);font-family:Arial;font-size:8px";
 
                 if (turn.discarded)
                 {
@@ -261,6 +271,9 @@ struct test_traverse
                         << (turn.is_discarded() ? " (discarded) " : turn.blocked() ? " (blocked)" : "")
                         << std::endl;
 
+                    out << "r: " << turn.operations[0].fraction
+                        << " ; " << turn.operations[1].fraction
+                        << std::endl;
                     if (turn.operations[0].enriched.next_ip_index != -1)
                     {
                         out << "ip: " << turn.operations[0].enriched.next_ip_index;
@@ -270,7 +283,7 @@ struct test_traverse
                         out << "vx: " << turn.operations[0].enriched.travels_to_vertex_index
                          << " -> ip: "  << turn.operations[0].enriched.travels_to_ip_index;
                     }
-                    out << " ";
+                    out << " ";
                     if (turn.operations[1].enriched.next_ip_index != -1)
                     {
                         out << "ip: " << turn.operations[1].enriched.next_ip_index;
@@ -321,9 +334,9 @@ struct test_traverse
                             << std::endl
 
                             << std::setprecision(3)
-                            << "dist: " << turn.operations[0].enriched.distance
-                            << " / "  << turn.operations[1].enriched.distance
-                            << std::endl
+                            << "dist: " << turn.operations[0].fraction
+                            << " / "  << turn.operations[1].fraction
+                            << std::endl;
                             */
 
 
@@ -410,7 +423,7 @@ void test_all(bool test_self_tangencies = true, bool test_mixed = false)
 
     typedef bg::model::point<T, 2, bg::cs::cartesian> P;
     typedef bg::model::polygon<P> polygon;
-    typedef bg::model::box<P> box;
+    //typedef bg::model::box<P> box;
 
     // 1-6
     test_traverse<polygon, polygon, operation_intersection>::apply("1", 1, 5.4736, case_1[0], case_1[1]);
@@ -633,8 +646,7 @@ void test_all(bool test_self_tangencies = true, bool test_mixed = false)
             2, 16, case_53[0], case_53[2]);
     if (test_self_tangencies)
     {
-        // The st_st version might generate one ring with area zero, which is OK
-        test_traverse<polygon, polygon, operation_union>::apply("54_st_st", 3, 20, case_54[0], case_54[2]);
+        test_traverse<polygon, polygon, operation_union>::apply("54_st_st", 2, 20, case_54[0], case_54[2]);
         test_traverse<polygon, polygon, operation_union>::apply("54_st_iet", 2, 20, case_54[0], case_54[3]);
         test_traverse<polygon, polygon, operation_union>::apply("54_iet_st", 2, 20, case_54[1], case_54[2]);
     }
@@ -685,9 +697,12 @@ void test_all(bool test_self_tangencies = true, bool test_mixed = false)
     test_traverse<polygon, polygon, operation_union>::apply("72",
         1, 10.65, case_72[0], case_72[1]);
 
-
-
     // other
+    test_traverse<polygon, polygon, operation_union>::apply("box_poly5",
+            2, 4.7191,
+            "POLYGON((1.5 1.5, 1.5 2.5, 4.5 2.5, 4.5 1.5, 1.5 1.5))",
+            "POLYGON((2 1.3,2.4 1.7,2.8 1.8,3.4 1.2,3.7 1.6,3.4 2,4.1 2.5,4.5 2.5,4.5 2.3,5.0 2.3,5.0 2.1,4.5 2.1,4.5 1.9,4.0 1.9,4.5 1.2,4.9 0.8,2.9 0.7,2 1.3))");
+
     test_traverse<polygon, polygon, operation_intersection>::apply("collinear_overlaps",
         1, 24,
         collinear_overlaps[0], collinear_overlaps[1]);
@@ -729,9 +744,6 @@ void test_all(bool test_self_tangencies = true, bool test_mixed = false)
 
     static const bool is_float
         = boost::is_same<T, float>::value;
-    static const bool is_double
-        = boost::is_same<T, double>::value
-        || boost::is_same<T, long double>::value;
 
     static const double float_might_deviate_more = is_float ? 0.1 : 0.001; // In some cases up to 1 promille permitted
 
@@ -786,19 +798,20 @@ void test_all(bool test_self_tangencies = true, bool test_mixed = false)
     // the chance is 50% that the segments are not sorted correctly and the wrong
     // decision is taken.
     // Solved now (by sorting on sides in those cases)
+    if (! is_float_on_non_msvc)
     {
         test_traverse<polygon, polygon, operation_intersection>::apply("dz_1",
-                3, 16.887537949472005, dz_1[0], dz_1[1]);
+                2, 16.887537949472005, dz_1[0], dz_1[1]);
         test_traverse<polygon, polygon, operation_union>::apply("dz_1",
                 3, 1444.2621305732864, dz_1[0], dz_1[1]);
 
         test_traverse<polygon, polygon, operation_intersection>::apply("dz_2",
                 2, 68.678921274288541, dz_2[0], dz_2[1]);
         test_traverse<polygon, polygon, operation_union>::apply("dz_2",
-                2, 1505.4202304878663, dz_2[0], dz_2[1]);
+                1, 1505.4202304878663, dz_2[0], dz_2[1]);
 
         test_traverse<polygon, polygon, operation_intersection>::apply("dz_3",
-                6, 192.49316937645651, dz_3[0], dz_3[1]);
+                5, 192.49316937645651, dz_3[0], dz_3[1]);
         test_traverse<polygon, polygon, operation_union>::apply("dz_3",
                 6, 1446.496005965641, dz_3[0], dz_3[1]);
 
@@ -812,18 +825,15 @@ void test_all(bool test_self_tangencies = true, bool test_mixed = false)
 
     // SNL (Subsidiestelsel Natuur & Landschap - verAANnen)
 
-    if (! is_float_on_non_msvc)
-    {
-        test_traverse<polygon, polygon, operation_intersection>::apply("snl-1",
-            2, 286.996062095888,
-            snl_1[0], snl_1[1],
-            float_might_deviate_more);
-
-        test_traverse<polygon, polygon, operation_union>::apply("snl-1",
-            2, 51997.5408506132,
-            snl_1[0], snl_1[1],
-            float_might_deviate_more);
-    }
+    test_traverse<polygon, polygon, operation_intersection>::apply("snl-1",
+        2, 286.996062095888,
+        snl_1[0], snl_1[1],
+        float_might_deviate_more);
+
+    test_traverse<polygon, polygon, operation_union>::apply("snl-1",
+        2, 51997.5408506132,
+        snl_1[0], snl_1[1],
+        float_might_deviate_more);
 
     {
         test_traverse<polygon, polygon, operation_intersection>::apply("isov",
@@ -834,113 +844,94 @@ void test_all(bool test_self_tangencies = true, bool test_mixed = false)
                 float_might_deviate_more);
     }
 
-    // GEOS tests
-    if (! is_float)
-    {
-        test_traverse<polygon, polygon, operation_intersection>::apply("geos_1_test_overlay",
-                1, 3461.02330171138, geos_1_test_overlay[0], geos_1_test_overlay[1]);
-        test_traverse<polygon, polygon, operation_union>::apply("geos_1_test_overlay",
-                1, 3461.31592235516, geos_1_test_overlay[0], geos_1_test_overlay[1]);
-
-        if (! is_double)
-        {
-            test_traverse<polygon, polygon, operation_intersection>::apply("geos_2",
-                    2, 2.157e-6, // by bg/ttmath; sql server reports: 2.20530228034477E-06
-                    geos_2[0], geos_2[1]);
-        }
-        test_traverse<polygon, polygon, operation_union>::apply("geos_2",
-                1, 350.550662845485,
-                geos_2[0], geos_2[1]);
-    }
-
-    if (! is_float && ! is_double)
-    {
-        test_traverse<polygon, polygon, operation_intersection>::apply("geos_3",
-                1, 2.484885e-7,
-                geos_3[0], geos_3[1]);
-    }
-
-    if (! is_float_on_non_msvc)
-    {
-        // Sometimes output is reported as 29229056
-        test_traverse<polygon, polygon, operation_union>::apply("geos_3",
-                1, 29391548.5,
-                geos_3[0], geos_3[1],
-                float_might_deviate_more);
-
-        // Sometimes output is reported as 0.078125
-        test_traverse<polygon, polygon, operation_intersection>::apply("geos_4",
-                1, 0.0836884926070727,
-                geos_4[0], geos_4[1],
-                float_might_deviate_more);
-    }
-
-    test_traverse<polygon, polygon, operation_union>::apply("geos_4",
-            1, 2304.41633605957,
-            geos_4[0], geos_4[1]);
-       
     if (! is_float)
     {
 
+/* TODO check this BSG 2013-09-24
 #if defined(_MSC_VER)
         double const expected = if_typed_tt<T>(3.63794e-17, 0.0);
+        int expected_count = if_typed_tt<T>(1, 0);
 #else
         double const expected = if_typed<T, long double>(2.77555756156289135106e-17, 0.0);
+        int expected_count = if_typed<T, long double>(1, 0);
 #endif
 
         // Calculate intersection/union of two triangles. Robustness case.
-        // ttmath can form a very small intersection triangle 
+        // ttmath can form a very small intersection triangle
         // (which is even not accomplished by SQL Server/PostGIS)
         std::string const caseid = "ggl_list_20110820_christophe";
-        test_traverse<polygon, polygon, operation_intersection>::apply(caseid, 
-            1, expected,
+        test_traverse<polygon, polygon, operation_intersection>::apply(caseid,
+            expected_count, expected,
             ggl_list_20110820_christophe[0], ggl_list_20110820_christophe[1]);
-        test_traverse<polygon, polygon, operation_union>::apply(caseid, 
-            1, 67.3550722317627, 
+        test_traverse<polygon, polygon, operation_union>::apply(caseid,
+            1, 67.3550722317627,
             ggl_list_20110820_christophe[0], ggl_list_20110820_christophe[1]);
+*/
     }
 
-    test_traverse<polygon, polygon, operation_union>::apply("buffer_rt_f", 
-        1, 4.60853, 
-        buffer_rt_f[0], buffer_rt_f[1]);
-    test_traverse<polygon, polygon, operation_intersection>::apply("buffer_rt_f", 
-        1, 0.0002943725152286, 
+    test_traverse<polygon, polygon, operation_union>::apply("buffer_rt_f",
+        1, 4.60853,
         buffer_rt_f[0], buffer_rt_f[1]);
+    test_traverse<polygon, polygon, operation_intersection>::apply("buffer_rt_f",
+        1, 0.0002943725152286,
+        buffer_rt_f[0], buffer_rt_f[1], 0.01);
 
-    test_traverse<polygon, polygon, operation_union>::apply("buffer_rt_g", 
-        1, 16.571, 
+    test_traverse<polygon, polygon, operation_union>::apply("buffer_rt_g",
+        1, 16.571,
         buffer_rt_g[0], buffer_rt_g[1]);
 
-    test_traverse<polygon, polygon, operation_union>::apply("buffer_rt_g_boxes1", 
-        1, 20, 
+    test_traverse<polygon, polygon, operation_union>::apply("buffer_rt_g_boxes1",
+        1, 20,
         buffer_rt_g_boxes[0], buffer_rt_g_boxes[1]);
-    test_traverse<polygon, polygon, operation_union>::apply("buffer_rt_g_boxes2", 
-        1, 24, 
+    test_traverse<polygon, polygon, operation_union>::apply("buffer_rt_g_boxes2",
+        1, 24,
         buffer_rt_g_boxes[0], buffer_rt_g_boxes[2]);
-    test_traverse<polygon, polygon, operation_union>::apply("buffer_rt_g_boxes3", 
-        1, 28, 
+    test_traverse<polygon, polygon, operation_union>::apply("buffer_rt_g_boxes3",
+        1, 28,
         buffer_rt_g_boxes[0], buffer_rt_g_boxes[3]);
 
-    test_traverse<polygon, polygon, operation_union>::apply("buffer_rt_g_boxes43", 
-        1, 30, 
+    test_traverse<polygon, polygon, operation_union>::apply("buffer_rt_g_boxes43",
+        1, 30,
         buffer_rt_g_boxes[4], buffer_rt_g_boxes[3]);
 
+    test_traverse<polygon, polygon, operation_union>::apply("buffer_rt_l",
+        1, 19.3995, buffer_rt_l[0], buffer_rt_l[1]);
+
+    test_traverse<polygon, polygon, operation_union>::apply("buffer_mp2",
+            1, 36.7535642, buffer_mp2[0], buffer_mp2[1], 0.01);
+    test_traverse<polygon, polygon, operation_union>::apply("collinear_opposite_rr",
+            1, 6.41, collinear_opposite_right[0], collinear_opposite_right[1]);
+    test_traverse<polygon, polygon, operation_union>::apply("collinear_opposite_ll",
+            1, 11.75, collinear_opposite_left[0], collinear_opposite_left[1]);
+    test_traverse<polygon, polygon, operation_union>::apply("collinear_opposite_ss",
+            1, 6, collinear_opposite_straight[0], collinear_opposite_straight[1]);
+    test_traverse<polygon, polygon, operation_union>::apply("collinear_opposite_lr",
+            1, 8.66, collinear_opposite_left[0], collinear_opposite_right[1]);
+    test_traverse<polygon, polygon, operation_union>::apply("collinear_opposite_rl",
+            1, 9, collinear_opposite_right[0], collinear_opposite_left[1]);
+
+    test_traverse<polygon, polygon, operation_intersection>::apply("ticket_7462", 1, 0.220582, ticket_7462[0], ticket_7462[1]);
+
+    test_traverse<polygon, polygon, operation_intersection>::apply
+        ("ticket_9081_15", 1, 0.006889578,
+            ticket_9081_15[0], ticket_9081_15[1]);
+
 #ifdef BOOST_GEOMETRY_OVERLAY_NO_THROW
     {
         // NOTE: currently throws (normally)
         std::string caseid = "ggl_list_20120229_volker";
-        test_traverse<polygon, polygon, operation_union>::apply(caseid, 
-            1, 99, 
+        test_traverse<polygon, polygon, operation_union>::apply(caseid,
+            1, 99,
             ggl_list_20120229_volker[0], ggl_list_20120229_volker[1]);
-        test_traverse<polygon, polygon, operation_intersection>::apply(caseid, 
-            1, 99, 
+        test_traverse<polygon, polygon, operation_intersection>::apply(caseid,
+            1, 99,
             ggl_list_20120229_volker[0], ggl_list_20120229_volker[1]);
         caseid = "ggl_list_20120229_volker_2";
-        test_traverse<polygon, polygon, operation_union>::apply(caseid, 
-            1, 99, 
+        test_traverse<polygon, polygon, operation_union>::apply(caseid,
+            1, 99,
             ggl_list_20120229_volker[2], ggl_list_20120229_volker[1]);
-        test_traverse<polygon, polygon, operation_intersection>::apply(caseid, 
-            1, 99, 
+        test_traverse<polygon, polygon, operation_intersection>::apply(caseid,
+            1, 99,
             ggl_list_20120229_volker[2], ggl_list_20120229_volker[1]);
     }
 #endif