disjoint_coverage_l_l.cpp 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379
  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. // Copyright (c) 2014-2015, Oracle and/or its affiliates.
  3. // Licensed under the Boost Software License version 1.0.
  4. // http://www.boost.org/users/license.html
  5. // Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
  6. // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
  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. // linear-linear geometries
  58. template <typename P>
  59. inline void test_segment_segment()
  60. {
  61. typedef bg::model::segment<P> S;
  62. typedef test_disjoint tester;
  63. tester::apply("s-s-01",
  64. from_wkt<S>("SEGMENT(0 0,2 0)"),
  65. from_wkt<S>("SEGMENT(0 0,0 2)"),
  66. false);
  67. tester::apply("s-s-02",
  68. from_wkt<S>("SEGMENT(0 0,2 0)"),
  69. from_wkt<S>("SEGMENT(2 0,3 0)"),
  70. false);
  71. tester::apply("s-s-03",
  72. from_wkt<S>("SEGMENT(0 0,2 0)"),
  73. from_wkt<S>("SEGMENT(1 0,3 0)"),
  74. false);
  75. tester::apply("s-s-04",
  76. from_wkt<S>("SEGMENT(0 0,2 0)"),
  77. from_wkt<S>("SEGMENT(1 0,1 1)"),
  78. false);
  79. tester::apply("s-s-05",
  80. from_wkt<S>("SEGMENT(0 0,2 0)"),
  81. from_wkt<S>("SEGMENT(1 1,2 2)"),
  82. true);
  83. tester::apply("s-s-06",
  84. from_wkt<S>("SEGMENT(0 0,1 1)"),
  85. from_wkt<S>("SEGMENT(1 1,1 1)"),
  86. false);
  87. tester::apply("s-s-07",
  88. from_wkt<S>("SEGMENT(0 0,1 1)"),
  89. from_wkt<S>("SEGMENT(2 2,2 2)"),
  90. true);
  91. tester::apply("s-s-08",
  92. from_wkt<S>("SEGMENT(0 0,1 1)"),
  93. from_wkt<S>("SEGMENT(2 2,3 3)"),
  94. true);
  95. }
  96. template <typename P>
  97. inline void test_linestring_segment()
  98. {
  99. typedef bg::model::segment<P> S;
  100. typedef bg::model::linestring<P> L;
  101. typedef test_disjoint tester;
  102. tester::apply("l-s-01",
  103. from_wkt<S>("SEGMENT(0 0,2 0)"),
  104. from_wkt<L>("LINESTRING(0 0,0 2)"),
  105. false);
  106. tester::apply("l-s-02",
  107. from_wkt<S>("SEGMENT(0 0,2 0)"),
  108. from_wkt<L>("LINESTRING(2 0,3 0)"),
  109. false);
  110. tester::apply("l-s-03",
  111. from_wkt<S>("SEGMENT(0 0,2 0)"),
  112. from_wkt<L>("LINESTRING(1 0,3 0)"),
  113. false);
  114. tester::apply("l-s-04",
  115. from_wkt<S>("SEGMENT(0 0,2 0)"),
  116. from_wkt<L>("LINESTRING(1 0,1 1)"),
  117. false);
  118. tester::apply("l-s-05",
  119. from_wkt<S>("SEGMENT(0 0,2 0)"),
  120. from_wkt<L>("LINESTRING(1 1,2 2)"),
  121. true);
  122. tester::apply("l-s-06",
  123. from_wkt<S>("SEGMENT(0 0,2 0)"),
  124. from_wkt<L>("LINESTRING(1 1,1 1,2 2)"),
  125. true);
  126. tester::apply("l-s-07",
  127. from_wkt<S>("SEGMENT(0 0,2 0)"),
  128. from_wkt<L>("LINESTRING(1 0,1 0,1 1,2 2)"),
  129. false);
  130. tester::apply("l-s-08",
  131. from_wkt<S>("SEGMENT(0 0,2 0)"),
  132. from_wkt<L>("LINESTRING(1 0,1 0,3 0)"),
  133. false);
  134. tester::apply("l-s-09",
  135. from_wkt<S>("SEGMENT(0 0,2 0)"),
  136. from_wkt<L>("LINESTRING(3 0,3 0,4 0)"),
  137. true);
  138. tester::apply("l-s-10",
  139. from_wkt<S>("SEGMENT(0 0,2 0)"),
  140. from_wkt<L>("LINESTRING(3 0,3 0)"),
  141. true);
  142. tester::apply("l-s-11",
  143. from_wkt<S>("SEGMENT(0 0,2 0)"),
  144. from_wkt<L>("LINESTRING(-1 0,-1 0)"),
  145. true);
  146. tester::apply("l-s-12",
  147. from_wkt<S>("SEGMENT(0 0,2 0)"),
  148. from_wkt<L>("LINESTRING(1 0,1 0)"),
  149. false);
  150. tester::apply("l-s-13",
  151. from_wkt<S>("SEGMENT(0 0,2 0)"),
  152. from_wkt<L>("LINESTRING(1 1,1 1)"),
  153. true);
  154. }
  155. template <typename P>
  156. inline void test_multilinestring_segment()
  157. {
  158. typedef bg::model::segment<P> S;
  159. typedef bg::model::linestring<P> L;
  160. typedef bg::model::multi_linestring<L> ML;
  161. typedef test_disjoint tester;
  162. tester::apply("s-ml-01",
  163. from_wkt<S>("SEGMENT(0 0,2 0)"),
  164. from_wkt<ML>("MULTILINESTRING((0 0,0 2))"),
  165. false);
  166. tester::apply("s-ml-02",
  167. from_wkt<S>("SEGMENT(0 0,2 0)"),
  168. from_wkt<ML>("MULTILINESTRING((2 0,3 0))"),
  169. false);
  170. tester::apply("s-ml-03",
  171. from_wkt<S>("SEGMENT(0 0,2 0)"),
  172. from_wkt<ML>("MULTILINESTRING((1 0,3 0))"),
  173. false);
  174. tester::apply("s-ml-04",
  175. from_wkt<S>("SEGMENT(0 0,2 0)"),
  176. from_wkt<ML>("MULTILINESTRING((1 0,1 1))"),
  177. false);
  178. tester::apply("s-ml-05",
  179. from_wkt<S>("SEGMENT(0 0,2 0)"),
  180. from_wkt<ML>("MULTILINESTRING((1 1,2 2))"),
  181. true);
  182. tester::apply("s-ml-06",
  183. from_wkt<S>("SEGMENT(0 0,2 0)"),
  184. from_wkt<ML>("MULTILINESTRING((1 1,2 2),(3 3,3 3))"),
  185. true);
  186. tester::apply("s-ml-07",
  187. from_wkt<S>("SEGMENT(0 0,2 0)"),
  188. from_wkt<ML>("MULTILINESTRING((1 1,2 2),(1 0,1 0))"),
  189. false);
  190. tester::apply("s-ml-08",
  191. from_wkt<S>("SEGMENT(0 0,2 0)"),
  192. from_wkt<ML>("MULTILINESTRING((1 1,2 2),(3 0,3 0))"),
  193. true);
  194. }
  195. template <typename P>
  196. inline void test_linestring_linestring()
  197. {
  198. typedef bg::model::linestring<P> L;
  199. typedef test_disjoint tester;
  200. tester::apply("l-l-01",
  201. from_wkt<L>("LINESTRING(0 0,2 0)"),
  202. from_wkt<L>("LINESTRING(0 0,0 2)"),
  203. false);
  204. tester::apply("l-l-02",
  205. from_wkt<L>("LINESTRING(0 0,2 0)"),
  206. from_wkt<L>("LINESTRING(2 0,3 0)"),
  207. false);
  208. tester::apply("l-l-03",
  209. from_wkt<L>("LINESTRING(0 0,2 0)"),
  210. from_wkt<L>("LINESTRING(1 0,3 0)"),
  211. false);
  212. tester::apply("l-l-04",
  213. from_wkt<L>("LINESTRING(0 0,2 0)"),
  214. from_wkt<L>("LINESTRING(1 0,1 1)"),
  215. false);
  216. tester::apply("l-l-05",
  217. from_wkt<L>("LINESTRING(0 0,2 0)"),
  218. from_wkt<L>("LINESTRING(1 1,2 2)"),
  219. true);
  220. }
  221. template <typename P>
  222. inline void test_linestring_multilinestring()
  223. {
  224. typedef bg::model::linestring<P> L;
  225. typedef bg::model::multi_linestring<L> ML;
  226. typedef test_disjoint tester;
  227. tester::apply("l-ml-01",
  228. from_wkt<L>("LINESTRING(0 0,2 0)"),
  229. from_wkt<ML>("MULTILINESTRING((0 0,0 2))"),
  230. false);
  231. tester::apply("l-ml-02",
  232. from_wkt<L>("LINESTRING(0 0,2 0)"),
  233. from_wkt<ML>("MULTILINESTRING((2 0,3 0))"),
  234. false);
  235. tester::apply("l-ml-03",
  236. from_wkt<L>("LINESTRING(0 0,2 0)"),
  237. from_wkt<ML>("MULTILINESTRING((1 0,3 0))"),
  238. false);
  239. tester::apply("l-ml-04",
  240. from_wkt<L>("LINESTRING(0 0,2 0)"),
  241. from_wkt<ML>("MULTILINESTRING((1 0,1 1))"),
  242. false);
  243. tester::apply("l-ml-05",
  244. from_wkt<L>("LINESTRING(0 0,2 0)"),
  245. from_wkt<ML>("MULTILINESTRING((1 1,2 2))"),
  246. true);
  247. }
  248. template <typename P>
  249. inline void test_multilinestring_multilinestring()
  250. {
  251. typedef bg::model::linestring<P> L;
  252. typedef bg::model::multi_linestring<L> ML;
  253. typedef test_disjoint tester;
  254. tester::apply("ml-ml-01",
  255. from_wkt<ML>("MULTILINESTRING((0 0,2 0))"),
  256. from_wkt<ML>("MULTILINESTRING((0 0,0 2))"),
  257. false);
  258. tester::apply("ml-ml-02",
  259. from_wkt<ML>("MULTILINESTRING((0 0,2 0))"),
  260. from_wkt<ML>("MULTILINESTRING((2 0,3 0))"),
  261. false);
  262. tester::apply("ml-ml-03",
  263. from_wkt<ML>("MULTILINESTRING((0 0,2 0))"),
  264. from_wkt<ML>("MULTILINESTRING((1 0,3 0))"),
  265. false);
  266. tester::apply("ml-ml-04",
  267. from_wkt<ML>("MULTILINESTRING((0 0,2 0))"),
  268. from_wkt<ML>("MULTILINESTRING((1 0,1 1))"),
  269. false);
  270. tester::apply("ml-ml-05",
  271. from_wkt<ML>("MULTILINESTRING((0 0,2 0))"),
  272. from_wkt<ML>("MULTILINESTRING((1 1,2 2))"),
  273. true);
  274. }
  275. //============================================================================
  276. template <typename CoordinateType>
  277. inline void test_linear_linear()
  278. {
  279. typedef bg::model::point<CoordinateType, 2, bg::cs::cartesian> point_type;
  280. test_linestring_linestring<point_type>();
  281. test_linestring_multilinestring<point_type>();
  282. test_linestring_segment<point_type>();
  283. test_multilinestring_multilinestring<point_type>();
  284. test_multilinestring_segment<point_type>();
  285. test_segment_segment<point_type>();
  286. }
  287. //============================================================================
  288. BOOST_AUTO_TEST_CASE( test_linear_linear_all )
  289. {
  290. test_linear_linear<double>();
  291. test_linear_linear<int>();
  292. #ifdef HAVE_TTMATH
  293. test_linear_linear<ttmath_big>();
  294. #endif
  295. }