disjoint_coverage_p_l.cpp 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391
  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. // pointlike-linear geometries
  58. template <typename P>
  59. inline void test_point_segment()
  60. {
  61. typedef test_disjoint tester;
  62. typedef bg::model::segment<P> S;
  63. tester::apply("p-s-01",
  64. from_wkt<P>("POINT(0 0)"),
  65. from_wkt<S>("SEGMENT(0 0,2 0)"),
  66. false);
  67. tester::apply("p-s-02",
  68. from_wkt<P>("POINT(2 0)"),
  69. from_wkt<S>("SEGMENT(0 0,2 0)"),
  70. false);
  71. tester::apply("p-s-03",
  72. from_wkt<P>("POINT(1 0)"),
  73. from_wkt<S>("SEGMENT(0 0,2 0)"),
  74. false);
  75. tester::apply("p-s-04",
  76. from_wkt<P>("POINT(1 1)"),
  77. from_wkt<S>("SEGMENT(0 0,2 0)"),
  78. true);
  79. tester::apply("p-s-05",
  80. from_wkt<P>("POINT(3 0)"),
  81. from_wkt<S>("SEGMENT(0 0,2 0)"),
  82. true);
  83. tester::apply("p-s-06",
  84. from_wkt<P>("POINT(-1 0)"),
  85. from_wkt<S>("SEGMENT(0 0,2 0)"),
  86. true);
  87. // degenerate segment
  88. tester::apply("p-s-07",
  89. from_wkt<P>("POINT(-1 0)"),
  90. from_wkt<S>("SEGMENT(2 0,2 0)"),
  91. true);
  92. // degenerate segment
  93. tester::apply("p-s-08",
  94. from_wkt<P>("POINT(2 0)"),
  95. from_wkt<S>("SEGMENT(2 0,2 0)"),
  96. false);
  97. // degenerate segment
  98. tester::apply("p-s-09",
  99. from_wkt<P>("POINT(3 0)"),
  100. from_wkt<S>("SEGMENT(2 0,2 0)"),
  101. true);
  102. // degenerate segment
  103. tester::apply("p-s-10",
  104. from_wkt<P>("POINT(1 1)"),
  105. from_wkt<S>("SEGMENT(2 0,2 0)"),
  106. true);
  107. }
  108. template <typename P>
  109. inline void test_point_linestring()
  110. {
  111. typedef bg::model::linestring<P> L;
  112. typedef test_disjoint tester;
  113. tester::apply("p-l-01",
  114. from_wkt<P>("POINT(0 0)"),
  115. from_wkt<L>("LINESTRING(0 0,2 2,4 4)"),
  116. false);
  117. tester::apply("p-l-02",
  118. from_wkt<P>("POINT(1 1)"),
  119. from_wkt<L>("LINESTRING(0 0,2 2,4 4)"),
  120. false);
  121. tester::apply("p-l-03",
  122. from_wkt<P>("POINT(3 3)"),
  123. from_wkt<L>("LINESTRING(0 0,2 2,4 4)"),
  124. false);
  125. tester::apply("p-l-04",
  126. from_wkt<P>("POINT(1 0)"),
  127. from_wkt<L>("LINESTRING(0 0,2 2,4 4)"),
  128. true);
  129. tester::apply("p-l-05",
  130. from_wkt<P>("POINT(5 5)"),
  131. from_wkt<L>("LINESTRING(0 0,2 2,4 4)"),
  132. true);
  133. tester::apply("p-l-06",
  134. from_wkt<P>("POINT(5 5)"),
  135. from_wkt<L>("LINESTRING(0 0,2 2)"),
  136. true);
  137. }
  138. template <typename P>
  139. inline void test_point_multilinestring()
  140. {
  141. typedef bg::model::linestring<P> L;
  142. typedef bg::model::multi_linestring<L> ML;
  143. typedef test_disjoint tester;
  144. tester::apply("p-ml-01",
  145. from_wkt<P>("POINT(0 1)"),
  146. from_wkt<ML>("MULTILINESTRING((0 0,2 2,4 4),(0 0,2 0,4 0))"),
  147. true);
  148. tester::apply("p-ml-02",
  149. from_wkt<P>("POINT(0 0)"),
  150. from_wkt<ML>("MULTILINESTRING((0 0,2 2,4 4),(0 0,2 0,4 0))"),
  151. false);
  152. tester::apply("p-ml-03",
  153. from_wkt<P>("POINT(1 1)"),
  154. from_wkt<ML>("MULTILINESTRING((0 0,2 2,4 4),(0 0,2 0,4 0))"),
  155. false);
  156. tester::apply("p-ml-04",
  157. from_wkt<P>("POINT(1 0)"),
  158. from_wkt<ML>("MULTILINESTRING((0 0,2 2,4 4),(0 0,2 0,4 0))"),
  159. false);
  160. tester::apply("p-ml-05",
  161. from_wkt<P>("POINT(0 0)"),
  162. from_wkt<ML>("MULTILINESTRING((1 1,2 2,4 4),(3 0,4 0))"),
  163. true);
  164. tester::apply("p-ml-06",
  165. from_wkt<P>("POINT(0 0)"),
  166. from_wkt<ML>("MULTILINESTRING((1 1,2 2,4 4),(0 0,4 0))"),
  167. false);
  168. tester::apply("p-ml-07",
  169. from_wkt<P>("POINT(0 0)"),
  170. from_wkt<ML>("MULTILINESTRING((1 1,2 2,4 4),(-1 0,4 0))"),
  171. false);
  172. }
  173. template <typename P>
  174. inline void test_multipoint_segment()
  175. {
  176. typedef test_disjoint tester;
  177. typedef bg::model::multi_point<P> MP;
  178. typedef bg::model::segment<P> S;
  179. tester::apply("mp-s-01",
  180. from_wkt<MP>("MULTIPOINT(0 0,1 1)"),
  181. from_wkt<S>("SEGMENT(0 0,2 0)"),
  182. false);
  183. tester::apply("mp-s-02",
  184. from_wkt<MP>("MULTIPOINT(1 0,1 1)"),
  185. from_wkt<S>("SEGMENT(0 0,2 0)"),
  186. false);
  187. tester::apply("mp-s-03",
  188. from_wkt<MP>("MULTIPOINT(1 1,2 2)"),
  189. from_wkt<S>("SEGMENT(0 0,2 0)"),
  190. true);
  191. tester::apply("mp-s-04",
  192. from_wkt<MP>("MULTIPOINT()"),
  193. from_wkt<S>("SEGMENT(0 0,2 0)"),
  194. true);
  195. tester::apply("mp-s-05",
  196. from_wkt<MP>("MULTIPOINT(3 0,4 0)"),
  197. from_wkt<S>("SEGMENT(0 0,2 0)"),
  198. true);
  199. tester::apply("mp-s-06",
  200. from_wkt<MP>("MULTIPOINT(1 0,4 0)"),
  201. from_wkt<S>("SEGMENT(0 0,2 0)"),
  202. false);
  203. // segments that degenerate to a point
  204. tester::apply("mp-s-07",
  205. from_wkt<MP>("MULTIPOINT(1 1,2 2)"),
  206. from_wkt<S>("SEGMENT(0 0,0 0)"),
  207. true);
  208. tester::apply("mp-s-08",
  209. from_wkt<MP>("MULTIPOINT(1 1,2 2)"),
  210. from_wkt<S>("SEGMENT(1 1,1 1)"),
  211. false);
  212. }
  213. template <typename P>
  214. inline void test_multipoint_linestring()
  215. {
  216. typedef bg::model::multi_point<P> MP;
  217. typedef bg::model::linestring<P> L;
  218. typedef test_disjoint tester;
  219. tester::apply("mp-l-01",
  220. from_wkt<MP>("MULTIPOINT(0 0,1 0)"),
  221. from_wkt<L>("LINESTRING(0 0,2 2,4 4)"),
  222. false);
  223. tester::apply("mp-l-02",
  224. from_wkt<MP>("MULTIPOINT(1 0,1 1)"),
  225. from_wkt<L>("LINESTRING(0 0,2 2,4 4)"),
  226. false);
  227. tester::apply("mp-l-03",
  228. from_wkt<MP>("MULTIPOINT(1 0,3 3)"),
  229. from_wkt<L>("LINESTRING(0 0,2 2,4 4)"),
  230. false);
  231. tester::apply("mp-l-04",
  232. from_wkt<MP>("MULTIPOINT(1 0,2 0)"),
  233. from_wkt<L>("LINESTRING(0 0,2 2,4 4)"),
  234. true);
  235. tester::apply("mp-l-05",
  236. from_wkt<MP>("MULTIPOINT(-1 -1,2 0)"),
  237. from_wkt<L>("LINESTRING(0 0,2 2,4 4)"),
  238. true);
  239. tester::apply("mp-l-06",
  240. from_wkt<MP>("MULTIPOINT(-1 -1,2 0)"),
  241. from_wkt<L>("LINESTRING(1 0,3 0)"),
  242. false);
  243. tester::apply("mp-l-07",
  244. from_wkt<MP>("MULTIPOINT(-1 -1,2 0,-1 -1,2 0)"),
  245. from_wkt<L>("LINESTRING(1 0,3 0)"),
  246. false);
  247. tester::apply("mp-l-08",
  248. from_wkt<MP>("MULTIPOINT(2 0)"),
  249. from_wkt<L>("LINESTRING(1 0)"),
  250. true);
  251. tester::apply("mp-l-09",
  252. from_wkt<MP>("MULTIPOINT(3 0,0 0,3 0)"),
  253. from_wkt<L>("LINESTRING(1 0,2 0)"),
  254. true);
  255. }
  256. template <typename P>
  257. inline void test_multipoint_multilinestring()
  258. {
  259. typedef bg::model::multi_point<P> MP;
  260. typedef bg::model::linestring<P> L;
  261. typedef bg::model::multi_linestring<L> ML;
  262. typedef test_disjoint tester;
  263. tester::apply("mp-ml-01",
  264. from_wkt<MP>("MULTIPOINT(0 1,0 2)"),
  265. from_wkt<ML>("MULTILINESTRING((0 0,2 2,4 4),(0 0,2 0,4 0))"),
  266. true);
  267. tester::apply("mp-ml-02",
  268. from_wkt<MP>("MULTIPOINT(0 0,1 0)"),
  269. from_wkt<ML>("MULTILINESTRING((0 0,2 2,4 4),(0 0,2 0,4 0))"),
  270. false);
  271. tester::apply("mp-ml-03",
  272. from_wkt<MP>("MULTIPOINT(0 1,1 1)"),
  273. from_wkt<ML>("MULTILINESTRING((0 0,2 2,4 4),(0 0,2 0,4 0))"),
  274. false);
  275. tester::apply("mp-ml-04",
  276. from_wkt<MP>("MULTIPOINT(0 1,1 0)"),
  277. from_wkt<ML>("MULTILINESTRING((0 0,2 2,4 4),(0 0,2 0,4 0))"),
  278. false);
  279. tester::apply("mp-ml-05",
  280. from_wkt<MP>("MULTIPOINT(0 0,10 0)"),
  281. from_wkt<ML>("MULTILINESTRING((0 0,2 2,4 4),(0 0,2 0,4 0))"),
  282. false);
  283. tester::apply("mp-ml-06",
  284. from_wkt<MP>("MULTIPOINT(-1 0,3 0)"),
  285. from_wkt<ML>("MULTILINESTRING((0 0,2 2,4 4),(0 0,2 0,4 0))"),
  286. false);
  287. }
  288. //============================================================================
  289. template <typename CoordinateType>
  290. inline void test_pointlike_linear()
  291. {
  292. typedef bg::model::point<CoordinateType, 2, bg::cs::cartesian> point_type;
  293. test_point_linestring<point_type>();
  294. test_point_multilinestring<point_type>();
  295. test_point_segment<point_type>();
  296. test_multipoint_linestring<point_type>();
  297. test_multipoint_multilinestring<point_type>();
  298. test_multipoint_segment<point_type>();
  299. }
  300. //============================================================================
  301. BOOST_AUTO_TEST_CASE( test_pointlike_linear_all )
  302. {
  303. test_pointlike_linear<double>();
  304. test_pointlike_linear<int>();
  305. #ifdef HAVE_TTMATH
  306. test_pointlike_linear<ttmath_big>();
  307. #endif
  308. }