From 1f9ccb6698c9a47cff6e72ba5d468cea08e6afde Mon Sep 17 00:00:00 2001 From: Menelaos Karavelas Date: Wed, 19 Feb 2014 09:25:30 +0200 Subject: [PATCH] rearranged and simplified test code for differences of linear geometries; added test cases for the LS/MLS difference; polished debug macros a bit; --- .../detail/difference/linear_linear.hpp | 30 +- .../detail/turns/follow_linear_linear.hpp | 8 +- test/algorithms/difference1.cpp | 337 ++++++++++++++---- test/algorithms/test_difference1.hpp | 144 ++------ 4 files changed, 306 insertions(+), 213 deletions(-) diff --git a/include/boost/geometry/algorithms/detail/difference/linear_linear.hpp b/include/boost/geometry/algorithms/detail/difference/linear_linear.hpp index 4de076929..fc9c1b21e 100644 --- a/include/boost/geometry/algorithms/detail/difference/linear_linear.hpp +++ b/include/boost/geometry/algorithms/detail/difference/linear_linear.hpp @@ -45,6 +45,7 @@ struct multilinestring_multilinestring_linestring typedef typename Turns::iterator TurnIt; typedef detail::get_turns::no_interrupt_policy InterruptPolicy; + struct AssignPolicy { static bool const include_no_turn = false; @@ -66,6 +67,7 @@ struct multilinestring_multilinestring_linestring } }; + struct IsContinueTurn { template @@ -89,17 +91,6 @@ struct multilinestring_multilinestring_linestring }; - struct TurnEqualsTo - { - template - bool operator()(Turn const& t1, Turn const& t2) const - { - return geometry::equals(t1.point, t2.point) - && t1.operations[0].seg_id == t2.operations[0].seg_id - && t1.operations[0].other_id == t2.operations[0].other_id; - } - }; - template static inline void filter_turns(Turns& turns) { @@ -110,16 +101,6 @@ struct multilinestring_multilinestring_linestring turns.resize( std::distance(turns.begin(), new_end) ); } - template - static inline void remove_duplicates(Turns& turns) - { - typedef typename Turns::iterator TurnIt; - - TurnIt new_end = std::unique(turns.begin(), turns.end(), - TurnEqualsTo()); - turns.resize( std::distance(turns.begin(), new_end) ); - } - template < @@ -190,7 +171,7 @@ struct multilinestring_multilinestring_linestring { // the two linestrings are disjoint; we return the first as is; // canonical::apply(mls1); -#ifdef PRINT_DEBUG +#ifdef GEOMETRY_TEST_DEBUG std::cout << "NO INTERSECTIONS" << std::endl; #endif std::copy(mls1.begin(), mls1.end(), oit); @@ -212,10 +193,7 @@ struct multilinestring_multilinestring_linestring std::sort(boost::begin(reverse_turns), boost::end(reverse_turns), rev_less()); - remove_duplicates(turns); - remove_duplicates(reverse_turns); - -#ifdef PRINT_DEBUG +#ifdef GEOMETRY_TEST_DEBUG detail::turns::print_turns(mls1, mls2, turns); std::cout << std::endl << std::endl; detail::turns::print_turns(mls1, mls2_reverse, reverse_turns); diff --git a/include/boost/geometry/algorithms/detail/turns/follow_linear_linear.hpp b/include/boost/geometry/algorithms/detail/turns/follow_linear_linear.hpp index 1783ac150..d5fea80e7 100644 --- a/include/boost/geometry/algorithms/detail/turns/follow_linear_linear.hpp +++ b/include/boost/geometry/algorithms/detail/turns/follow_linear_linear.hpp @@ -210,7 +210,9 @@ public: if ( is_entering(*it, *iit) ) { +#ifdef GEOMETRY_TEST_DEBUG detail::overlay::debug_traverse(*it, *iit, "-> Entering"); +#endif entered = true; if ( enter_count == 0 ) @@ -223,13 +225,17 @@ public: } else if ( is_staying_inside(*it, *iit, entered, first, ls1, ls2) ) { +#ifdef GEOMETRY_TEST_DEBUG detail::overlay::debug_traverse(*it, *iit, "-> Staying inside"); +#endif entered = true; } else if ( is_leaving(*it, *iit, *iit_r, entered, first, ls1, ls2) ) { +#ifdef GEOMETRY_TEST_DEBUG detail::overlay::debug_traverse(*it, *iit, "-> Leaving"); +#endif --enter_count; if ( enter_count == 0 ) @@ -243,7 +249,7 @@ public: first = false; } -#ifdef PRINT_DEBUG +#ifdef GEOMETRY_TEST_DEBUG std::cout << "*** enter count: " << enter_count << std::endl; #endif BOOST_CHECK( enter_count == 0 ); diff --git a/test/algorithms/difference1.cpp b/test/algorithms/difference1.cpp index 61e5a5d9a..54e7d51b9 100644 --- a/test/algorithms/difference1.cpp +++ b/test/algorithms/difference1.cpp @@ -44,163 +44,165 @@ BOOST_AUTO_TEST_CASE( test_difference_linestring_linestring ) typedef linestring_type L; typedef multi_linestring_type ML; - test_difference_of_linestrings() + typedef test_difference_of_geometries tester; + + tester() (from_wkt("LINESTRING(0 0,5 0)"), from_wkt("LINESTRING(3 0,4 0)"), from_wkt("MULTILINESTRING((0 0,3 0),(4 0,5 0))"), "lldf01"); - test_difference_of_linestrings() + tester() (from_wkt("LINESTRING(3 0,4 0)"), from_wkt("LINESTRING(0 0,5 0)"), from_wkt("MULTILINESTRING()"), "lldf01-1"); - test_difference_of_linestrings() + tester() (from_wkt("LINESTRING(0 0,4 0)"), from_wkt("LINESTRING(3 0,6 0)"), from_wkt("MULTILINESTRING((0 0,3 0))"), "lldf01-2"); - test_difference_of_linestrings() + tester() (from_wkt("LINESTRING(3 0,6 0)"), from_wkt("LINESTRING(0 0,4 0)"), from_wkt("MULTILINESTRING((4 0,6 0))"), "lldf01-3"); - test_difference_of_linestrings() + tester() (from_wkt("LINESTRING(0 0,6 0)"), from_wkt("LINESTRING(0 0,4 0)"), from_wkt("MULTILINESTRING((4 0,6 0))"), "lldf01-4"); - test_difference_of_linestrings() + tester() (from_wkt("LINESTRING(0 0,4 0)"), from_wkt("LINESTRING(0 0,6 0)"), from_wkt("MULTILINESTRING()"), "lldf01-5"); - test_difference_of_linestrings() + tester() (from_wkt("LINESTRING(0 0,20 0)"), from_wkt("LINESTRING(0 0,1 1,2 0,3 1,4 0,5 0,6 1,7 -1,8 0)"), from_wkt("MULTILINESTRING((0 0,4 0),(5 0,20 0))"), "lldf01-6"); - test_difference_of_linestrings() + tester() (from_wkt("LINESTRING(-20 0,20 0)"), from_wkt("LINESTRING(0 0,1 1,2 0,3 1,4 0,5 0,6 1,7 -1,8 0)"), from_wkt("MULTILINESTRING((-20 0,4 0),(5 0,20 0))"), "lldf01-7"); - test_difference_of_linestrings() + tester() (from_wkt("LINESTRING(0 0,4 0)"), from_wkt("LINESTRING(2 0,4 0)"), from_wkt("MULTILINESTRING((0 0,2 0))"), "lldf01-8"); - test_difference_of_linestrings() + tester() (from_wkt("LINESTRING(2 0,4 0)"), from_wkt("LINESTRING(0 0,4 0)"), from_wkt("MULTILINESTRING()"), "lldf01-9"); - test_difference_of_linestrings() + tester() (from_wkt("LINESTRING(0 0,2 0)"), from_wkt("LINESTRING(4 0,5 0)"), from_wkt("MULTILINESTRING((0 0,2 0))"), "lldf01-10"); - test_difference_of_linestrings() + tester() (from_wkt("LINESTRING(0 0,2 0)"), from_wkt("LINESTRING(2 0,5 0)"), from_wkt("MULTILINESTRING((0 0,2 0))"), "lldf01-11"); - test_difference_of_linestrings() + tester() (from_wkt("LINESTRING(0 0,1 0,4 0)"), from_wkt("LINESTRING(3 0,5 0)"), from_wkt("MULTILINESTRING((0 0,1 0,3 0))"), "lldf01-11a"); - test_difference_of_linestrings() + tester() (from_wkt("LINESTRING(0 0,1 0,4 0)"), from_wkt("LINESTRING(3 0,4 0,5 0)"), from_wkt("MULTILINESTRING((0 0,1 0,3 0))"), "lldf01-11b"); - test_difference_of_linestrings() + tester() (from_wkt("LINESTRING(0 0,6 0)"), from_wkt("LINESTRING(2 0,4 0,5 0)"), from_wkt("MULTILINESTRING((0 0,2 0),(5 0,6 0))"), "lldf01-12"); - test_difference_of_linestrings() + tester() (from_wkt("LINESTRING(0 0,1 0,5 5,10 5,15 0)"), from_wkt("LINESTRING(-1 6,0 5,15 5)"), from_wkt("MULTILINESTRING((0 0,1 0,5 5),(10 5,15 0))"), "lldf02"); - test_difference_of_linestrings() + tester() (from_wkt("LINESTRING(-1 1,0 0,1 0,5 5,10 5,15 0,20 0)"), from_wkt("LINESTRING(-1 0,30 0)"), from_wkt("MULTILINESTRING((-1 1,0 0),(1 0,5 5,10 5,15 0))"), "lldf03"); - test_difference_of_linestrings() + tester() (from_wkt("LINESTRING(0 0,1 0,5 5,10 5,15 0,20 0)"), from_wkt("LINESTRING(-1 0,30 0)"), from_wkt("MULTILINESTRING((1 0,5 5,10 5,15 0))"), "lldf04"); - test_difference_of_linestrings() + tester() (from_wkt("LINESTRING(-1 1,0 0,1 0,5 5,10 5,15 0,20 0,25 1)"), from_wkt("LINESTRING(-1 0,30 0)"), from_wkt("MULTILINESTRING((-1 1,0 0),(1 0,5 5,10 5,15 0),\ (20 0,25 1))"), "lldf05"); - test_difference_of_linestrings() + tester() (from_wkt("LINESTRING(-1 1,0 0,1 0,5 5,10 5,15 0,20 0,30 0)"), from_wkt("LINESTRING(-1 0,30 0)"), from_wkt("MULTILINESTRING((-1 1,0 0),(1 0,5 5,10 5,15 0))"), "lldf05-1"); - test_difference_of_linestrings() + tester() (from_wkt("LINESTRING(-1 1,0 0,1 0,5 5,10 5,15 0,20 0,31 0)"), from_wkt("LINESTRING(-1 0,30 0)"), from_wkt("MULTILINESTRING((-1 1,0 0),(1 0,5 5,10 5,15 0),\ (30 0,31 0))"), "lldf06"); - test_difference_of_linestrings() + tester() (from_wkt("LINESTRING(-1 1,0 0,1 0,5 5,10 5,15 0,20 0,31 0)"), from_wkt("LINESTRING(-1 0,25 0,30 0)"), from_wkt("MULTILINESTRING((-1 1,0 0),(1 0,5 5,10 5,15 0),\ (30 0,31 0))"), "lldf07"); - test_difference_of_linestrings() + tester() (from_wkt("LINESTRING(-1 1,0 0,1 0,5 5,10 5,15 0,20 0,31 0)"), from_wkt("LINESTRING(-1 0,19 0,30 0)"), from_wkt("MULTILINESTRING((-1 1,0 0),(1 0,5 5,10 5,15 0),\ (30 0,31 0))"), "lldf08"); - test_difference_of_linestrings() + tester() (from_wkt("LINESTRING(-1 1,0 0,1 0,5 5,10 5,15 0,20 0,30 0,31 1)"), from_wkt("LINESTRING(-1 0,30 0)"), from_wkt("MULTILINESTRING((-1 1,0 0),(1 0,5 5,10 5,15 0),\ (30 0,31 1))"), "lldf09"); - test_difference_of_linestrings() + tester() (from_wkt("LINESTRING(-1 1,0 0,1 0,5 5,10 5,15 0,20 0,30 0,31 1)"), from_wkt("LINESTRING(-1 -1,0 0,1 0,2 1,3 0,30 0)"), from_wkt("MULTILINESTRING((-1 1,0 0),(1 0,5 5,10 5,15 0),\ (30 0,31 1))"), "lldf10"); - test_difference_of_linestrings() + tester() (from_wkt("LINESTRING(-1 1,0 0,1 0,4 0,5 5,10 5,15 0,20 0,\ 30 0,31 1)"), from_wkt("LINESTRING(-1 -1,0 0,1 0,2 0,2.5 1,3 0,30 0)"), @@ -208,147 +210,147 @@ BOOST_AUTO_TEST_CASE( test_difference_linestring_linestring ) (4 0,5 5,10 5,15 0),(30 0,31 1))"), "lldf11"); - test_difference_of_linestrings() + tester() (from_wkt("LINESTRING(-1 1,0 0,1 0,4 0,5 5,10 5,15 0,31 0)"), from_wkt("LINESTRING(-1 -1,0 0,1 0,2 0,2.5 1,3 0,30 0)"), from_wkt("MULTILINESTRING((-1 1,0 0),(2 0,3 0),\ (4 0,5 5,10 5,15 0),(30 0,31 0))"), "lldf11-1"); - test_difference_of_linestrings() + tester() (from_wkt("LINESTRING(0 0,2 0,3 1)"), from_wkt("LINESTRING(0 0,2 0,3 1)"), from_wkt("MULTILINESTRING()"), "lldf12"); - test_difference_of_linestrings() + tester() (from_wkt("LINESTRING(0 0,2 0,3 1)"), from_wkt("LINESTRING(3 1,2 0,0 0)"), from_wkt("MULTILINESTRING()"), "lldf12-1"); - test_difference_of_linestrings() + tester() (from_wkt("LINESTRING(0 0,1 0,2 1,3 5,4 0)"), from_wkt("LINESTRING(1 0,2 1,3 5,4 0,5 10)"), from_wkt("MULTILINESTRING((0 0,1 0))"), "lldf13"); - test_difference_of_linestrings() + tester() (from_wkt("LINESTRING(0 0,1 0,2 0,2.5 0,3 1)"), from_wkt("LINESTRING(0 0,2 0,2.5 0,3 1)"), from_wkt("MULTILINESTRING()"), "lldf14"); - test_difference_of_linestrings() + tester() (from_wkt("LINESTRING(0 0,1 0,2 1,3 5,4 0)"), from_wkt("LINESTRING(1 0,2 1,3 5)"), from_wkt("MULTILINESTRING((0 0,1 0),(3 5,4 0))"), "lldf15"); - test_difference_of_linestrings() + tester() (from_wkt("LINESTRING(0 0,1 0,2 1,3 2)"), from_wkt("LINESTRING(0.5 0,1 0,3 2,4 5)"), from_wkt("MULTILINESTRING((0 0,0.5 0))"), "lldf16"); - test_difference_of_linestrings() + tester() (from_wkt("LINESTRING(0 0,1 0,2 1,3 2)"), from_wkt("LINESTRING(4 5,3 2,1 0,0.5 0)"), from_wkt("MULTILINESTRING((0 0,0.5 0))"), "lldf16-r"); - test_difference_of_linestrings() + tester() (from_wkt("LINESTRING(0 0,10 0,20 1,30 1)"), from_wkt("LINESTRING(1 1,2 0,3 1,20 1,25 1)"), from_wkt("MULTILINESTRING((0 0,10 0,20 1),(25 1,30 1))"), "lldf17"); - test_difference_of_linestrings() + tester() (from_wkt("LINESTRING(0 0,10 0,20 1,21 0,30 0)"), from_wkt("LINESTRING(1 1,2 0,3 1,20 1,25 0)"), from_wkt("MULTILINESTRING((0 0,10 0,20 1,21 0,30 0))"), "lldf18"); - test_difference_of_linestrings() + tester() (from_wkt("LINESTRING(0 0,30 0)"), from_wkt("LINESTRING(1 0,5 0,20 1,4 1,4 0,5 1)"), from_wkt("MULTILINESTRING((0 0,1 0),(5 0,30 0))"), "lldf19"); - test_difference_of_linestrings() + tester() (from_wkt("LINESTRING(0 0,30 0)"), from_wkt("LINESTRING(5 1,4 0,4 1,20 1,5 0,1 0)"), from_wkt("MULTILINESTRING((0 0,1 0),(5 0,30 0))"), "lldf19-r"); - test_difference_of_linestrings() + tester() (from_wkt("LINESTRING(0 0,30 0)"), from_wkt("LINESTRING(1 0,5 0,20 1,4 1,4 0)"), from_wkt("MULTILINESTRING((0 0,1 0),(5 0,30 0))"), "lldf19a"); - test_difference_of_linestrings() + tester() (from_wkt("LINESTRING(0 0,30 0)"), from_wkt("LINESTRING(4 0,4 1,20 1,5 0,1 0)"), from_wkt("MULTILINESTRING((0 0,1 0),(5 0,30 0))"), "lldf19a-r"); - test_difference_of_linestrings() + tester() (from_wkt("LINESTRING(0 0,30 0)"), from_wkt("LINESTRING(1 0,5 0,20 1,4 1,4 0,5 0)"), from_wkt("MULTILINESTRING((0 0,1 0),(5 0,30 0))"), "lldf19b"); - test_difference_of_linestrings() + tester() (from_wkt("LINESTRING(0 0,30 0)"), from_wkt("LINESTRING(1 0,5 0,20 1,4 1,4 0,5 0,6 1)"), from_wkt("MULTILINESTRING((0 0,1 0),(5 0,30 0))"), "lldf19c"); - test_difference_of_linestrings() + tester() (from_wkt("LINESTRING(0 0,30 0)"), from_wkt("LINESTRING(1 0,5 0,20 1,4 1,4 0,3 0)"), from_wkt("MULTILINESTRING((0 0,1 0),(5 0,30 0))"), "lldf19d"); - test_difference_of_linestrings() + tester() (from_wkt("LINESTRING(0 0,30 0)"), from_wkt("LINESTRING(1 0,5 0,20 1,4 1,4 0,3 0,3 1)"), from_wkt("MULTILINESTRING((0 0,1 0),(5 0,30 0))"), "lldf19e"); - test_difference_of_linestrings() + tester() (from_wkt("LINESTRING(0 0,30 0)"), from_wkt("LINESTRING(1 0,5 0,20 1,4 1,4 0,5 0,5 1)"), from_wkt("MULTILINESTRING((0 0,1 0),(5 0,30 0))"), "lldf19f"); - test_difference_of_linestrings() + tester() (from_wkt("LINESTRING(0 0,30 0)"), from_wkt("LINESTRING(5 1,5 0,4 0,4 1,20 1,5 0,1 0)"), from_wkt("MULTILINESTRING((0 0,1 0),(5 0,30 0))"), "lldf19f-r"); - test_difference_of_linestrings() + tester() (from_wkt("LINESTRING(0 0,30 0)"), from_wkt("LINESTRING(1 0,5 0,20 1,4 1,5 0,5 1)"), from_wkt("MULTILINESTRING((0 0,1 0),(5 0,30 0))"), "lldf19g"); - test_difference_of_linestrings() + tester() (from_wkt("LINESTRING(0 0,30 0)"), from_wkt("LINESTRING(5 1,5 0,4 1,20 1,5 0,1 0)"), from_wkt("MULTILINESTRING((0 0,1 0),(5 0,30 0))"), "lldf19g-r"); - test_difference_of_linestrings() + tester() (from_wkt("LINESTRING(0 0,30 0,30 30,10 30,10 -10,15 0,40 0)"), from_wkt("LINESTRING(5 5,10 0,10 30,20 0,25 0,25 25,50 0,35 0)"), from_wkt("MULTILINESTRING((0 0,20 0),(25 0,30 0,30 30,10 30),\ (10 0,10 -10,15 0,20 0),(25 0,35 0))"), "lldf20"); - test_difference_of_linestrings() + tester() (from_wkt("LINESTRING(0 0,30 0,30 30,10 30,10 -10,15 0,40 0)"), from_wkt("LINESTRING(5 5,10 0,10 30,20 0,25 0,25 25,50 0,15 0)"), from_wkt("MULTILINESTRING((0 0,15 0),(30 0,30 30,10 30),\ @@ -358,6 +360,191 @@ BOOST_AUTO_TEST_CASE( test_difference_linestring_linestring ) +BOOST_AUTO_TEST_CASE( test_difference_linestring_multilinestring ) +{ +#ifdef GEOMETRY_TEST_DEBUG + std::cout << std::endl << std::endl << std::endl; + std::cout << "*** LINESTRING / MULTILINESTRING DIFFERENCE ***" + << std::endl; + std::cout << std::endl; +#endif + + typedef linestring_type L; + typedef multi_linestring_type ML; + + typedef test_difference_of_geometries tester; + + // disjoint linestrings + tester() + (from_wkt("LINESTRING(0 0,10 0,20 1)"), + from_wkt("MULTILINESTRING((1 1,2 2,4 3),(1 1,2 2,5 3))"), + from_wkt("MULTILINESTRING((0 0,10 0,20 1))"), + "lmldf01" + ); + + tester() + (from_wkt("LINESTRING(0 0,10 0,20 1)"), + from_wkt("MULTILINESTRING((1 1,2 0,4 0),(1 1,3 0,4 0))"), + from_wkt("MULTILINESTRING((0 0,2 0),(4 0,10 0,20 1))"), + "lmldf02" + ); + + tester() + (from_wkt("LINESTRING(0 0,10 0,20 1)"), + from_wkt("MULTILINESTRING((1 1,2 0,4 0),(1 1,3 0,5 0))"), + from_wkt("MULTILINESTRING((0 0,2 0),(5 0,10 0,20 1))"), + "lmldf03" + ); + + tester() + (from_wkt("LINESTRING(0 0,10 0,20 1)"), + from_wkt("MULTILINESTRING((1 1,2 0,4 0))"), + from_wkt("MULTILINESTRING((0 0,2 0),(4 0,10 0,20 1))"), + "lmldf04" + ); + + tester() + (from_wkt("LINESTRING(0 0,101 0)"), + from_wkt("MULTILINESTRING((-1 -1,1 0,101 0,200 -1))"), + from_wkt("MULTILINESTRING((0 0,1 0))"), + "lmldf07" + ); + + tester() + (from_wkt("LINESTRING(-1 1,0 0,101 0)"), + from_wkt("MULTILINESTRING((-1 -1,0 0,50 0),\ + (19 -1,20 0,101 0,200 -1))"), + from_wkt("MULTILINESTRING((-1 1,0 0))"), + "lmldf07a" + ); + + tester() + (from_wkt("LINESTRING(0 0,101 0)"), + from_wkt("MULTILINESTRING((-1 -1,0 0,50 0),\ + (19 -1,20 0,101 0,200 -1))"), + from_wkt("MULTILINESTRING()"), + "lmldf07b" + ); + + tester() + (from_wkt("LINESTRING(0 0,101 0)"), + from_wkt("MULTILINESTRING((0 1,1 1,2 0),\ + (-1 -1,1 0,101 0,200 -1))"), + from_wkt("MULTILINESTRING((0 0,1 0))"), + "lmldf08" + ); + + tester() + (from_wkt("LINESTRING(0 0,1 0,2 0.5,3 0,101 0)"), + from_wkt("MULTILINESTRING((0 1,1 1,2 0.5),\ + (-1 -1,1 0,101 0,200 -1))"), + from_wkt("MULTILINESTRING((0 0,1 0,2 0.5,3 0))"), + "lmldf09" + ); + + tester() + (from_wkt("LINESTRING(0 0,1 0,1.5 0,2 0.5,3 0,101 0)"), + from_wkt("MULTILINESTRING((0 1,1 1,1 0,2 0.5),\ + (-1 -1,1 0,101 0,200 -1))"), + from_wkt("MULTILINESTRING((0 0,1 0),(1.5 0,2 0.5,3 0))"), + "lmldf10" + ); + + tester() + (from_wkt("LINESTRING(0 0,20 0)"), + from_wkt("MULTILINESTRING((0 1,1 0,19 0,20 1),\ + (1 1,2 0,18 0,19 1),(2 1,3 0,17 0,18 1),\ + (3 1,4 0,16 0,17 1))"), + from_wkt("MULTILINESTRING((0 0,1 0),(19 0,20 0))"), + "lmldf12" + ); + + tester() + (from_wkt("LINESTRING(0 0,20 0)"), + from_wkt("MULTILINESTRING((1 0,19 0,20 1),\ + (2 0,18 0,19 1),(3 0,17 0,18 1),\ + (4 0,16 0,17 1))"), + from_wkt("MULTILINESTRING((0 0,1 0),(19 0,20 0))"), + "lmldf13" + ); + + tester() + (from_wkt("LINESTRING(0 0,20 0)"), + from_wkt("MULTILINESTRING((0 1,1 0,19 0,20 1,19 1,18 0,2 0,\ + 1 1,2 1,3 0,17 0,18 1,17 1,16 0,4 0,3 1))"), + from_wkt("MULTILINESTRING((0 0,1 0),(19 0,20 0))"), + "lmldf14" + ); + + tester() + (from_wkt("LINESTRING(0 0,20 0)"), + from_wkt("MULTILINESTRING((0 1,1 0,19 0,20 1),\ + (2 2,4 2,6 0))"), + from_wkt("MULTILINESTRING((0 0,1 0),(19 0,20 0))"), + "lmldf15" + ); + + tester() + (from_wkt("LINESTRING(0 0,20 0)"), + from_wkt("MULTILINESTRING((0 1,1 0,19 0,20 1),\ + (6 0,4 2,2 2))"), + from_wkt("MULTILINESTRING((0 0,1 0),(19 0,20 0))"), + "lmldf15a" + ); + + tester() + (from_wkt("LINESTRING(0 0,20 0)"), + from_wkt("MULTILINESTRING((0 1,1 0,19 0,20 1),\ + (2 2,4 2,5 0,6 0))"), + from_wkt("MULTILINESTRING((0 0,1 0),(19 0,20 0))"), + "lmldf16" + ); + + tester() + (from_wkt("LINESTRING(0 0,20 0)"), + from_wkt("MULTILINESTRING((0 1,1 0,19 0,20 1),\ + (6 0,5 0,4 2,2 2))"), + from_wkt("MULTILINESTRING((0 0,1 0),(19 0,20 0))"), + "lmldf16a" + ); + + tester() + (from_wkt("LINESTRING(0 0,30 0)"), + from_wkt("MULTILINESTRING((0 1,1 0,19 0,20 1),\ + (2 2,4 0,5 2,20 2,25 0))"), + from_wkt("MULTILINESTRING((0 0,1 0),(19 0,30 0))"), + "lmldf17" + ); + + tester() + (from_wkt("LINESTRING(0 0,30 0)"), + from_wkt("MULTILINESTRING((0 1,1 0,19 0,20 1),\ + (2 2,4 0,5 2,20 2,25 0,26 2))"), + from_wkt("MULTILINESTRING((0 0,1 0),(19 0,30 0))"), + "lmldf17a" + ); + + tester() + (from_wkt("LINESTRING(0 0,30 0)"), + from_wkt("MULTILINESTRING((0 1,1 0,19 0,20 1),\ + (2 2,5 -1,15 2,18 0))"), + from_wkt("MULTILINESTRING((0 0,1 0),(19 0,30 0))"), + "lmldf18" + ); + + tester() + (from_wkt("LINESTRING(0 0,18 0,19 0,30 0)"), + from_wkt("MULTILINESTRING((0 1,1 0,19 0,20 1),\ + (2 2,5 -1,15 2,18 0))"), + from_wkt("MULTILINESTRING((0 0,1 0),(19 0,30 0))"), + "lmldf18a" + ); +} + + + + + BOOST_AUTO_TEST_CASE( test_difference_multilinestring_multilinestring ) { #ifdef GEOMETRY_TEST_DEBUG @@ -369,15 +556,17 @@ BOOST_AUTO_TEST_CASE( test_difference_multilinestring_multilinestring ) typedef multi_linestring_type ML; + typedef test_difference_of_geometries tester; + // disjoint linestrings - test_difference_of_multilinestrings() + tester() (from_wkt("MULTILINESTRING((0 0,10 0,20 1),(1 0,7 0))"), from_wkt("MULTILINESTRING((1 1,2 2,4 3),(1 1,2 2,5 3))"), from_wkt("MULTILINESTRING((0 0,10 0,20 1),(1 0,7 0))"), "mlmldf01" ); - test_difference_of_multilinestrings() + tester() (from_wkt("MULTILINESTRING((0 0,10 0,20 1),(1 0,7 0))"), from_wkt("MULTILINESTRING((1 1,2 0,4 0),(1 1,3 0,4 0))"), from_wkt("MULTILINESTRING((0 0,2 0),(4 0,10 0,20 1),\ @@ -385,7 +574,7 @@ BOOST_AUTO_TEST_CASE( test_difference_multilinestring_multilinestring ) "mlmldf02" ); - test_difference_of_multilinestrings() + tester() (from_wkt("MULTILINESTRING((0 0,10 0,20 1),(1 0,7 0))"), from_wkt("MULTILINESTRING((1 1,2 0,4 0),(1 1,3 0,5 0))"), from_wkt("MULTILINESTRING((0 0,2 0),(5 0,10 0,20 1),\ @@ -393,7 +582,7 @@ BOOST_AUTO_TEST_CASE( test_difference_multilinestring_multilinestring ) "mlmldf03" ); - test_difference_of_multilinestrings() + tester() (from_wkt("MULTILINESTRING((0 0,10 0,20 1),(1 0,7 0))"), from_wkt("MULTILINESTRING((1 1,2 0,4 0))"), from_wkt("MULTILINESTRING((0 0,2 0),(4 0,10 0,20 1),\ @@ -401,7 +590,7 @@ BOOST_AUTO_TEST_CASE( test_difference_multilinestring_multilinestring ) "mlmldf04" ); - test_difference_of_multilinestrings() + tester() (from_wkt("MULTILINESTRING((0 0,10 0,20 1),(1 0,7 0),\ (10 10,20 10,30 20))"), from_wkt("MULTILINESTRING((1 1,2 0,4 0),\ @@ -411,7 +600,7 @@ BOOST_AUTO_TEST_CASE( test_difference_multilinestring_multilinestring ) "mlmldf05" ); - test_difference_of_multilinestrings() + tester() (from_wkt("MULTILINESTRING((0 0,10 0,20 1),(1 0,7 0),\ (10 10,20 10,30 20))"), from_wkt("MULTILINESTRING((1 1,2 0,4 0),\ @@ -422,14 +611,14 @@ BOOST_AUTO_TEST_CASE( test_difference_multilinestring_multilinestring ) "mlmldf06" ); - test_difference_of_multilinestrings() + tester() (from_wkt("MULTILINESTRING((0 0,101 0))"), from_wkt("MULTILINESTRING((-1 -1,1 0,101 0,200 -1))"), from_wkt("MULTILINESTRING((0 0,1 0))"), "mlmldf07" ); - test_difference_of_multilinestrings() + tester() (from_wkt("MULTILINESTRING((-1 1,0 0,101 0))"), from_wkt("MULTILINESTRING((-1 -1,0 0,50 0),\ (19 -1,20 0,101 0,200 -1))"), @@ -437,7 +626,7 @@ BOOST_AUTO_TEST_CASE( test_difference_multilinestring_multilinestring ) "mlmldf07a" ); - test_difference_of_multilinestrings() + tester() (from_wkt("MULTILINESTRING((0 0,101 0))"), from_wkt("MULTILINESTRING((-1 -1,0 0,50 0),\ (19 -1,20 0,101 0,200 -1))"), @@ -445,7 +634,7 @@ BOOST_AUTO_TEST_CASE( test_difference_multilinestring_multilinestring ) "mlmldf07b" ); - test_difference_of_multilinestrings() + tester() (from_wkt("MULTILINESTRING((0 0,101 0))"), from_wkt("MULTILINESTRING((0 1,1 1,2 0),\ (-1 -1,1 0,101 0,200 -1))"), @@ -453,7 +642,7 @@ BOOST_AUTO_TEST_CASE( test_difference_multilinestring_multilinestring ) "mlmldf08" ); - test_difference_of_multilinestrings() + tester() (from_wkt("MULTILINESTRING((0 0,1 0,2 0.5,3 0,101 0))"), from_wkt("MULTILINESTRING((0 1,1 1,2 0.5),\ (-1 -1,1 0,101 0,200 -1))"), @@ -461,7 +650,7 @@ BOOST_AUTO_TEST_CASE( test_difference_multilinestring_multilinestring ) "mlmldf09" ); - test_difference_of_multilinestrings() + tester() (from_wkt("MULTILINESTRING((0 0,1 0,1.5 0,2 0.5,3 0,101 0))"), from_wkt("MULTILINESTRING((0 1,1 1,1 0,2 0.5),\ (-1 -1,1 0,101 0,200 -1))"), @@ -469,7 +658,7 @@ BOOST_AUTO_TEST_CASE( test_difference_multilinestring_multilinestring ) "mlmldf10" ); - test_difference_of_multilinestrings() + tester() (from_wkt("MULTILINESTRING((0 0,1 1,100 1,101 0),\ (0 0,101 0))"), from_wkt("MULTILINESTRING((1 0,1 1,2 1,3 0,4 0,5 1,6 1,\ @@ -480,7 +669,7 @@ BOOST_AUTO_TEST_CASE( test_difference_multilinestring_multilinestring ) "mlmldf11" ); - test_difference_of_multilinestrings() + tester() (from_wkt("MULTILINESTRING((0 0,20 0))"), from_wkt("MULTILINESTRING((0 1,1 0,19 0,20 1),\ (1 1,2 0,18 0,19 1),(2 1,3 0,17 0,18 1),\ @@ -489,7 +678,7 @@ BOOST_AUTO_TEST_CASE( test_difference_multilinestring_multilinestring ) "mlmldf12" ); - test_difference_of_multilinestrings() + tester() (from_wkt("MULTILINESTRING((0 0,20 0))"), from_wkt("MULTILINESTRING((1 0,19 0,20 1),\ (2 0,18 0,19 1),(3 0,17 0,18 1),\ @@ -498,7 +687,7 @@ BOOST_AUTO_TEST_CASE( test_difference_multilinestring_multilinestring ) "mlmldf13" ); - test_difference_of_multilinestrings() + tester() (from_wkt("MULTILINESTRING((0 0,20 0))"), from_wkt("MULTILINESTRING((0 1,1 0,19 0,20 1,19 1,18 0,2 0,\ 1 1,2 1,3 0,17 0,18 1,17 1,16 0,4 0,3 1))"), @@ -506,7 +695,7 @@ BOOST_AUTO_TEST_CASE( test_difference_multilinestring_multilinestring ) "mlmldf14" ); - test_difference_of_multilinestrings() + tester() (from_wkt("MULTILINESTRING((0 0,20 0))"), from_wkt("MULTILINESTRING((0 1,1 0,19 0,20 1),\ (2 2,4 2,6 0))"), @@ -514,7 +703,7 @@ BOOST_AUTO_TEST_CASE( test_difference_multilinestring_multilinestring ) "mlmldf15" ); - test_difference_of_multilinestrings() + tester() (from_wkt("MULTILINESTRING((0 0,20 0))"), from_wkt("MULTILINESTRING((0 1,1 0,19 0,20 1),\ (6 0,4 2,2 2))"), @@ -522,7 +711,7 @@ BOOST_AUTO_TEST_CASE( test_difference_multilinestring_multilinestring ) "mlmldf15a" ); - test_difference_of_multilinestrings() + tester() (from_wkt("MULTILINESTRING((0 0,20 0))"), from_wkt("MULTILINESTRING((0 1,1 0,19 0,20 1),\ (2 2,4 2,5 0,6 0))"), @@ -530,7 +719,7 @@ BOOST_AUTO_TEST_CASE( test_difference_multilinestring_multilinestring ) "mlmldf16" ); - test_difference_of_multilinestrings() + tester() (from_wkt("MULTILINESTRING((0 0,20 0))"), from_wkt("MULTILINESTRING((0 1,1 0,19 0,20 1),\ (6 0,5 0,4 2,2 2))"), @@ -538,7 +727,7 @@ BOOST_AUTO_TEST_CASE( test_difference_multilinestring_multilinestring ) "mlmldf16a" ); - test_difference_of_multilinestrings() + tester() (from_wkt("MULTILINESTRING((0 0,30 0))"), from_wkt("MULTILINESTRING((0 1,1 0,19 0,20 1),\ (2 2,4 0,5 2,20 2,25 0))"), @@ -546,7 +735,7 @@ BOOST_AUTO_TEST_CASE( test_difference_multilinestring_multilinestring ) "mlmldf17" ); - test_difference_of_multilinestrings() + tester() (from_wkt("MULTILINESTRING((0 0,30 0))"), from_wkt("MULTILINESTRING((0 1,1 0,19 0,20 1),\ (2 2,4 0,5 2,20 2,25 0,26 2))"), @@ -554,7 +743,7 @@ BOOST_AUTO_TEST_CASE( test_difference_multilinestring_multilinestring ) "mlmldf17a" ); - test_difference_of_multilinestrings() + tester() (from_wkt("MULTILINESTRING((0 0,30 0))"), from_wkt("MULTILINESTRING((0 1,1 0,19 0,20 1),\ (2 2,5 -1,15 2,18 0))"), @@ -562,7 +751,7 @@ BOOST_AUTO_TEST_CASE( test_difference_multilinestring_multilinestring ) "mlmldf18" ); - test_difference_of_multilinestrings() + tester() (from_wkt("MULTILINESTRING((0 0,18 0,19 0,30 0))"), from_wkt("MULTILINESTRING((0 1,1 0,19 0,20 1),\ (2 2,5 -1,15 2,18 0))"), diff --git a/test/algorithms/test_difference1.hpp b/test/algorithms/test_difference1.hpp index 489a09682..8f578dd4b 100644 --- a/test/algorithms/test_difference1.hpp +++ b/test/algorithms/test_difference1.hpp @@ -15,14 +15,16 @@ #include #include -//#include "to_svg.hpp" #include +#include #include #include namespace bg = ::boost::geometry; +#include "to_svg.hpp" + template struct ls_less @@ -116,7 +118,7 @@ struct multilinestring_equals //================================================================== //================================================================== -// difference -- base test +// difference of (linear) geometries //================================================================== //================================================================== @@ -125,13 +127,13 @@ template typename Geometry1, typename Geometry2, typename MultiLineString > -struct test_difference_base_test +struct test_difference_of_geometries { - void operator()(Geometry1 const& geometry1, - Geometry2 const& geometry2, - MultiLineString const& mls_diff, - bool test_vector_and_deque = true, - bool reverse_output_for_checking = false) const + void base_test(Geometry1 const& geometry1, + Geometry2 const& geometry2, + MultiLineString const& mls_diff, + bool test_vector_and_deque = true, + bool reverse_output_for_checking = false) const { typedef typename boost::range_value::type LineString; typedef std::vector LineStringVector; @@ -157,7 +159,7 @@ struct test_difference_base_test if ( test_vector_and_deque ) { -#ifdef PRINT_DEBUG +#ifdef GEOMETRY_TEST_DEBUG std::cout << std::endl; std::cout << "Testing with vector and deque as output container..." << std::endl; @@ -176,7 +178,7 @@ struct test_difference_base_test MultiLineString, LineStringDeque >::apply(mls_diff, ls_deque_output) )); -#ifdef PRINT_DEBUG +#ifdef GEOMETRY_TEST_DEBUG std::cout << "Done!" << std::endl << std::endl; #endif } @@ -191,42 +193,23 @@ struct test_difference_base_test std::cout << std::endl; #endif } -}; -//================================================================== -//================================================================== -// difference of linestrings -//================================================================== -//================================================================== -struct test_difference_of_linestrings -{ - template - < - typename LineString1, typename LineString2, - typename MultiLineStringOut - > - void operator()(LineString1 const& linestring1, - LineString2 const& linestring2, - MultiLineStringOut const& mls_diff) const + + void operator()(Geometry1 const& geometry1, + Geometry2 const& geometry2, + MultiLineString const& mls_diff) const { - typedef test_difference_base_test - < - LineString1, LineString2, MultiLineStringOut - > BaseTest; + Geometry1 rg1(geometry1); + bg::reverse(rg1); - BaseTest base_test; + Geometry2 rg2(geometry2); + bg::reverse(rg2); - LineString1 rls1(linestring1); - bg::reverse(rls1); - - LineString2 rls2(linestring2); - bg::reverse(rls2); - - base_test(linestring1, linestring2, mls_diff); - base_test(linestring1, rls2, mls_diff, false); - base_test(rls1, linestring2, mls_diff, false, true); - base_test(rls1, rls2, mls_diff, false, true); + base_test(geometry1, geometry2, mls_diff); + base_test(geometry1, rg2, mls_diff, false); + base_test(rg1, geometry2, mls_diff, false, true); + base_test(rg1, rg2, mls_diff, false, true); #ifdef GEOMETRY_TEST_DEBUG std::cout << std::endl; @@ -234,84 +217,21 @@ struct test_difference_of_linestrings #endif } - template - < - typename Linestring1, typename Linestring2, - typename MultiLinestringOut - > - void operator()(Linestring1 const& linestring1, - Linestring2 const& linestring2, - MultiLinestringOut const& mls_diff, + + void operator()(Geometry1 const& geometry1, + Geometry2 const& geometry2, + MultiLineString const& mls_diff, std::string const& test_case_str) const { #ifdef GEOMETRY_TEST_DEBUG std::cout << "test case: " << test_case_str << std::endl; - // to_svg(linestring1, linestring2, svg_fname); + std::stringstream sstr; + sstr << "svgs/" << test_case_str << ".svg"; + to_svg(geometry1, geometry2, sstr.str()); #endif - this->operator()(linestring1, linestring2, mls_diff); + this->operator()(geometry1, geometry2, mls_diff); } }; -//================================================================== -//================================================================== -// difference of multilinestrings -//================================================================== -//================================================================== - -struct test_difference_of_multilinestrings -{ - template - < - typename MultiLinestring1, typename MultiLinestring2, - typename MultiLinestringOut - > - void operator()(MultiLinestring1 const& multilinestring1, - MultiLinestring2 const& multilinestring2, - MultiLinestringOut const& mls_diff) const - { - typedef test_difference_base_test - < - MultiLinestring1, MultiLinestring2, MultiLinestringOut - > BaseTest; - - BaseTest base_test; - - MultiLinestring1 rmls1(multilinestring1); - bg::reverse(rmls1); - - MultiLinestring2 rmls2(multilinestring2); - bg::reverse(rmls2); - - base_test(multilinestring1, multilinestring2, mls_diff); - base_test(multilinestring1, rmls2, mls_diff, false); - base_test(rmls1, multilinestring2, mls_diff, false, true); - base_test(rmls1, rmls2, mls_diff, false, true); - -#ifdef GEOMETRY_TEST_DEBUG - std::cout << std::endl; - std::cout << std::endl; -#endif - } - - template - < - typename MultiLinestring1, typename MultiLinestring2, - typename MultiLinestringOut - > - void operator()(MultiLinestring1 const& multilinestring1, - MultiLinestring2 const& multilinestring2, - MultiLinestringOut const& mls_diff, - std::string const& test_case_str) const - { -#ifdef GEOMETRY_TEST_DEBUG - std::cout << "test case: " << test_case_str << std::endl; - // to_svg(multilinestring1, multilinestring2, svg_fname); -#endif - this->operator()(multilinestring1, multilinestring2, mls_diff); - } -}; - - - #endif // BOOST_GEOMETRY_TEST_DIFFERENCE1_HPP