test_union_linear_linear.hpp 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. // Copyright (c) 2014-2017, Oracle and/or its affiliates.
  3. // Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
  4. // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
  5. // Licensed under the Boost Software License version 1.0.
  6. // http://www.boost.org/users/license.html
  7. #ifndef BOOST_GEOMETRY_TEST_UNION_LINEAR_LINEAR_HPP
  8. #define BOOST_GEOMETRY_TEST_UNION_LINEAR_LINEAR_HPP
  9. #include <limits>
  10. #include <boost/geometry/geometry.hpp>
  11. #include "../test_set_ops_linear_linear.hpp"
  12. #include <from_wkt.hpp>
  13. #include <to_svg.hpp>
  14. //==================================================================
  15. //==================================================================
  16. // union of (linear) geometries
  17. //==================================================================
  18. //==================================================================
  19. template <typename Geometry1, typename Geometry2, typename MultiLineString>
  20. inline void check_result(Geometry1 const& geometry1,
  21. Geometry2 const& geometry2,
  22. MultiLineString const& mls_output,
  23. MultiLineString const& mls_union,
  24. std::string const& case_id,
  25. double tolerance)
  26. {
  27. BOOST_CHECK_MESSAGE( equals::apply(mls_union, mls_output, tolerance),
  28. "case id: " << case_id
  29. << ", union L/L: " << bg::wkt(geometry1)
  30. << " " << bg::wkt(geometry2)
  31. << " -> Expected: " << bg::wkt(mls_union)
  32. << " computed: " << bg::wkt(mls_output) );
  33. }
  34. template
  35. <
  36. typename Geometry1, typename Geometry2,
  37. typename MultiLineString
  38. >
  39. class test_union_of_geometries
  40. {
  41. private:
  42. static inline void base_test(Geometry1 const& geometry1,
  43. Geometry2 const& geometry2,
  44. MultiLineString const& mls_union1,
  45. MultiLineString const& mls_union2,
  46. std::string const& case_id,
  47. double tolerance,
  48. bool test_vector_and_deque = false)
  49. {
  50. static bool vector_deque_already_tested = false;
  51. typedef typename boost::range_value<MultiLineString>::type LineString;
  52. typedef std::vector<LineString> linestring_vector;
  53. typedef std::deque<LineString> linestring_deque;
  54. MultiLineString mls_output;
  55. linestring_vector ls_vector_output;
  56. linestring_deque ls_deque_output;
  57. // Check strategy passed explicitly
  58. typedef typename bg::strategy::relate::services::default_strategy
  59. <
  60. Geometry1, Geometry2
  61. >::type strategy_type;
  62. bg::union_(geometry1, geometry2, mls_output, strategy_type());
  63. check_result(geometry1, geometry2, mls_output, mls_union1, case_id, tolerance);
  64. // Check normal behaviour
  65. bg::clear(mls_output);
  66. bg::union_(geometry1, geometry2, mls_output);
  67. check_result(geometry1, geometry2, mls_output, mls_union1, case_id, tolerance);
  68. set_operation_output("union", case_id,
  69. geometry1, geometry2, mls_output);
  70. #ifdef BOOST_GEOMETRY_TEST_DEBUG
  71. std::cout << "Geometry #1: " << bg::wkt(geometry1) << std::endl;
  72. std::cout << "Geometry #2: " << bg::wkt(geometry2) << std::endl;
  73. std::cout << "union : " << bg::wkt(mls_output) << std::endl;
  74. std::cout << "expected union : " << bg::wkt(mls_union1)
  75. << std::endl;
  76. std::cout << std::endl;
  77. std::cout << "************************************" << std::endl;
  78. std::cout << std::endl;
  79. std::cout << std::endl;
  80. #endif
  81. if ( !vector_deque_already_tested && test_vector_and_deque )
  82. {
  83. vector_deque_already_tested = true;
  84. #ifdef BOOST_GEOMETRY_TEST_DEBUG
  85. std::cout << std::endl;
  86. std::cout << "Testing with vector and deque as output container..."
  87. << std::endl;
  88. #endif
  89. bg::union_(geometry1, geometry2, ls_vector_output);
  90. bg::union_(geometry1, geometry2, ls_deque_output);
  91. BOOST_CHECK(multilinestring_equals
  92. <
  93. false
  94. >::apply(mls_union1, ls_vector_output, tolerance));
  95. BOOST_CHECK(multilinestring_equals
  96. <
  97. false
  98. >::apply(mls_union1, ls_deque_output, tolerance));
  99. #ifdef BOOST_GEOMETRY_TEST_DEBUG
  100. std::cout << "Done!" << std::endl << std::endl;
  101. #endif
  102. }
  103. // check the union where the order of the two
  104. // geometries is reversed
  105. bg::clear(mls_output);
  106. bg::union_(geometry2, geometry1, mls_output);
  107. check_result(geometry1, geometry2, mls_output, mls_union2, case_id, tolerance);
  108. #ifdef BOOST_GEOMETRY_TEST_DEBUG
  109. std::cout << "Geometry #1: " << bg::wkt(geometry2) << std::endl;
  110. std::cout << "Geometry #2: " << bg::wkt(geometry1) << std::endl;
  111. std::cout << "union : " << bg::wkt(mls_output) << std::endl;
  112. std::cout << "expected union : " << bg::wkt(mls_union2)
  113. << std::endl;
  114. std::cout << std::endl;
  115. std::cout << "************************************" << std::endl;
  116. std::cout << std::endl;
  117. std::cout << std::endl;
  118. #endif
  119. }
  120. public:
  121. static inline void apply(Geometry1 const& geometry1,
  122. Geometry2 const& geometry2,
  123. MultiLineString const& mls_union1,
  124. MultiLineString const& mls_union2,
  125. std::string const& case_id,
  126. double tolerance
  127. = std::numeric_limits<double>::epsilon())
  128. {
  129. #ifdef BOOST_GEOMETRY_TEST_DEBUG
  130. std::cout << "test case: " << case_id << std::endl;
  131. std::stringstream sstr;
  132. sstr << "svgs/" << case_id << ".svg";
  133. to_svg(geometry1, geometry2, sstr.str());
  134. #endif
  135. Geometry1 rg1(geometry1);
  136. bg::reverse<Geometry1>(rg1);
  137. Geometry2 rg2(geometry2);
  138. bg::reverse<Geometry2>(rg2);
  139. test_get_turns_ll_invariance<>::apply(geometry1, geometry2);
  140. #ifdef BOOST_GEOMETRY_TEST_DEBUG
  141. std::cout << std::endl
  142. << "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%"
  143. << std::endl << std::endl;
  144. #endif
  145. test_get_turns_ll_invariance<>::apply(rg1, geometry2);
  146. base_test(geometry1, geometry2, mls_union1, mls_union2,
  147. case_id, tolerance, true);
  148. // base_test(geometry1, rg2, mls_sym_diff);
  149. // base_test(rg1, geometry2, mls_sym_diff);
  150. base_test(rg1, rg2, mls_union1, mls_union2, case_id, tolerance);
  151. #ifdef BOOST_GEOMETRY_TEST_DEBUG
  152. std::cout << std::endl;
  153. std::cout << std::endl;
  154. #endif
  155. }
  156. static inline void apply(Geometry1 const& geometry1,
  157. Geometry2 const& geometry2,
  158. MultiLineString const& mls_union,
  159. std::string const& case_id,
  160. double tolerance
  161. = std::numeric_limits<double>::epsilon())
  162. {
  163. apply(geometry1, geometry2, mls_union, mls_union, case_id, tolerance);
  164. }
  165. };
  166. #endif // BOOST_GEOMETRY_TEST_UNION1_HPP