test_covered_by.hpp 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. // Unit Test
  3. // Copyright (c) 2007-2015 Barend Gehrels, Amsterdam, the Netherlands.
  4. // Copyright (c) 2013-2015 Adam Wulkiewicz, Lodz, Poland.
  5. // This file was modified by Oracle on 2017.
  6. // Modifications copyright (c) 2017 Oracle and/or its affiliates.
  7. // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
  8. // Use, modification and distribution is subject to the Boost Software License,
  9. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  10. // http://www.boost.org/LICENSE_1_0.txt)
  11. #ifndef BOOST_GEOMETRY_TEST_COVERED_BY_HPP
  12. #define BOOST_GEOMETRY_TEST_COVERED_BY_HPP
  13. #include <geometry_test_common.hpp>
  14. #include <boost/variant/variant.hpp>
  15. #include <boost/geometry/algorithms/covered_by.hpp>
  16. #include <boost/geometry/core/ring_type.hpp>
  17. #include <boost/geometry/geometries/ring.hpp>
  18. #include <boost/geometry/geometries/polygon.hpp>
  19. #include <boost/geometry/geometries/multi_linestring.hpp>
  20. #include <boost/geometry/io/wkt/read.hpp>
  21. #include <boost/geometry/strategies/strategies.hpp>
  22. struct no_strategy {};
  23. template <typename Geometry1, typename Geometry2, typename Strategy>
  24. bool call_covered_by(Geometry1 const& geometry1,
  25. Geometry2 const& geometry2,
  26. Strategy const& strategy)
  27. {
  28. return bg::covered_by(geometry1, geometry2, strategy);
  29. }
  30. template <typename Geometry1, typename Geometry2>
  31. bool call_covered_by(Geometry1 const& geometry1,
  32. Geometry2 const& geometry2,
  33. no_strategy)
  34. {
  35. return bg::covered_by(geometry1, geometry2);
  36. }
  37. template <typename Geometry1, typename Geometry2, typename Strategy>
  38. void check_geometry(Geometry1 const& geometry1,
  39. Geometry2 const& geometry2,
  40. std::string const& wkt1,
  41. std::string const& wkt2,
  42. bool expected,
  43. Strategy const& strategy)
  44. {
  45. bool detected = call_covered_by(geometry1, geometry2, strategy);
  46. BOOST_CHECK_MESSAGE(detected == expected,
  47. "covered_by: " << wkt1
  48. << " in " << wkt2
  49. << " -> Expected: " << expected
  50. << " detected: " << detected);
  51. }
  52. template <typename Geometry1, typename Geometry2>
  53. void test_geometry(std::string const& wkt1,
  54. std::string const& wkt2, bool expected)
  55. {
  56. Geometry1 geometry1;
  57. Geometry2 geometry2;
  58. bg::read_wkt(wkt1, geometry1);
  59. bg::read_wkt(wkt2, geometry2);
  60. boost::variant<Geometry1> v1(geometry1);
  61. boost::variant<Geometry2> v2(geometry2);
  62. typedef typename bg::strategy::covered_by::services::default_strategy
  63. <
  64. Geometry1, Geometry2
  65. >::type strategy_type;
  66. check_geometry(geometry1, geometry2, wkt1, wkt2, expected, no_strategy());
  67. check_geometry(geometry1, geometry2, wkt1, wkt2, expected, strategy_type());
  68. check_geometry(v1, geometry2, wkt1, wkt2, expected, no_strategy());
  69. check_geometry(geometry1, v2, wkt1, wkt2, expected, no_strategy());
  70. check_geometry(v1, v2, wkt1, wkt2, expected, no_strategy());
  71. }
  72. template <typename Geometry1, typename Geometry2, typename Strategy>
  73. void test_geometry(std::string const& wkt1,
  74. std::string const& wkt2,
  75. bool expected,
  76. Strategy const& strategy)
  77. {
  78. Geometry1 geometry1;
  79. Geometry2 geometry2;
  80. bg::read_wkt(wkt1, geometry1);
  81. bg::read_wkt(wkt2, geometry2);
  82. check_geometry(geometry1, geometry2, wkt1, wkt2, expected, strategy);
  83. }
  84. /*
  85. template <typename Point, bool Clockwise, bool Closed>
  86. void test_ordered_ring(std::string const& wkt_point,
  87. std::string const& wkt_geometry, bool expected)
  88. {
  89. typedef bg::model::ring<Point, Clockwise, Closed> ring_type;
  90. ring_type ring;
  91. Point point;
  92. bg::read_wkt(wkt_geometry, ring);
  93. if (! Clockwise)
  94. {
  95. std::reverse(boost::begin(ring), boost::end(ring));
  96. }
  97. if (! Closed)
  98. {
  99. ring.resize(ring.size() - 1);
  100. }
  101. bg::read_wkt(wkt_point, point);
  102. bool detected = bg::covered_by(point, ring);
  103. BOOST_CHECK_MESSAGE(detected == expected,
  104. "covered_by: " << wkt_point
  105. << " in " << wkt_geometry
  106. << " -> Expected: " << expected
  107. << " detected: " << detected
  108. << " clockwise: " << int(Clockwise)
  109. << " closed: " << int(Closed)
  110. );
  111. // other strategy (note that this one cannot detect OnBorder
  112. // (without modifications)
  113. bg::strategy::covered_by::franklin<Point> franklin;
  114. detected = bg::covered_by(point, ring, franklin);
  115. if (! on_border)
  116. {
  117. BOOST_CHECK_MESSAGE(detected == expected,
  118. "covered_by: " << wkt_point
  119. << " in " << wkt_geometry
  120. << " -> Expected: " << expected
  121. << " detected: " << detected
  122. << " clockwise: " << int(Clockwise)
  123. << " closed: " << int(Closed)
  124. );
  125. }
  126. bg::strategy::covered_by::crossings_multiply<Point> cm;
  127. detected = bg::covered_by(point, ring, cm);
  128. if (! on_border)
  129. {
  130. BOOST_CHECK_MESSAGE(detected == expected,
  131. "covered_by: " << wkt_point
  132. << " in " << wkt_geometry
  133. << " -> Expected: " << expected
  134. << " detected: " << detected
  135. << " clockwise: " << int(Clockwise)
  136. << " closed: " << int(Closed)
  137. );
  138. }
  139. }
  140. template <typename Point>
  141. void test_ring(std::string const& wkt_point,
  142. std::string const& wkt_geometry,
  143. bool expected)
  144. {
  145. test_ordered_ring<Point, true, true>(wkt_point, wkt_geometry, expected);
  146. test_ordered_ring<Point, false, true>(wkt_point, wkt_geometry, expected);
  147. test_ordered_ring<Point, true, false>(wkt_point, wkt_geometry, expected);
  148. test_ordered_ring<Point, false, false>(wkt_point, wkt_geometry, expected);
  149. test_geometry<Point, bg::model::polygon<Point> >(wkt_point, wkt_geometry, expected);
  150. }
  151. */
  152. #endif