disjoint_coverage_p_a.cpp 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  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_TEST_MODULE
  8. #define BOOST_TEST_MODULE test_disjoint_coverage
  9. #endif
  10. // unit test to test disjoint for all geometry combinations
  11. #include <iostream>
  12. #include <boost/test/included/unit_test.hpp>
  13. #include <boost/geometry/core/tag.hpp>
  14. #include <boost/geometry/core/tags.hpp>
  15. #include <boost/geometry/strategies/strategies.hpp>
  16. #include <boost/geometry/io/wkt/wkt.hpp>
  17. #include <boost/geometry/io/dsv/write.hpp>
  18. #include <boost/geometry/geometries/geometries.hpp>
  19. #include <boost/geometry/algorithms/disjoint.hpp>
  20. #include <from_wkt.hpp>
  21. #ifdef HAVE_TTMATH
  22. #include <boost/geometry/extensions/contrib/ttmath_stub.hpp>
  23. #endif
  24. namespace bg = ::boost::geometry;
  25. //============================================================================
  26. struct test_disjoint
  27. {
  28. template <typename Geometry1, typename Geometry2>
  29. static inline void apply(std::string const& case_id,
  30. Geometry1 const& geometry1,
  31. Geometry2 const& geometry2,
  32. bool expected_result)
  33. {
  34. bool result = bg::disjoint(geometry1, geometry2);
  35. BOOST_CHECK_MESSAGE(result == expected_result,
  36. "case ID: " << case_id << ", G1: " << bg::wkt(geometry1)
  37. << ", G2: " << bg::wkt(geometry2) << " -> Expected: "
  38. << expected_result << ", detected: " << result);
  39. result = bg::disjoint(geometry2, geometry1);
  40. BOOST_CHECK_MESSAGE(result == expected_result,
  41. "case ID: " << case_id << ", G1: " << bg::wkt(geometry2)
  42. << ", G2: " << bg::wkt(geometry1) << " -> Expected: "
  43. << expected_result << ", detected: " << result);
  44. #ifdef BOOST_GEOMETRY_TEST_DEBUG
  45. std::cout << "case ID: " << case_id << "; G1 - G2: ";
  46. std::cout << bg::wkt(geometry1) << " - ";
  47. std::cout << bg::wkt(geometry2) << std::endl;
  48. std::cout << std::boolalpha;
  49. std::cout << "expected/computed result: "
  50. << expected_result << " / " << result << std::endl;
  51. std::cout << std::endl;
  52. std::cout << std::noboolalpha;
  53. #endif
  54. }
  55. };
  56. //============================================================================
  57. // pointlike-areal geometries
  58. template <typename P>
  59. inline void test_point_box()
  60. {
  61. typedef test_disjoint tester;
  62. typedef bg::model::box<P> B;
  63. tester::apply("p-b-01",
  64. from_wkt<P>("POINT(0 0)"),
  65. from_wkt<B>("BOX(0 0,1 1)"),
  66. false);
  67. tester::apply("p-b-02",
  68. from_wkt<P>("POINT(2 2)"),
  69. from_wkt<B>("BOX(0 0,1 0)"),
  70. true);
  71. }
  72. template <typename P>
  73. inline void test_point_ring()
  74. {
  75. typedef bg::model::ring<P, false, false> R; // ccw, open
  76. typedef test_disjoint tester;
  77. tester::apply("p-r-01",
  78. from_wkt<P>("POINT(0 0)"),
  79. from_wkt<R>("POLYGON((0 0,1 0,0 1))"),
  80. false);
  81. tester::apply("p-r-02",
  82. from_wkt<P>("POINT(1 1)"),
  83. from_wkt<R>("POLYGON((0 0,1 0,0 1))"),
  84. true);
  85. }
  86. template <typename P>
  87. inline void test_point_polygon()
  88. {
  89. typedef bg::model::polygon<P, false, false> PL; // ccw, open
  90. typedef test_disjoint tester;
  91. tester::apply("p-pg-01",
  92. from_wkt<P>("POINT(0 0)"),
  93. from_wkt<PL>("POLYGON((0 0,1 0,0 1))"),
  94. false);
  95. tester::apply("p-pg-02",
  96. from_wkt<P>("POINT(1 1)"),
  97. from_wkt<PL>("POLYGON((0 0,1 0,0 1))"),
  98. true);
  99. }
  100. template <typename P>
  101. inline void test_point_multipolygon()
  102. {
  103. typedef bg::model::polygon<P, false, false> PL; // ccw, open
  104. typedef bg::model::multi_polygon<PL> MPL;
  105. typedef test_disjoint tester;
  106. tester::apply("p-mpg-01",
  107. from_wkt<P>("POINT(0 0)"),
  108. from_wkt<MPL>("MULTIPOLYGON(((0 0,1 0,0 1)),((2 0,3 0,2 1)))"),
  109. false);
  110. tester::apply("p-mpg-02",
  111. from_wkt<P>("POINT(1 1)"),
  112. from_wkt<MPL>("MULTIPOLYGON(((0 0,1 0,0 1)),((2 0,3 0,2 1)))"),
  113. true);
  114. }
  115. template <typename P>
  116. inline void test_multipoint_box()
  117. {
  118. typedef test_disjoint tester;
  119. typedef bg::model::multi_point<P> MP;
  120. typedef bg::model::box<P> B;
  121. tester::apply("mp-b-01",
  122. from_wkt<MP>("MULTIPOINT(0 0,1 1)"),
  123. from_wkt<B>("BOX(0 0,2 2)"),
  124. false);
  125. tester::apply("mp-b-02",
  126. from_wkt<MP>("MULTIPOINT(1 1,3 3)"),
  127. from_wkt<B>("BOX(0 0,2 2)"),
  128. false);
  129. tester::apply("mp-b-03",
  130. from_wkt<MP>("MULTIPOINT(3 3,4 4)"),
  131. from_wkt<B>("BOX(0 0,2 2)"),
  132. true);
  133. tester::apply("mp-b-04",
  134. from_wkt<MP>("MULTIPOINT()"),
  135. from_wkt<B>("BOX(0 0,2 2)"),
  136. true);
  137. }
  138. template <typename P>
  139. inline void test_multipoint_ring()
  140. {
  141. typedef bg::model::multi_point<P> MP;
  142. typedef bg::model::ring<P, false, false> R; // ccw, open
  143. typedef test_disjoint tester;
  144. tester::apply("mp-r-01",
  145. from_wkt<MP>("MULTIPOINT(0 0,1 0)"),
  146. from_wkt<R>("POLYGON((0 0,1 0,0 1))"),
  147. false);
  148. tester::apply("mp-r-02",
  149. from_wkt<MP>("MULTIPOINT(1 0,1 1)"),
  150. from_wkt<R>("POLYGON((0 0,1 0,0 1))"),
  151. false);
  152. tester::apply("mp-r-03",
  153. from_wkt<MP>("MULTIPOINT(1 1,2 2)"),
  154. from_wkt<R>("POLYGON((0 0,1 0,0 1))"),
  155. true);
  156. }
  157. template <typename P>
  158. inline void test_multipoint_polygon()
  159. {
  160. typedef bg::model::multi_point<P> MP;
  161. typedef bg::model::polygon<P, false, false> PL; // ccw, open
  162. typedef test_disjoint tester;
  163. tester::apply("mp-pg-01",
  164. from_wkt<MP>("MULTIPOINT(0 0,1 0)"),
  165. from_wkt<PL>("POLYGON((0 0,1 0,0 1))"),
  166. false);
  167. tester::apply("mp-pg-02",
  168. from_wkt<MP>("MULTIPOINT(0 0,2 0)"),
  169. from_wkt<PL>("POLYGON((0 0,1 0,0 1))"),
  170. false);
  171. tester::apply("mp-pg-03",
  172. from_wkt<MP>("MULTIPOINT(1 1,2 0)"),
  173. from_wkt<PL>("POLYGON((0 0,1 0,0 1))"),
  174. true);
  175. tester::apply("mp-pg-04",
  176. from_wkt<MP>("MULTIPOINT(1 1,2 3)"),
  177. from_wkt<PL>("POLYGON((0 0,1 0,0 1))"),
  178. true);
  179. }
  180. template <typename P>
  181. inline void test_multipoint_multipolygon()
  182. {
  183. typedef bg::model::multi_point<P> MP;
  184. typedef bg::model::polygon<P, false, false> PL; // ccw, open
  185. typedef bg::model::multi_polygon<PL> MPL;
  186. typedef test_disjoint tester;
  187. tester::apply("mp-mp-01",
  188. from_wkt<MP>("MULTIPOINT(0 0,2 0)"),
  189. from_wkt<MPL>("MULTIPOLYGON(((0 0,1 0,0 1)),((2 0,3 0,2 1)))"),
  190. false);
  191. tester::apply("mp-mp-02",
  192. from_wkt<MP>("MULTIPOINT(0 0,1 0)"),
  193. from_wkt<MPL>("MULTIPOLYGON(((0 0,1 0,0 1)),((2 0,3 0,2 1)))"),
  194. false);
  195. tester::apply("mp-mp-03",
  196. from_wkt<MP>("MULTIPOINT(1 1,2 0)"),
  197. from_wkt<MPL>("MULTIPOLYGON(((0 0,1 0,0 1)),((2 0,3 0,2 1)))"),
  198. false);
  199. tester::apply("mp-mp-04",
  200. from_wkt<MP>("MULTIPOINT(1 1,2 3)"),
  201. from_wkt<MPL>("MULTIPOLYGON(((0 0,1 0,0 1)),((2 0,3 0,2 1)))"),
  202. true);
  203. }
  204. //============================================================================
  205. template <typename CoordinateType>
  206. inline void test_pointlike_areal()
  207. {
  208. typedef bg::model::point<CoordinateType, 2, bg::cs::cartesian> point_type;
  209. test_point_polygon<point_type>();
  210. test_point_multipolygon<point_type>();
  211. test_point_ring<point_type>();
  212. test_point_box<point_type>();
  213. test_multipoint_polygon<point_type>();
  214. test_multipoint_multipolygon<point_type>();
  215. test_multipoint_ring<point_type>();
  216. test_multipoint_box<point_type>();
  217. }
  218. //============================================================================
  219. BOOST_AUTO_TEST_CASE( test_pointlike_areal_all )
  220. {
  221. test_pointlike_areal<double>();
  222. test_pointlike_areal<int>();
  223. #ifdef HAVE_TTMATH
  224. test_pointlike_areal<ttmath_big>();
  225. #endif
  226. }