diff --git a/test/algorithms/intersection.cpp b/test/algorithms/intersection.cpp index e313f39fb..5610e6c67 100644 --- a/test/algorithms/intersection.cpp +++ b/test/algorithms/intersection.cpp @@ -15,7 +15,10 @@ #include #include +//#define BOOST_GEOMETRY_DEBUG_SEGMENT_IDENTIFIER +//#define BOOST_GEOMETRY_DEBUG_INTERSECTION //#define BOOST_GEOMETRY_DEBUG_TRAVERSE +//#define BOOST_GEOMETRY_DEBUG_FOLLOW //#define BOOST_GEOMETRY_DEBUG_ASSEMBLE //#define BOOST_GEOMETRY_DEBUG_IDENTIFIER @@ -287,17 +290,33 @@ template void test_polygon_linestring() { std::string const poly_simplex = "POLYGON((1 1,1 3,3 3,3 1,1 1))"; - test_one("simplex", poly_simplex, "LINESTRING(0 2,4 2)", 1, 2, 2.0); - test_one("case2", poly_simplex, "LINESTRING(0 1,4 3)", 1, 2, sqrt(5.0)); - test_one("case3", "POLYGON((2 0,2 5,5 5,5 0,2 0))", "LINESTRING(0 1,1 2,3 2,4 3,6 3,7 4)", 1, 4, 2 + sqrt(2.0)); - test_one("case4", "POLYGON((0 0,0 4,2 4,2 0,0 0))", "LINESTRING(1 1,3 2,1 3)", 2, 4, sqrt(5.0)); + std::string const poly_9 = "POLYGON((1 1,1 4,4 4,4 1,1 1))"; - test_one("case5", poly_simplex, "LINESTRING(0 1,3 4)", 1, 2, sqrt(2.0)); - test_one("case6", "POLYGON((2 0,2 4,3 4,3 1,4 1,4 3,5 3,5 1,6 1,6 3,7 3,7 1,8 1,8 3,9 3,9 0,2 0))", "LINESTRING(1 1,10 3)", 4, 8, + test_one_lp("simplex", poly_simplex, "LINESTRING(0 2,4 2)", 1, 2, 2.0); + test_one_lp("case2", poly_simplex, "LINESTRING(0 1,4 3)", 1, 2, sqrt(5.0)); + test_one_lp("case3", "POLYGON((2 0,2 5,5 5,5 0,2 0))", "LINESTRING(0 1,1 2,3 2,4 3,6 3,7 4)", 1, 4, 2 + sqrt(2.0)); + test_one_lp("case4", "POLYGON((0 0,0 4,2 4,2 0,0 0))", "LINESTRING(1 1,3 2,1 3)", 2, 4, sqrt(5.0)); + + test_one_lp("case5", poly_simplex, "LINESTRING(0 1,3 4)", 1, 2, sqrt(2.0)); + test_one_lp("case6", "POLYGON((2 0,2 4,3 4,3 1,4 1,4 3,5 3,5 1,6 1,6 3,7 3,7 1,8 1,8 3,9 3,9 0,2 0))", "LINESTRING(1 1,10 3)", 4, 8, // Pieces are 1 x 2/9: 4.0 * sqrt(1.0 + 4.0/81.0)); - test_one("case7", poly_simplex, "LINESTRING(1.5 1.5,2.5 2.5)", 1, 2, sqrt(2.0)); - test_one("case8", poly_simplex, "LINESTRING(1 0,2 0)", 0, 0, 0.0); + test_one_lp("case7", poly_simplex, "LINESTRING(1.5 1.5,2.5 2.5)", 1, 2, sqrt(2.0)); + test_one_lp("case8", poly_simplex, "LINESTRING(1 0,2 0)", 0, 0, 0.0); + + test_one_lp("case9", poly_9, "LINESTRING(0 1,1 2,2 2)", 1, 2, 1.0); + test_one_lp("case10", poly_9, "LINESTRING(0 1,1 2,0 2)", 0, 0, 0.0); + test_one_lp("case11", poly_9, "LINESTRING(2 2,4 2,3 3)", 1, 3, 2.0 + sqrt(2.0)); + test_one_lp("case12", poly_9, "LINESTRING(2 3,4 4,5 6)", 1, 2, sqrt(5.0)); + + test_one_lp("case13", poly_9, "LINESTRING(3 2,4 4,2 3)", 1, 3, 2.0 * sqrt(5.0)); + test_one_lp("case14", poly_9, "LINESTRING(5 6,4 4,6 5)", 0, 0, 0.0); + //test_one_lp("case15", poly_9, "LINESTRING(0 2,1 2,1 3,0 3)", 1, 2, 1.0); + //test_one_lp("case16", poly_9, "LINESTRING(2 2,1 2,1 3,2 3)", 1, 4, 3.0); + + // Compile test - arguments in any order: + test_one("simplex", poly_simplex, "LINESTRING(0 2,4 2)", 1, 2, 2.0); + test_one("simplex", "LINESTRING(0 2,4 2)", poly_simplex, 1, 2, 2.0); } @@ -315,6 +334,8 @@ void test_all() std::string clip = "box(2 2,8 8)"; + test_polygon_linestring(); + // Test polygons clockwise and counter clockwise test_areal(); @@ -322,7 +343,6 @@ void test_all() test_areal(); test_areal(); - test_polygon_linestring(); test_areal_clip(); test_areal_clip(); diff --git a/test/algorithms/test_intersection.hpp b/test/algorithms/test_intersection.hpp index 2b606a11a..ad5f7e3fb 100644 --- a/test/algorithms/test_intersection.hpp +++ b/test/algorithms/test_intersection.hpp @@ -39,11 +39,15 @@ typename bg::default_area_result::type test_intersection(std::string const& G1 const& g1, G2 const& g2, std::size_t expected_count = 0, std::size_t expected_point_count = 0, double expected_length_or_area = 0, - double percentage = 0.0001) + double percentage = 0.0001, + bool debug = false) { static const bool is_line = bg::geometry_id::type::value == 2; - //std::cout << caseid << std::endl; + if (debug) + { + std::cout << std::endl << "case " << caseid << std::endl; + } typedef typename bg::coordinate_type::type coordinate_type; @@ -83,12 +87,10 @@ typename bg::default_area_result::type test_intersection(std::string const& ? bg::length(*it) : bg::area(*it); - /* - std::cout << std::endl << "case " << caseid << " "; - std::cout - << std::setprecision(20) - << bg::dsv(*it) << std::endl; - */ + if (debug) + { + std::cout << std::setprecision(20) << bg::wkt(*it) << std::endl; + } } @@ -159,6 +161,11 @@ typename bg::default_area_result::type test_intersection(std::string const& } #endif + if (debug) + { + std::cout << "end case " << caseid << std::endl; + } + return length_or_area; } @@ -167,7 +174,8 @@ typename bg::default_area_result::type test_one(std::string const& caseid, std::string const& wkt1, std::string const& wkt2, std::size_t expected_count = 0, std::size_t expected_point_count = 0, double expected_length_or_area = 0, - double percentage = 0.0001) + double percentage = 0.0001, + bool debug = false) { G1 g1; bg::read_wkt(wkt1, g1); @@ -181,7 +189,35 @@ typename bg::default_area_result::type test_one(std::string const& caseid, return test_intersection(caseid, g1, g2, expected_count, expected_point_count, - expected_length_or_area, percentage); + expected_length_or_area, percentage, + debug); +} + +template +void test_one_lp(std::string const& caseid, + std::string const& wkt_areal, std::string const& wkt_linear, + std::size_t expected_count = 0, std::size_t expected_point_count = 0, + double expected_length = 0, + double percentage = 0.0001, + bool debug1 = false, bool debug2 = false) +{ + Areal areal; + bg::read_wkt(wkt_areal, areal); + bg::correct(areal); + + Linear linear; + bg::read_wkt(wkt_linear, linear); + + test_intersection(caseid, areal, linear, + expected_count, expected_point_count, + expected_length, percentage, debug1); + + // A linestring reversed should deliver exactly the same. + bg::reverse(linear); + + test_intersection(caseid, areal, linear, + expected_count, expected_point_count, + expected_length, percentage, debug2); } template