distance_geo_linear_box.cpp 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567
  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. // Unit Test
  3. // Copyright (c) 2017, 2018 Oracle and/or its affiliates.
  4. // Contributed and/or modified by Vissarion Fysikopoulos, on behalf of Oracle
  5. // Licensed under the Boost Software License version 1.0.
  6. // http://www.boost.org/users/license.html
  7. #include <iostream>
  8. #ifndef BOOST_TEST_MODULE
  9. #define BOOST_TEST_MODULE test_distance_geographic_linear_areal
  10. #endif
  11. #include <boost/range.hpp>
  12. #include <boost/type_traits/is_same.hpp>
  13. #include <boost/test/included/unit_test.hpp>
  14. #include <boost/geometry/util/condition.hpp>
  15. #include <boost/geometry/strategies/strategies.hpp>
  16. #include "test_distance_geo_common.hpp"
  17. //#include "test_empty_geometry.hpp"
  18. template <typename Point, typename Strategy_pp, typename Strategy_ps>
  19. void test_distance_segment_polygon(Strategy_pp const& strategy_pp,
  20. Strategy_ps const& strategy_ps)
  21. {
  22. #ifdef BOOST_GEOMETRY_TEST_DEBUG
  23. std::cout << std::endl;
  24. std::cout << "segment/polygon distance tests" << std::endl;
  25. #endif
  26. typedef bg::model::segment<Point> segment_type;
  27. typedef bg::model::polygon<Point> polygon_type;
  28. typedef test_distance_of_geometries<segment_type, polygon_type> tester;
  29. std::string const polygon = "POLYGON((10 10,0 20, 15 30, 20 15, 15 10, 10 10))";
  30. tester::apply("s-r-1", "SEGMENT(0 0, 0 10)", polygon,
  31. ps_distance<Point>("POINT(0 10)", "SEGMENT(0 20, 10 10)", strategy_ps),
  32. strategy_ps, true, false, false);
  33. }
  34. template <typename Point, typename Strategy_pp, typename Strategy_ps>
  35. void test_distance_linestring_polygon(Strategy_pp const& strategy_pp,
  36. Strategy_ps const& strategy_ps)
  37. {
  38. #ifdef BOOST_GEOMETRY_TEST_DEBUG
  39. std::cout << std::endl;
  40. std::cout << "linestring/polygon distance tests" << std::endl;
  41. #endif
  42. typedef bg::model::linestring<Point> linestring_type;
  43. typedef bg::model::polygon<Point> polygon_type;
  44. typedef test_distance_of_geometries<linestring_type, polygon_type> tester;
  45. std::string const polygon = "POLYGON((10 10,0 20, 15 30, 20 15, 15 10, 10 10))";
  46. tester::apply("l-r-1", "LINESTRING(0 0, 0 10)", polygon,
  47. ps_distance<Point>("POINT(0 10)", "SEGMENT(0 20, 10 10)", strategy_ps),
  48. strategy_ps, true, false, false);
  49. }
  50. template <typename Point, typename Strategy_pp, typename Strategy_ps>
  51. void test_distance_multi_linestring_polygon(Strategy_pp const& strategy_pp,
  52. Strategy_ps const& strategy_ps)
  53. {
  54. #ifdef BOOST_GEOMETRY_TEST_DEBUG
  55. std::cout << std::endl;
  56. std::cout << "multilinestring/polygon distance tests" << std::endl;
  57. #endif
  58. typedef bg::model::linestring<Point> linestring_type;
  59. typedef bg::model::multi_linestring<linestring_type> multi_linestring_type;
  60. typedef bg::model::polygon<Point> polygon_type;
  61. typedef test_distance_of_geometries<multi_linestring_type, polygon_type> tester;
  62. std::string const polygon = "POLYGON((10 10,0 20, 15 30, 20 15, 15 10, 10 10))";
  63. tester::apply("ml-r-1", "MULTILINESTRING((0 0, 0 10)(0 0, 10 0))", polygon,
  64. ps_distance<Point>("POINT(0 10)", "SEGMENT(0 20, 10 10)", strategy_ps),
  65. strategy_ps, true, false, false);
  66. }
  67. //=====================================================================
  68. template <typename Point, typename Strategy_pp, typename Strategy_ps>
  69. void test_distance_segment_multi_polygon(Strategy_pp const& strategy_pp,
  70. Strategy_ps const& strategy_ps)
  71. {
  72. #ifdef BOOST_GEOMETRY_TEST_DEBUG
  73. std::cout << std::endl;
  74. std::cout << "segment/multi_polygon distance tests" << std::endl;
  75. #endif
  76. typedef bg::model::segment<Point> segment_type;
  77. typedef bg::model::polygon<Point> polygon_type;
  78. typedef bg::model::multi_polygon<polygon_type> multi_polygon_type;
  79. typedef test_distance_of_geometries<segment_type, multi_polygon_type> tester;
  80. std::string const mp = "MULTIPOLYGON(((20 20, 20 30, 30 40, 20 20)),\
  81. ((10 10,0 20, 15 30, 20 15, 15 10, 10 10)))";
  82. tester::apply("s-r-1", "SEGMENT(0 0, 0 10)", mp,
  83. ps_distance<Point>("POINT(0 10)", "SEGMENT(0 20, 10 10)", strategy_ps),
  84. strategy_ps, true, false, false);
  85. }
  86. template <typename Point, typename Strategy_pp, typename Strategy_ps>
  87. void test_distance_linestring_multi_polygon(Strategy_pp const& strategy_pp,
  88. Strategy_ps const& strategy_ps)
  89. {
  90. #ifdef BOOST_GEOMETRY_TEST_DEBUG
  91. std::cout << std::endl;
  92. std::cout << "linestring/multi_polygon distance tests" << std::endl;
  93. #endif
  94. typedef bg::model::linestring<Point> linestring_type;
  95. typedef bg::model::polygon<Point> polygon_type;
  96. typedef bg::model::multi_polygon<polygon_type> multi_polygon_type;
  97. typedef test_distance_of_geometries<linestring_type, multi_polygon_type> tester;
  98. std::string const mp = "MULTIPOLYGON(((20 20, 20 30, 30 40, 20 20)),\
  99. ((10 10,0 20, 15 30, 20 15, 15 10, 10 10)))";
  100. tester::apply("l-r-1", "LINESTRING(0 0, 0 10)", mp,
  101. ps_distance<Point>("POINT(0 10)", "SEGMENT(0 20, 10 10)", strategy_ps),
  102. strategy_ps, true, false, false);
  103. }
  104. template <typename Point, typename Strategy_pp, typename Strategy_ps>
  105. void test_distance_multi_linestring_multi_polygon(Strategy_pp const& strategy_pp,
  106. Strategy_ps const& strategy_ps)
  107. {
  108. #ifdef BOOST_GEOMETRY_TEST_DEBUG
  109. std::cout << std::endl;
  110. std::cout << "multilinestring/multi_polygon distance tests" << std::endl;
  111. #endif
  112. typedef bg::model::linestring<Point> linestring_type;
  113. typedef bg::model::multi_linestring<linestring_type> multi_linestring_type;
  114. typedef bg::model::polygon<Point> polygon_type;
  115. typedef bg::model::multi_polygon<polygon_type> multi_polygon_type;
  116. typedef test_distance_of_geometries<multi_linestring_type, multi_polygon_type> tester;
  117. std::string const polygon = "MULTIPOLYGON(((20 20, 20 30, 30 40, 20 20)),\
  118. ((10 10,0 20, 15 30, 20 15, 15 10, 10 10)))";
  119. tester::apply("ml-r-1", "MULTILINESTRING((0 0, 0 10)(0 0, 10 0))", polygon,
  120. ps_distance<Point>("POINT(0 10)", "SEGMENT(0 20, 10 10)", strategy_ps),
  121. strategy_ps, true, false, false);
  122. }
  123. //=====================================================================
  124. template <typename Point, typename Strategy_pp, typename Strategy_ps>
  125. void test_distance_segment_ring(Strategy_pp const& strategy_pp,
  126. Strategy_ps const& strategy_ps)
  127. {
  128. #ifdef BOOST_GEOMETRY_TEST_DEBUG
  129. std::cout << std::endl;
  130. std::cout << "segment/ring distance tests" << std::endl;
  131. #endif
  132. typedef bg::model::segment<Point> segment_type;
  133. typedef bg::model::ring<Point> ring_type;
  134. typedef test_distance_of_geometries<segment_type, ring_type> tester;
  135. std::string const ring = "POLYGON((10 10,0 20, 15 30, 20 15, 15 10, 10 10))";
  136. tester::apply("s-r-1", "SEGMENT(0 0, 0 10)", ring,
  137. ps_distance<Point>("POINT(0 10)", "SEGMENT(0 20, 10 10)", strategy_ps),
  138. strategy_ps, true, false, false);
  139. }
  140. template <typename Point, typename Strategy_pp, typename Strategy_ps>
  141. void test_distance_linestring_ring(Strategy_pp const& strategy_pp,
  142. Strategy_ps const& strategy_ps)
  143. {
  144. #ifdef BOOST_GEOMETRY_TEST_DEBUG
  145. std::cout << std::endl;
  146. std::cout << "linestring/ring distance tests" << std::endl;
  147. #endif
  148. typedef bg::model::linestring<Point> linestring_type;
  149. typedef bg::model::ring<Point> ring_type;
  150. typedef test_distance_of_geometries<linestring_type, ring_type> tester;
  151. std::string const ring = "POLYGON((10 10,0 20, 15 30, 20 15, 15 10, 10 10))";
  152. tester::apply("l-r-1", "LINESTRING(0 0, 0 10)", ring,
  153. ps_distance<Point>("POINT(0 10)", "SEGMENT(0 20, 10 10)", strategy_ps),
  154. strategy_ps, true, false, false);
  155. }
  156. template <typename Point, typename Strategy_pp, typename Strategy_ps>
  157. void test_distance_multi_linestring_ring(Strategy_pp const& strategy_pp,
  158. Strategy_ps const& strategy_ps)
  159. {
  160. #ifdef BOOST_GEOMETRY_TEST_DEBUG
  161. std::cout << std::endl;
  162. std::cout << "multilinestring/ring distance tests" << std::endl;
  163. #endif
  164. typedef bg::model::linestring<Point> linestring_type;
  165. typedef bg::model::multi_linestring<linestring_type> multi_linestring_type;
  166. typedef bg::model::ring<Point> ring_type;
  167. typedef test_distance_of_geometries<multi_linestring_type, ring_type> tester;
  168. std::string const ring = "POLYGON((10 10,0 20, 15 30, 20 15, 15 10, 10 10))";
  169. tester::apply("ml-r-1", "MULTILINESTRING((0 0, 0 10)(0 0, 10 0))", ring,
  170. ps_distance<Point>("POINT(0 10)", "SEGMENT(0 20, 10 10)", strategy_ps),
  171. strategy_ps, true, false, false);
  172. }
  173. //======================================================================
  174. template <typename Point, typename Strategy_pp, typename Strategy_ps, typename Strategy_sb>
  175. void test_distance_segment_box(Strategy_pp const& strategy_pp,
  176. Strategy_ps const& strategy_ps,
  177. Strategy_sb const& strategy_sb)
  178. {
  179. #ifdef BOOST_GEOMETRY_TEST_DEBUG
  180. std::cout << std::endl;
  181. std::cout << "segment/box distance tests" << std::endl;
  182. #endif
  183. typedef bg::model::segment<Point> segment_type;
  184. typedef bg::model::box<Point> box_type;
  185. typedef test_distance_of_geometries<segment_type, box_type> tester;
  186. std::string const box_north = "BOX(10 10,20 20)";
  187. tester::apply("sb1-1a", "SEGMENT(0 0, 0 20)", box_north,
  188. pp_distance<Point>("POINT(0 20)", "POINT(10 20)", strategy_pp),
  189. strategy_sb);
  190. //segment with slope
  191. tester::apply("sb1-1b", "SEGMENT(10 5, 20 6)", box_north,
  192. pp_distance<Point>("POINT(20 6)", "POINT(20 10)", strategy_pp),
  193. strategy_sb);
  194. tester::apply("sb1-2", "SEGMENT(0 0, 0 10)", box_north,
  195. ps_distance<Point>("POINT(0 10)", "SEGMENT(10 10,10 20)", strategy_ps),
  196. strategy_sb);
  197. tester::apply("sb1-3", "SEGMENT(0 0, 0 15)", box_north,
  198. ps_distance<Point>("POINT(0 15)", "SEGMENT(10 10,10 20)", strategy_ps),
  199. strategy_sb);
  200. tester::apply("sb1-4", "SEGMENT(0 0, 0 25)", box_north,
  201. ps_distance<Point>("POINT(10 20)", "SEGMENT(0 0,0 25)", strategy_ps),
  202. strategy_sb);
  203. tester::apply("sb1-5", "SEGMENT(0 10, 0 25)", box_north,
  204. ps_distance<Point>("POINT(10 20)", "SEGMENT(0 0,0 25)", strategy_ps),
  205. strategy_sb);
  206. tester::apply("sb2-2", "SEGMENT(0 5, 15 5)", box_north,
  207. ps_distance<Point>("POINT(10 10)", "SEGMENT(0 5,15 5)", strategy_ps),
  208. strategy_sb);
  209. tester::apply("sb2-3a", "SEGMENT(0 5, 20 5)", box_north,
  210. ps_distance<Point>("POINT(10 10)", "SEGMENT(0 5,20 5)", strategy_ps),
  211. strategy_sb);
  212. // Test segments below box
  213. tester::apply("test_b1", "SEGMENT(0 5, 9 5)", box_north,
  214. ps_distance<Point>("POINT(10 10)", "SEGMENT(0 5, 9 5)", strategy_ps),
  215. strategy_sb);
  216. tester::apply("test_b2", "SEGMENT(0 5, 10 5)", box_north,
  217. ps_distance<Point>("POINT(10 10)", "SEGMENT(0 5, 10 5)", strategy_ps),
  218. strategy_sb);
  219. tester::apply("test_b3", "SEGMENT(0 5, 11 5)", box_north,
  220. ps_distance<Point>("POINT(10 10)", "SEGMENT(0 5, 11 5)", strategy_ps),
  221. strategy_sb);
  222. tester::apply("test_b4", "SEGMENT(0 5, 20 5)", box_north,
  223. ps_distance<Point>("POINT(10 10)", "SEGMENT(0 5,20 5)", strategy_ps),
  224. strategy_sb);
  225. tester::apply("test_b5", "SEGMENT(0 5, 22 5)", box_north,
  226. ps_distance<Point>("POINT(11 10)", "SEGMENT(0 5,22 5)", strategy_ps),
  227. strategy_sb);
  228. tester::apply("test_b6", "SEGMENT(10 5, 20 5)", box_north,
  229. ps_distance<Point>("POINT(15 10)", "SEGMENT(10 5,20 5)", strategy_ps),
  230. strategy_sb);
  231. tester::apply("test_b7", "SEGMENT(10 5, 22 5)", box_north,
  232. ps_distance<Point>("POINT(16 10)", "SEGMENT(10 5,22 5)", strategy_ps),
  233. strategy_sb);
  234. tester::apply("test_b8", "SEGMENT(12 5, 22 5)", box_north,
  235. ps_distance<Point>("POINT(17 10)", "SEGMENT(12 5,22 5)", strategy_ps),
  236. strategy_sb);
  237. tester::apply("test_b9", "SEGMENT(18 5, 22 5)", box_north,
  238. ps_distance<Point>("POINT(20 10)", "SEGMENT(18 5,22 5)", strategy_ps),
  239. strategy_sb);
  240. tester::apply("test_b10", "SEGMENT(18 5, 24 5)", box_north,
  241. ps_distance<Point>("POINT(20 10)", "SEGMENT(18 5,24 5)", strategy_ps),
  242. strategy_sb);
  243. tester::apply("test_b11", "SEGMENT(20 5, 24 5)", box_north,
  244. ps_distance<Point>("POINT(20 10)", "SEGMENT(20 5,24 5)", strategy_ps),
  245. strategy_sb);
  246. tester::apply("test_b12", "SEGMENT(22 5, 24 5)", box_north,
  247. ps_distance<Point>("POINT(20 10)", "SEGMENT(22 5,24 5)", strategy_ps),
  248. strategy_sb);
  249. tester::apply("test_b13", "SEGMENT(0 5, 125 5)", box_north,
  250. ps_distance<Point>("POINT(20 10)", "SEGMENT(0 5, 125 5)", strategy_ps),
  251. strategy_sb);
  252. // Test segments above box
  253. tester::apply("test_a1", "SEGMENT(0 25, 9 25)", box_north,
  254. ps_distance<Point>("POINT(10 20)", "SEGMENT(0 25, 9 25)", strategy_ps),
  255. strategy_sb);
  256. tester::apply("test_a2", "SEGMENT(0 25, 10 25)", box_north,
  257. ps_distance<Point>("POINT(10 20)", "SEGMENT(0 25, 10 25)", strategy_ps),
  258. strategy_sb);
  259. tester::apply("test_a3", "SEGMENT(0 25, 11 25)", box_north,
  260. ps_distance<Point>("POINT(11 20)", "SEGMENT(0 25, 11 25)", strategy_ps),
  261. strategy_sb);
  262. tester::apply("test_a4", "SEGMENT(0 25, 20 25)", box_north,
  263. ps_distance<Point>("POINT(20 20)", "SEGMENT(0 25, 20 25)", strategy_ps),
  264. strategy_sb);
  265. tester::apply("test_a5", "SEGMENT(0 25, 22 25)", box_north,
  266. ps_distance<Point>("POINT(20 20)", "SEGMENT(0 25, 22 25)", strategy_ps),
  267. strategy_sb);
  268. tester::apply("test_a6", "SEGMENT(10 25, 20 25)", box_north,
  269. ps_distance<Point>("POINT(20 20)", "SEGMENT(10 25, 20 25)", strategy_ps),
  270. strategy_sb);
  271. tester::apply("test_a7", "SEGMENT(10 25, 22 25)", box_north,
  272. ps_distance<Point>("POINT(10 20)", "SEGMENT(10 25, 22 25)", strategy_ps),
  273. strategy_sb);
  274. tester::apply("test_a8", "SEGMENT(12 25, 22 25)", box_north,
  275. ps_distance<Point>("POINT(12 20)", "SEGMENT(12 25, 22 25)", strategy_ps),
  276. strategy_sb);
  277. tester::apply("test_a9", "SEGMENT(18 25, 22 25)", box_north,
  278. ps_distance<Point>("POINT(18 20)", "SEGMENT(18 25, 22 25)", strategy_ps),
  279. strategy_sb);
  280. tester::apply("test_a10", "SEGMENT(18 25, 24 25)", box_north,
  281. ps_distance<Point>("POINT(18 20)", "SEGMENT(18 25, 24 25)", strategy_ps),
  282. strategy_sb);
  283. tester::apply("test_a11", "SEGMENT(20 25, 24 25)", box_north,
  284. ps_distance<Point>("POINT(20 20)", "SEGMENT(20 25, 24 25)", strategy_ps),
  285. strategy_sb);
  286. tester::apply("test_a12", "SEGMENT(22 25, 24 25)", box_north,
  287. ps_distance<Point>("POINT(20 20)", "SEGMENT(22 25, 24 25)", strategy_ps),
  288. strategy_sb);
  289. // Segments left-right of box
  290. tester::apply("test_l1", "SEGMENT(0 5, 9 5)", box_north,
  291. ps_distance<Point>("POINT(10 10)", "SEGMENT(0 5, 9 5)", strategy_ps),
  292. strategy_sb);
  293. tester::apply("test_l2", "SEGMENT(0 10, 9 10)", box_north,
  294. ps_distance<Point>("POINT(9 10)", "SEGMENT(10 10, 10 20)", strategy_ps),
  295. strategy_sb);
  296. tester::apply("test_l3", "SEGMENT(0 10, 9 15)", box_north,
  297. ps_distance<Point>("POINT(9 15)", "SEGMENT(10 10, 10 20)", strategy_ps),
  298. strategy_sb);
  299. tester::apply("test_l4", "SEGMENT(0 10, 0 15)", box_north,
  300. ps_distance<Point>("POINT(0 15)", "SEGMENT(10 10, 10 20)", strategy_ps),
  301. strategy_sb);
  302. tester::apply("test_l5", "SEGMENT(1 10, 0 15)", box_north,
  303. ps_distance<Point>("POINT(1 10)", "SEGMENT(10 10, 10 20)", strategy_ps),
  304. strategy_sb);
  305. tester::apply("test_l6", "SEGMENT(0 20, 9 21)", box_north,
  306. ps_distance<Point>("POINT(9 21)", "SEGMENT(10 10, 10 20)", strategy_ps),
  307. strategy_sb);
  308. tester::apply("test_r1", "SEGMENT(21 5, 29 5)", box_north,
  309. ps_distance<Point>("POINT(20 10)", "SEGMENT(21 5, 29 5)", strategy_ps),
  310. strategy_sb);
  311. tester::apply("test_r2", "SEGMENT(21 10, 29 10)", box_north,
  312. ps_distance<Point>("POINT(21 10)", "SEGMENT(20 10, 20 20)", strategy_ps),
  313. strategy_sb);
  314. tester::apply("test_r3", "SEGMENT(21 10, 29 15)", box_north,
  315. ps_distance<Point>("POINT(21 10)", "SEGMENT(20 10, 20 20)", strategy_ps),
  316. strategy_sb);
  317. tester::apply("test_r4", "SEGMENT(21 10, 21 15)", box_north,
  318. ps_distance<Point>("POINT(21 15)", "SEGMENT(20 10, 20 20)", strategy_ps),
  319. strategy_sb);
  320. tester::apply("test_r5", "SEGMENT(21 10, 22 15)", box_north,
  321. ps_distance<Point>("POINT(21 10)", "SEGMENT(20 10, 20 20)", strategy_ps),
  322. strategy_sb);
  323. tester::apply("test_r6", "SEGMENT(29 20, 21 21)", box_north,
  324. ps_distance<Point>("POINT(21 21)", "SEGMENT(20 10, 20 20)", strategy_ps),
  325. strategy_sb);
  326. //Segments on corners of box
  327. //left-top corner
  328. //generic
  329. tester::apply("test_c1", "SEGMENT(9 19.5, 11 21)", box_north,
  330. ps_distance<Point>("POINT(10 20)", "SEGMENT(9 19.5, 11 21)", strategy_ps),
  331. strategy_sb);
  332. //degenerate
  333. tester::apply("test_c2", "SEGMENT(9 19, 11 21)", box_north,
  334. ps_distance<Point>("POINT(10 20)", "SEGMENT(9 19, 11 21)", strategy_ps),
  335. strategy_sb);
  336. //left-bottom corner
  337. //generic
  338. tester::apply("test_c3", "SEGMENT(8.5 11, 11 9)", box_north,
  339. ps_distance<Point>("POINT(10 10)", "SEGMENT(8.5 11, 11 9)", strategy_ps),
  340. strategy_sb);
  341. //degenerate
  342. tester::apply("test_c4", "SEGMENT(9 11, 11 9)", box_north,
  343. 0,
  344. strategy_sb);
  345. //right-top corner
  346. //generic
  347. tester::apply("test_c5", "SEGMENT(19 21, 21 19.5)", box_north,
  348. ps_distance<Point>("POINT(20 20)", "SEGMENT(19 21, 21 19.5)", strategy_ps),
  349. strategy_sb);
  350. //degenerate
  351. tester::apply("test_c6", "SEGMENT(19 21, 21 19)", box_north,
  352. ps_distance<Point>("POINT(20 20)", "SEGMENT(19 21, 21 19)", strategy_ps),
  353. strategy_sb);
  354. //right-bottom corner
  355. //generic
  356. tester::apply("test_c7", "SEGMENT(19 9, 21 10.5)", box_north,
  357. ps_distance<Point>("POINT(20 10)", "SEGMENT(19 9, 21 10.5)", strategy_ps),
  358. strategy_sb);
  359. tester::apply("test_c7", "SEGMENT(19 9, 21 11)", box_north,
  360. 0,
  361. strategy_sb);
  362. //Segment and box on different hemispheres
  363. std::string const box_south = "BOX(10 -20,20 -10)";
  364. tester::apply("test_ns1", "SEGMENT(10 20, 15 30)", box_south,
  365. ps_distance<Point>("POINT(10 -10)", "SEGMENT(10 20, 15 30)", strategy_ps),
  366. strategy_sb);
  367. tester::apply("test_ns2", "SEGMENT(0 10, 12 10)", box_south,
  368. pp_distance<Point>("POINT(12 10)", "POINT(12 -10)", strategy_pp),
  369. strategy_sb);
  370. tester::apply("test_ns3", "SEGMENT(10 10, 20 10)", box_south,
  371. pp_distance<Point>("POINT(10 10)", "POINT(10 -10)", strategy_pp),
  372. strategy_sb);
  373. tester::apply("test_ns4", "SEGMENT(0 -10, 12 -10)", box_north,
  374. pp_distance<Point>("POINT(12 10)", "POINT(12 -10)", strategy_pp),
  375. strategy_sb);
  376. tester::apply("test_ns5", "SEGMENT(10 -10, 20 -10)", box_north,
  377. pp_distance<Point>("POINT(10 -10)", "POINT(10 10)", strategy_pp),
  378. strategy_sb);
  379. //Box crossing equator
  380. std::string const box_crossing_eq = "BOX(10 -10,20 10)";
  381. tester::apply("test_cr1", "SEGMENT(10 20, 15 30)", box_crossing_eq,
  382. pp_distance<Point>("POINT(10 10)", "POINT(10 20)", strategy_pp),
  383. strategy_sb);
  384. tester::apply("test_cr2", "SEGMENT(10 -20, 15 -30)", box_crossing_eq,
  385. pp_distance<Point>("POINT(10 10)", "POINT(10 20)", strategy_pp),
  386. strategy_sb);
  387. //Box crossing prime meridian
  388. std::string const box_crossing_mer = "BOX(-10 10,15 20)";
  389. tester::apply("test_cr3", "SEGMENT(-5 25, 10 30)", box_crossing_mer,
  390. pp_distance<Point>("POINT(-5 25)", "POINT(-5 20)", strategy_pp),
  391. strategy_sb);
  392. tester::apply("test_cr4", "SEGMENT(-5 5, 10 7)", box_crossing_mer,
  393. pp_distance<Point>("POINT(10 7)", "POINT(10 10)", strategy_pp),
  394. strategy_sb);
  395. tester::apply("test_cr5", "SEGMENT(-5 5, 10 5)", box_crossing_mer,
  396. ps_distance<Point>("POINT(2.5 10)", "SEGMENT(-5 5, 10 5)", strategy_ps),
  397. strategy_sb);
  398. //Geometries in south hemisphere
  399. tester::apply("test_south1", "SEGMENT(10 -30, 15 -30)", box_south,
  400. ps_distance<Point>("POINT(10 -20)", "SEGMENT(10 -30, 15 -30)", strategy_ps),
  401. strategy_sb);
  402. //Segments in boxes corner
  403. tester::apply("corner1", "SEGMENT(17 21, 25 20)", box_north,
  404. ps_distance<Point>("POINT(20 20)", "SEGMENT(17 21, 25 20)", strategy_ps),
  405. strategy_sb);
  406. tester::apply("corner2", "SEGMENT(17 21, 0 20)", box_north,
  407. ps_distance<Point>("POINT(10 20)", "SEGMENT(17 21, 0 20)", strategy_ps),
  408. strategy_sb);
  409. tester::apply("corner3", "SEGMENT(17 5, 0 10)", box_north,
  410. ps_distance<Point>("POINT(10 10)", "SEGMENT(17 5, 0 10)", strategy_ps),
  411. strategy_sb);
  412. tester::apply("corner4", "SEGMENT(17 5, 25 9)", box_north,
  413. ps_distance<Point>("POINT(20 10)", "SEGMENT(17 5, 25 9)", strategy_ps),
  414. strategy_sb);
  415. }
  416. template <typename Point, typename Strategy_ps, typename Strategy_sb>
  417. void test_distance_linestring_box(Strategy_ps const& strategy_ps, Strategy_sb const& strategy_sb)
  418. {
  419. #ifdef BOOST_GEOMETRY_TEST_DEBUG
  420. std::cout << std::endl;
  421. std::cout << "linestring/box distance tests" << std::endl;
  422. #endif
  423. typedef bg::model::linestring<Point> linestring_type;
  424. typedef bg::model::box<Point> box_type;
  425. typedef test_distance_of_geometries<linestring_type, box_type> tester;
  426. std::string const box_north = "BOX(10 10,20 20)";
  427. tester::apply("sl1", "LINESTRING(0 20, 15 21, 25 19.9, 21 5, 15 5, 0 10)", box_north,
  428. ps_distance<Point>("POINT(20 20)", "SEGMENT(15 21, 25 19.9)", strategy_ps),
  429. strategy_ps, true, false, false);
  430. tester::apply("sl2", "LINESTRING(0 20, 15 21, 25 19.9, 21 5, 15 5, 15 15)", box_north,
  431. 0, strategy_ps, true, false, false);
  432. tester::apply("sl3", "LINESTRING(0 20, 15 21, 25 19.9, 21 5, 15 5, 2 20)", box_north,
  433. 0, strategy_ps, true, false, false);
  434. }
  435. template <typename Point, typename Strategy_ps, typename Strategy_sb>
  436. void test_distance_multi_linestring_box(Strategy_ps const& strategy_ps, Strategy_sb const& strategy_sb)
  437. {
  438. #ifdef BOOST_GEOMETRY_TEST_DEBUG
  439. std::cout << std::endl;
  440. std::cout << "multi_linestring/box distance tests" << std::endl;
  441. #endif
  442. typedef bg::model::linestring<Point> linestring_type;
  443. typedef bg::model::multi_linestring<linestring_type> multi_linestring_type;
  444. typedef bg::model::box<Point> box_type;
  445. typedef test_distance_of_geometries<multi_linestring_type, box_type> tester;
  446. std::string const box_north = "BOX(10 10,20 20)";
  447. tester::apply("sl1", "MULTILINESTRING((0 20, 15 21, 25 19.9, 21 5, 15 5, 0 10)(25 20, 22 4, 0 0))", box_north,
  448. ps_distance<Point>("POINT(20 20)", "SEGMENT(15 21, 25 19.9)", strategy_ps),
  449. strategy_sb, true, false, false);
  450. }
  451. //===========================================================================
  452. //===========================================================================
  453. //===========================================================================
  454. template <typename Point, typename Strategy_pp, typename Strategy_ps, typename Strategy_sb>
  455. void test_all_l_ar(Strategy_pp pp_strategy, Strategy_ps ps_strategy, Strategy_sb sb_strategy)
  456. {
  457. test_distance_segment_polygon<Point>(pp_strategy, ps_strategy);
  458. test_distance_linestring_polygon<Point>(pp_strategy, ps_strategy);
  459. test_distance_multi_linestring_polygon<Point>(pp_strategy, ps_strategy);
  460. test_distance_segment_multi_polygon<Point>(pp_strategy, ps_strategy);
  461. test_distance_linestring_multi_polygon<Point>(pp_strategy, ps_strategy);
  462. test_distance_multi_linestring_multi_polygon<Point>(pp_strategy, ps_strategy);
  463. test_distance_segment_ring<Point>(pp_strategy, ps_strategy);
  464. test_distance_linestring_ring<Point>(pp_strategy, ps_strategy);
  465. test_distance_multi_linestring_ring<Point>(pp_strategy, ps_strategy);
  466. test_distance_segment_box<Point>(pp_strategy, ps_strategy, sb_strategy);
  467. //test_distance_linestring_box<Point>(ps_strategy, sb_strategy);
  468. //test_distance_multi_linestring_box<Point>(ps_strategy, sb_strategy);
  469. //test_more_empty_input_linear_areal<Point>(ps_strategy);
  470. }
  471. BOOST_AUTO_TEST_CASE( test_all_linear_areal )
  472. {
  473. typedef bg::model::point<double, 2, bg::cs::spherical_equatorial<bg::degree> >
  474. sph_point;
  475. test_all_l_ar<sph_point>(spherical_pp(), spherical_ps(), spherical_sb());
  476. typedef bg::model::point<double, 2, bg::cs::geographic<bg::degree> > geo_point;
  477. test_all_l_ar<geo_point>(vincenty_pp(), vincenty_ps(), vincenty_sb());
  478. test_all_l_ar<geo_point>(thomas_pp(), thomas_ps(), thomas_sb());
  479. test_all_l_ar<geo_point>(andoyer_pp(), andoyer_ps(), andoyer_sb());
  480. }