distance_se_geo_l_ar.cpp 29 KB

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