distance_geo_pl_l.cpp 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728
  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. // Unit Test
  3. // Copyright (c) 2016-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. #ifndef BOOST_TEST_MODULE
  8. #define BOOST_TEST_MODULE test_distance_geographic_pointlike_linear
  9. #endif
  10. #include <sstream>
  11. #include <boost/geometry/srs/spheroid.hpp>
  12. #include <boost/test/included/unit_test.hpp>
  13. #include "test_distance_geo_common.hpp"
  14. #include "test_empty_geometry.hpp"
  15. typedef bg::cs::geographic<bg::degree> cs_type;
  16. typedef bg::model::point<double, 2, cs_type> point_type;
  17. typedef bg::model::segment<point_type> segment_type;
  18. typedef bg::model::multi_point<point_type> multi_point_type;
  19. typedef bg::model::segment<point_type> segment_type;
  20. typedef bg::model::linestring<point_type> linestring_type;
  21. typedef bg::model::multi_linestring<linestring_type> multi_linestring_type;
  22. typedef bg::cs::geographic<bg::radian> cs_type_rad;
  23. typedef bg::model::point<double, 2, cs_type_rad> point_type_rad;
  24. typedef bg::model::segment<point_type_rad> segment_type_rad;
  25. //===========================================================================
  26. template <typename Strategy>
  27. inline bg::default_distance_result<point_type>::type
  28. pp_distance(std::string const& wkt1,
  29. std::string const& wkt2,
  30. Strategy const& strategy)
  31. {
  32. point_type p1, p2;
  33. bg::read_wkt(wkt1, p1);
  34. bg::read_wkt(wkt2, p2);
  35. return bg::distance(p1, p2, strategy);
  36. }
  37. template <typename Strategy>
  38. inline bg::default_distance_result<point_type>::type
  39. ps_distance(std::string const& wkt1,
  40. std::string const& wkt2,
  41. Strategy const& strategy)
  42. {
  43. point_type p;
  44. segment_type s;
  45. bg::read_wkt(wkt1, p);
  46. bg::read_wkt(wkt2, s);
  47. return bg::distance(p, s, strategy);
  48. }
  49. //===========================================================================
  50. template <typename Strategy_pp, typename Strategy_ps>
  51. void test_distance_point_segment(Strategy_pp const& strategy_pp,
  52. Strategy_ps const& strategy_ps,
  53. bool WGS84)
  54. {
  55. #ifdef BOOST_GEOMETRY_TEST_DEBUG
  56. std::cout << std::endl;
  57. std::cout << "point/segment distance tests" << std::endl;
  58. #endif
  59. typedef test_distance_of_geometries<point_type, segment_type> tester;
  60. tester::apply("p-s-01",
  61. "POINT(0 0)",
  62. "SEGMENT(2 0,3 0)",
  63. pp_distance("POINT(0 0)", "POINT(2 0)", strategy_pp),
  64. strategy_ps, true, true);
  65. tester::apply("p-s-02",
  66. "POINT(2.5 3)",
  67. "SEGMENT(2 0,3 0)",
  68. pp_distance("POINT(2.5 3)", "POINT(2.5 0)", strategy_pp),
  69. strategy_ps, true, true);
  70. tester::apply("p-s-03",
  71. "POINT(2 0)",
  72. "SEGMENT(2 0,3 0)",
  73. 0,
  74. strategy_ps, true, true);
  75. tester::apply("p-s-04",
  76. "POINT(3 0)",
  77. "SEGMENT(2 0,3 0)",
  78. 0,
  79. strategy_ps, true, true);
  80. tester::apply("p-s-05",
  81. "POINT(2.5 0)",
  82. "SEGMENT(2 0,3 0)",
  83. 0,
  84. strategy_ps, true, true);
  85. tester::apply("p-s-06",
  86. "POINT(3.5 3)",
  87. "SEGMENT(2 0,3 0)",
  88. pp_distance("POINT(3 0)", "POINT(3.5 3)", strategy_pp),
  89. strategy_ps, true, true);
  90. if(WGS84)
  91. {
  92. tester::apply("p-s-07",
  93. "POINT(15 80)",
  94. "SEGMENT(10 15,30 15)",
  95. 7204174.8264546748,
  96. strategy_ps, true, true);
  97. tester::apply("p-s-08",
  98. "POINT(15 10)",
  99. "SEGMENT(10 15,30 15)",
  100. 571412.71247283253,
  101. strategy_ps, true, true);
  102. }
  103. tester::apply("p-s-09",
  104. "POINT(5 10)",
  105. "SEGMENT(10 15,30 15)",
  106. pp_distance("POINT(5 10)", "POINT(10 15)", strategy_pp),
  107. strategy_ps, true, true);
  108. tester::apply("p-s-10",
  109. "POINT(35 10)",
  110. "SEGMENT(10 15,30 15)",
  111. pp_distance("POINT(35 10)", "POINT(30 15)", strategy_pp),
  112. strategy_ps, true, true);
  113. tester::apply("p-s-11",
  114. "POINT(5 10)",
  115. "SEGMENT(30 15,10 15)",
  116. pp_distance("POINT(5 10)", "POINT(10 15)", strategy_pp),
  117. strategy_ps, true, true);
  118. tester::apply("p-s-12",
  119. "POINT(35 10)",
  120. "SEGMENT(30 15,10 15)",
  121. pp_distance("POINT(35 10)", "POINT(30 15)", strategy_pp),
  122. strategy_ps, true, true);
  123. tester::apply("p-s-right-up",
  124. "POINT(3.5 3)",
  125. "SEGMENT(2 2,3 2)",
  126. pp_distance("POINT(3 2)", "POINT(3.5 3)", strategy_pp),
  127. strategy_ps, true, true);
  128. tester::apply("p-s-left-up",
  129. "POINT(1.5 3)",
  130. "SEGMENT(2 2,3 2)",
  131. pp_distance("POINT(2 2)", "POINT(1.5 3)", strategy_pp),
  132. strategy_ps, true, true);
  133. tester::apply("p-s-up-1",
  134. "POINT(2 3)",
  135. "SEGMENT(2 2,3 2)",
  136. pp_distance("POINT(2.0003 2)", "POINT(2 3)", strategy_pp),
  137. strategy_ps, true, true);
  138. tester::apply("p-s-up-2",
  139. "POINT(3 3)",
  140. "SEGMENT(2 2,3 2)",
  141. pp_distance("POINT(2.9997 2)", "POINT(3 3)", strategy_pp),
  142. strategy_ps, true, true);
  143. tester::apply("p-s-right-down",
  144. "POINT(3.5 1)",
  145. "SEGMENT(2 2,3 2)",
  146. pp_distance("POINT(3 2)", "POINT(3.5 1)", strategy_pp),
  147. strategy_ps, true, true);
  148. tester::apply("p-s-left-down",
  149. "POINT(1.5 1)",
  150. "SEGMENT(2 2,3 2)",
  151. pp_distance("POINT(2 2)", "POINT(1.5 1)", strategy_pp),
  152. strategy_ps, true, true);
  153. tester::apply("p-s-down-1",
  154. "POINT(2 1)",
  155. "SEGMENT(2 2,3 2)",
  156. pp_distance("POINT(2 2)", "POINT(2 1)", strategy_pp),
  157. strategy_ps, true, true);
  158. tester::apply("p-s-down-2",
  159. "POINT(3 1)",
  160. "SEGMENT(2 2,3 2)",
  161. pp_distance("POINT(3 2)", "POINT(3 1)", strategy_pp),
  162. strategy_ps, true, true);
  163. tester::apply("p-s-south",
  164. "POINT(3 -1)",
  165. "SEGMENT(2 -2,3 -2)",
  166. pp_distance("POINT(3 -2)", "POINT(3 -1)", strategy_pp),
  167. strategy_ps, true, true);
  168. tester::apply("p-s-antimeridian-1",
  169. "POINT(3 1)",
  170. "SEGMENT(220 2,3 2)",
  171. pp_distance("POINT(3 2)", "POINT(3 1)", strategy_pp),
  172. strategy_ps, true, true);
  173. tester::apply("p-s-antimeridian-2",
  174. "POINT(220 1)",
  175. "SEGMENT(220 2,3 2)",
  176. pp_distance("POINT(220 2)", "POINT(220 1)", strategy_pp),
  177. strategy_ps, true, true);
  178. // equator special case
  179. tester::apply("p-s-eq1",
  180. "POINT(2.5 0)",
  181. "SEGMENT(2 0,3 0)",
  182. 0,
  183. strategy_ps, true, true);
  184. tester::apply("p-s-eq2",
  185. "POINT(2.5 2)",
  186. "SEGMENT(2 0,3 0)",
  187. pp_distance("POINT(2.5 0)", "POINT(2.5 2)", strategy_pp),
  188. strategy_ps, true, true);
  189. tester::apply("p-s-eq3",
  190. "POINT(2 2)",
  191. "SEGMENT(2 0,3 0)",
  192. pp_distance("POINT(2 0)", "POINT(2 2)", strategy_pp),
  193. strategy_ps, true, true);
  194. tester::apply("p-s-eq4",
  195. "POINT(3 2)",
  196. "SEGMENT(2 0,3 0)",
  197. pp_distance("POINT(3 0)", "POINT(3 2)", strategy_pp),
  198. strategy_ps, true, true);
  199. // meridian special case
  200. tester::apply("p-s-mer1",
  201. "POINT(2.5 2)",
  202. "SEGMENT(2 2,2 4)",
  203. pp_distance("POINT(2.5 2)", "POINT(2 2.000076608014728)", strategy_pp),
  204. strategy_ps, true, true);
  205. tester::apply("p-s-mer3",
  206. "POINT(2.5 5)",
  207. "SEGMENT(2 2,2 4)",
  208. pp_distance("POINT(2.5 5)", "POINT(2 4)", strategy_pp),
  209. strategy_ps, true, true);
  210. tester::apply("p-s-mer4",
  211. "POINT(0 20)",
  212. "SEGMENT(0 40,180 80)",
  213. pp_distance("POINT(0 20)", "POINT(0 40)", strategy_pp),
  214. strategy_ps, true, true);
  215. tester::apply("p-s-mer5",
  216. "POINT(0 20)",
  217. "SEGMENT(0 40,0 80)",
  218. pp_distance("POINT(0 20)", "POINT(0 40)", strategy_pp),
  219. strategy_ps, true, true);
  220. //degenerate segment
  221. tester::apply("p-s-deg",
  222. "POINT(1 80)",
  223. "SEGMENT(0 0,0 0)",
  224. pp_distance("POINT(0 0)", "POINT(1 80)", strategy_pp),
  225. strategy_ps, true, true);
  226. //point on segment
  227. tester::apply("p-s-deg",
  228. "POINT(0 80)",
  229. "SEGMENT(0 0,0 90)",
  230. 0,
  231. strategy_ps, true, true);
  232. // very small distances to segment
  233. tester::apply("p-s-07",
  234. "POINT(90 1e-3)",
  235. "SEGMENT(0.5 0,175.5 0)",
  236. pp_distance("POINT(90 0)", "POINT(90 1e-3)", strategy_pp),
  237. strategy_ps, true, true);
  238. tester::apply("p-s-08",
  239. "POINT(90 1e-4)",
  240. "SEGMENT(0.5 0,175.5 0)",
  241. pp_distance("POINT(90 0)", "POINT(90 1e-4)", strategy_pp),
  242. strategy_ps, true, true);
  243. tester::apply("p-s-09",
  244. "POINT(90 1e-5)",
  245. "SEGMENT(0.5 0,175.5 0)",
  246. pp_distance("POINT(90 0)", "POINT(90 1e-5)", strategy_pp),
  247. strategy_ps, true, true);
  248. tester::apply("p-s-10",
  249. "POINT(90 1e-6)",
  250. "SEGMENT(0.5 0,175.5 0)",
  251. pp_distance("POINT(90 0)", "POINT(90 1e-6)", strategy_pp),
  252. strategy_ps, true, true);
  253. tester::apply("p-s-11",
  254. "POINT(90 1e-7)",
  255. "SEGMENT(0.5 0,175.5 0)",
  256. pp_distance("POINT(90 0)", "POINT(90 1e-7)", strategy_pp),
  257. strategy_ps, true, true);
  258. tester::apply("p-s-12",
  259. "POINT(90 1e-8)",
  260. "SEGMENT(0.5 0,175.5 0)",
  261. pp_distance("POINT(90 0)", "POINT(90 1e-8)", strategy_pp),
  262. strategy_ps, true, true);
  263. // very large distance to segment
  264. tester::apply("p-s-13",
  265. "POINT(90 90)",
  266. "SEGMENT(0.5 0,175.5 0)",
  267. pp_distance("POINT(90 0)", "POINT(90 90)", strategy_pp),
  268. strategy_ps, true, true);
  269. tester::apply("p-s-14",
  270. "POINT(90 90)",
  271. "SEGMENT(0.5 -89,175.5 -89)",
  272. pp_distance("POINT(90 -89)", "POINT(90 90)", strategy_pp),
  273. strategy_ps, true, true);
  274. // degenerate segment
  275. tester::apply("p-s-15",
  276. "POINT(90 90)",
  277. "SEGMENT(0.5 -90,175.5 -90)",
  278. pp_distance("POINT(0.5 -90)", "POINT(90 90)", strategy_pp),
  279. strategy_ps, true, true);
  280. tester::apply("p-s-16",
  281. "POINT(90 90)",
  282. "SEGMENT(0.5 -90,175.5 -90)",
  283. pp_distance("POINT(90 -90)", "POINT(90 90)", strategy_pp),
  284. strategy_ps, true, true);
  285. // equatorial segment
  286. tester::apply("p-s-17",
  287. "POINT(90 90)",
  288. "SEGMENT(0 0,175.5 0)",
  289. pp_distance("POINT(90 90)", "POINT(0 0)", strategy_pp),
  290. strategy_ps, true, true);
  291. // segment pass by pole
  292. tester::apply("p-s-18",
  293. "POINT(90 90)",
  294. "SEGMENT(0 0,180 0)",
  295. 0,
  296. strategy_ps, true, true);
  297. tester::apply("p-s-20",
  298. "POINT(80 89)",
  299. "SEGMENT(0 0,180 0)",
  300. pp_distance("POINT(80 89)", "POINT(0 89.82633489283377)", strategy_pp),
  301. strategy_ps, true, true);
  302. tester::apply("p-s-21",
  303. "POINT(80 89)",
  304. "SEGMENT(0 -1,180 1)",
  305. pp_distance("POINT(80 89)", "POINT(0 89.82633489283377)", strategy_pp),
  306. strategy_ps, true, true);
  307. // meridian special case
  308. tester::apply("p-s-mer1",
  309. "POINT(2.5 3)",
  310. "SEGMENT(2 2,2 4)",
  311. pp_distance("POINT(2.5 3)", "POINT(2 3.000114792872075)", strategy_pp),
  312. strategy_ps, true, true);
  313. tester::apply("p-s-mer2",
  314. "POINT(1 80)",
  315. "SEGMENT(0 0,0 90)",
  316. pp_distance("POINT(1 80)", "POINT(0 80.00149225834545)", strategy_pp),
  317. strategy_ps, true, true);
  318. tester::apply("p-s-mer3",
  319. "POINT(2 0)",
  320. "SEGMENT(1 -1,1 0)",
  321. pp_distance("POINT(2 0)", "POINT(1 0)", strategy_pp),
  322. strategy_ps, true, true);
  323. tester::apply("p-s-acos",
  324. "POINT(0 90)",
  325. "SEGMENT(90 0,0 1.000005)",
  326. pp_distance("POINT(0 90)", "POINT(0.3017072304435489 1.000018955050697)",
  327. strategy_pp),
  328. strategy_ps, true, true);
  329. }
  330. template <typename Strategy_pp, typename Strategy_ps>
  331. void test_distance_point_segment_no_thomas(Strategy_pp const& strategy_pp,
  332. Strategy_ps const& strategy_ps)
  333. {
  334. #ifdef BOOST_GEOMETRY_TEST_DEBUG
  335. std::cout << std::endl;
  336. std::cout << "point/segment distance tests" << std::endl;
  337. #endif
  338. typedef test_distance_of_geometries<point_type, segment_type> tester;
  339. // thomas strategy is failing for those test cases
  340. // this is because of inaccurate results for points close to poles
  341. tester::apply("p-s-19",
  342. "POINT(90 89)",
  343. "SEGMENT(0 0,180 0)",
  344. pp_distance("POINT(90 89)", "POINT(90 90)", strategy_pp),
  345. strategy_ps, true, true);
  346. }
  347. template <typename Strategy_pp, typename Strategy_ps>
  348. void test_distance_point_segment_rad_mix(Strategy_pp const& strategy_pp,
  349. Strategy_ps const& strategy_ps)
  350. {
  351. #ifdef BOOST_GEOMETRY_TEST_DEBUG
  352. std::cout << std::endl;
  353. std::cout << "point/segment distance tests" << std::endl;
  354. #endif
  355. typedef test_distance_of_geometries<point_type, segment_type> tester1;
  356. typedef test_distance_of_geometries<point_type_rad, segment_type> tester2;
  357. typedef test_distance_of_geometries<point_type, segment_type_rad> tester3;
  358. typedef test_distance_of_geometries<point_type_rad, segment_type_rad> tester4;
  359. const double d2r = bg::math::d2r<double>();
  360. std::ostringstream s1;
  361. s1 << 1*d2r;
  362. std::ostringstream s2;
  363. s2 << 2*d2r;
  364. std::ostringstream s3;
  365. s3 << 3*d2r;
  366. tester1::apply("p-s-mix1",
  367. "POINT(3 1)",
  368. "SEGMENT(2 2,3 2)",
  369. pp_distance("POINT(3 2)", "POINT(3 1)", strategy_pp),
  370. strategy_ps, true, true);
  371. tester2::apply("p-s-mix2",
  372. "POINT(" + s3.str() + " " + s1.str() + ")",
  373. "SEGMENT(2 2,3 2)",
  374. pp_distance("POINT(3 2)", "POINT(3 1)", strategy_pp),
  375. strategy_ps, true, true);
  376. tester3::apply("p-s-mix3",
  377. "POINT(3 1)",
  378. "SEGMENT(" + s2.str() + " " + s2.str() + ","
  379. + s3.str() + " " + s2.str() + ")",
  380. pp_distance("POINT(3 2)", "POINT(3 1)", strategy_pp),
  381. strategy_ps, true, true);
  382. tester4::apply("p-s-mix4",
  383. "POINT(" + s3.str() + " " + s1.str() + ")",
  384. "SEGMENT(" + s2.str() + " " + s2.str() + ","
  385. + s3.str() + " " + s2.str() + ")",
  386. pp_distance("POINT(3 2)", "POINT(3 1)", strategy_pp),
  387. strategy_ps, true, true);
  388. }
  389. //===========================================================================
  390. template <typename Strategy_pp, typename Strategy_ps>
  391. void test_distance_point_linestring(Strategy_pp const& strategy_pp,
  392. Strategy_ps const& strategy_ps)
  393. {
  394. #ifdef BOOST_GEOMETRY_TEST_DEBUG
  395. std::cout << std::endl;
  396. std::cout << "point/linestring distance tests" << std::endl;
  397. #endif
  398. typedef test_distance_of_geometries<point_type, linestring_type> tester;
  399. tester::apply("p-l-01",
  400. "POINT(0 0)",
  401. "LINESTRING(2 0,2 0)",
  402. pp_distance("POINT(0 0)", "POINT(2 0)", strategy_pp),
  403. strategy_ps, true, false, false);
  404. tester::apply("p-l-02",
  405. "POINT(0 0)",
  406. "LINESTRING(2 0,3 0)",
  407. pp_distance("POINT(0 0)", "POINT(2 0)", strategy_pp),
  408. strategy_ps, true, false, false);
  409. tester::apply("p-l-03",
  410. "POINT(2.5 3)",
  411. "LINESTRING(2 0,3 0)",
  412. pp_distance("POINT(2.5 3)", "POINT(2.5 0)", strategy_pp),
  413. strategy_ps, true, false, false);
  414. tester::apply("p-l-04",
  415. "POINT(2 0)",
  416. "LINESTRING(2 0,3 0)",
  417. 0,
  418. strategy_ps, true, false, false);
  419. tester::apply("p-l-05",
  420. "POINT(3 0)",
  421. "LINESTRING(2 0,3 0)",
  422. 0,
  423. strategy_ps, true, false, false);
  424. tester::apply("p-l-06",
  425. "POINT(2.5 0)",
  426. "LINESTRING(2 0,3 0)",
  427. 0,
  428. strategy_ps, true, false, false);
  429. tester::apply("p-l-07",
  430. "POINT(7.5 10)",
  431. "LINESTRING(1 0,2 0,3 0,4 0,5 0,6 0,7 0,8 0,9 0)",
  432. ps_distance("POINT(7.5 10)", "SEGMENT(7 0,8 0)", strategy_ps),
  433. strategy_ps, true, false, false);
  434. tester::apply("p-l-08",
  435. "POINT(7.5 10)",
  436. "LINESTRING(1 1,2 1,3 1,4 1,5 1,6 1,7 1,20 2,21 2)",
  437. ps_distance("POINT(7.5 10)", "SEGMENT(7 1,20 2)", strategy_ps),
  438. strategy_ps, true, false, false);
  439. }
  440. void test_distance_point_linestring_strategies()
  441. {
  442. typedef test_distance_of_geometries<point_type, linestring_type> tester;
  443. tester::apply("p-l-s-01",
  444. "POINT(2.5 3)",
  445. "LINESTRING(2 1,3 1)",
  446. 221147.24332788656,
  447. vincenty_ps(),
  448. true, false, false);
  449. tester::apply("p-l-s-02",
  450. "POINT(2.5 3)",
  451. "LINESTRING(2 1,3 1)",
  452. 221147.36682199029,
  453. thomas_ps(),
  454. true, false, false);
  455. tester::apply("p-l-s-03",
  456. "POINT(2.5 3)",
  457. "LINESTRING(2 1,3 1)",
  458. 221144.76527049288,
  459. andoyer_ps(),
  460. true, false, false);
  461. }
  462. //===========================================================================
  463. template <typename Strategy_pp, typename Strategy_ps>
  464. void test_distance_point_multilinestring(Strategy_pp const& strategy_pp,
  465. Strategy_ps const& strategy_ps)
  466. {
  467. #ifdef BOOST_GEOMETRY_TEST_DEBUG
  468. std::cout << std::endl;
  469. std::cout << "point/multilinestring distance tests" << std::endl;
  470. #endif
  471. typedef test_distance_of_geometries
  472. <
  473. point_type, multi_linestring_type
  474. > tester;
  475. tester::apply("p-ml-01",
  476. "POINT(0 0)",
  477. "MULTILINESTRING((-5 0,-3 0),(2 0,3 0))",
  478. pp_distance("POINT(0 0)", "POINT(2 0)", strategy_pp),
  479. strategy_ps, true, false, false);
  480. tester::apply("p-ml-02",
  481. "POINT(2.5 3)",
  482. "MULTILINESTRING((-5 0,-3 0),(2 0,3 0))",
  483. pp_distance("POINT(2.5 3)", "POINT(2.5 0)", strategy_pp),
  484. strategy_ps, true, false, false);
  485. tester::apply("p-ml-03",
  486. "POINT(2 0)",
  487. "MULTILINESTRING((-5 0,-3 0),(2 0,3 0))",
  488. 0,
  489. strategy_ps, true, false, false);
  490. tester::apply("p-ml-04",
  491. "POINT(3 0)",
  492. "MULTILINESTRING((-5 0,-3 0),(2 0,3 0))",
  493. 0,
  494. strategy_ps, true, false, false);
  495. tester::apply("p-ml-05",
  496. "POINT(2.5 0)",
  497. "MULTILINESTRING((-5 0,-3 0),(2 0,3 0))",
  498. 0,
  499. strategy_ps, true, false, false);
  500. tester::apply("p-ml-06",
  501. "POINT(7.5 10)",
  502. "MULTILINESTRING((-5 0,-3 0),(2 0,3 0,4 0,5 0,6 0,20 1,21 1))",
  503. ps_distance("POINT(7.5 10)", "SEGMENT(6 0,20 1)", strategy_ps),
  504. strategy_ps, true, false, false);
  505. tester::apply("p-ml-07",
  506. "POINT(-8 10)",
  507. "MULTILINESTRING((-20 10,-19 11,-18 10,-6 0,-5 0,-3 0),(2 0,6 0,20 1,21 1))",
  508. ps_distance("POINT(-8 10)", "SEGMENT(-6 0,-18 10)", strategy_ps),
  509. strategy_ps, true, false, false);
  510. }
  511. //===========================================================================
  512. template <typename Strategy_pp, typename Strategy_ps>
  513. void test_distance_linestring_multipoint(Strategy_pp const& strategy_pp,
  514. Strategy_ps const& strategy_ps)
  515. {
  516. #ifdef BOOST_GEOMETRY_TEST_DEBUG
  517. std::cout << std::endl;
  518. std::cout << "linestring/multipoint distance tests" << std::endl;
  519. #endif
  520. typedef test_distance_of_geometries
  521. <
  522. linestring_type, multi_point_type
  523. > tester;
  524. tester::apply("l-mp-01",
  525. "LINESTRING(2 0,0 2,100 80)",
  526. "MULTIPOINT(0 0,1 0,0 1,1 1)",
  527. ps_distance("POINT(1 1)", "SEGMENT(2 0,0 2)", strategy_ps),
  528. strategy_ps, true, false, false);
  529. tester::apply("l-mp-02",
  530. "LINESTRING(4 0,0 4,100 80)",
  531. "MULTIPOINT(0 0,1 0,0 1,1 1)",
  532. ps_distance("POINT(1 1)", "SEGMENT(0 4,4 0)", strategy_ps),
  533. strategy_ps, true, false, false);
  534. tester::apply("l-mp-03",
  535. "LINESTRING(1 1,2 2,100 80)",
  536. "MULTIPOINT(0 0,1 0,0 1,1 1)",
  537. 0,
  538. strategy_ps, true, false, false);
  539. tester::apply("l-mp-04",
  540. "LINESTRING(3 3,4 4,100 80)",
  541. "MULTIPOINT(0 0,1 0,0 1,1 1)",
  542. pp_distance("POINT(1 1)", "POINT(3 3)", strategy_pp),
  543. strategy_ps, true, false, false);
  544. tester::apply("l-mp-05",
  545. "LINESTRING(0 0,10 0,10 10,0 10,0 0)",
  546. "MULTIPOINT(1 -1,80 80,5 0,150 90)",
  547. 0,
  548. strategy_ps, true, false, false);
  549. tester::apply("l-mp-06",
  550. "LINESTRING(90 0,0 1.00005)",
  551. "MULTIPOINT((0 0),(0 0),(0 0),(0 0),(0 0),(0 0),(0 0 ),(0 0),\
  552. (0 0),(0 0 ),(0 0),(0 0),(69.35235 155.0205),\
  553. (75.72081 37.97683),(0 0),(0 0),(0 0))",
  554. pp_distance("POINT(0 0)", "POINT(0 1.00005)", strategy_pp),
  555. strategy_ps, true, false, false);
  556. }
  557. //===========================================================================
  558. template <typename Strategy_pp, typename Strategy_ps>
  559. void test_distance_multipoint_multilinestring(Strategy_pp const& strategy_pp,
  560. Strategy_ps const& strategy_ps)
  561. {
  562. #ifdef BOOST_GEOMETRY_TEST_DEBUG
  563. std::cout << std::endl;
  564. std::cout << "multipoint/multilinestring distance tests" << std::endl;
  565. #endif
  566. typedef test_distance_of_geometries
  567. <
  568. multi_point_type, multi_linestring_type
  569. > tester;
  570. tester::apply("mp-ml-01",
  571. "MULTIPOINT(0 0,1 0,0 1,1 1)",
  572. "MULTILINESTRING((2 0,0 2),(2 2,3 3))",
  573. ps_distance("POINT(1 1)", "SEGMENT(2 0,0 2)", strategy_ps),
  574. strategy_ps, true, false, false);
  575. tester::apply("mp-ml-02",
  576. "MULTIPOINT(0 0,1 0,0 1,1 1)",
  577. "MULTILINESTRING((3 0,0 3),(4 4,5 5))",
  578. ps_distance("POINT(1 1)", "SEGMENT(3 0,0 3)", strategy_ps),
  579. strategy_ps, true, false, false);
  580. tester::apply("mp-ml-03",
  581. "MULTIPOINT(0 0,1 0,0 1,1 1)",
  582. "MULTILINESTRING((4 4,5 5),(1 1,2 2))",
  583. 0,
  584. strategy_ps, true, false, false);
  585. tester::apply("mp-ml-04",
  586. "MULTIPOINT(0 0,1 0,0 1,1 1)",
  587. "MULTILINESTRING((4 4,3 3),(4 4,5 5))",
  588. pp_distance("POINT(1 1)", "POINT(3 3)", strategy_pp),
  589. strategy_ps, true, false, false);
  590. }
  591. //===========================================================================
  592. template <typename Strategy_pp, typename Strategy_ps>
  593. void test_distance_multipoint_segment(Strategy_pp const& strategy_pp,
  594. Strategy_ps const& strategy_ps)
  595. {
  596. #ifdef BOOST_GEOMETRY_TEST_DEBUG
  597. std::cout << std::endl;
  598. std::cout << "multipoint/segment distance tests" << std::endl;
  599. #endif
  600. typedef test_distance_of_geometries<multi_point_type, segment_type> tester;
  601. tester::apply("mp-s-01",
  602. "MULTIPOINT(0 0,1 0,0 1,1 1)",
  603. "SEGMENT(2 0,0 2)",
  604. ps_distance("POINT(1 1)", "SEGMENT(2 0,0 2)", strategy_ps),
  605. strategy_ps, true, false, false);
  606. tester::apply("mp-s-02",
  607. "MULTIPOINT(0 0,1 0,0 1,1 1)",
  608. "SEGMENT(0 -3,1 -10)",
  609. pp_distance("POINT(0 0)", "POINT(0 -3)", strategy_pp),
  610. strategy_ps, true, false, false);
  611. tester::apply("mp-s-03",
  612. "MULTIPOINT(0 0,1 0,0 1,1 1)",
  613. "SEGMENT(1 1,2 2)",
  614. 0,
  615. strategy_ps, true, false, false);
  616. tester::apply("mp-s-04",
  617. "MULTIPOINT(0 0,1 0,0 1,1 1)",
  618. "SEGMENT(3 3,4 4)",
  619. pp_distance("POINT(1 1)", "POINT(3 3)", strategy_pp),
  620. strategy_ps, true, false, false);
  621. tester::apply("mp-s-05",
  622. "MULTIPOINT(0 0,1 0,0 1,1 1)",
  623. "SEGMENT(0.5 -3,1 -10)",
  624. pp_distance("POINT(1 0)", "POINT(0.5 -3)", strategy_pp),
  625. strategy_ps, true, false, false);
  626. }
  627. //===========================================================================
  628. //===========================================================================
  629. //===========================================================================
  630. template <typename Strategy_pp, typename Strategy_ps>
  631. void test_all_pl_l(Strategy_pp pp_strategy, Strategy_ps ps_strategy,
  632. bool WGS84 = true)
  633. {
  634. test_distance_point_segment(pp_strategy, ps_strategy, WGS84);
  635. test_distance_point_linestring(pp_strategy, ps_strategy);
  636. test_distance_point_multilinestring(pp_strategy, ps_strategy);
  637. test_distance_linestring_multipoint(pp_strategy, ps_strategy);
  638. test_distance_multipoint_multilinestring(pp_strategy, ps_strategy);
  639. test_distance_multipoint_segment(pp_strategy, ps_strategy);
  640. test_more_empty_input_pointlike_linear<point_type>(ps_strategy);
  641. }
  642. BOOST_AUTO_TEST_CASE( test_all_pointlike_linear )
  643. {
  644. test_all_pl_l(vincenty_pp(), vincenty_ps_bisection());
  645. test_all_pl_l(vincenty_pp(), vincenty_ps());
  646. test_all_pl_l(thomas_pp(), thomas_ps());
  647. test_all_pl_l(andoyer_pp(), andoyer_ps());
  648. // test with different spheroid
  649. stype spheroid(6372000, 6370000);
  650. test_all_pl_l(andoyer_pp(spheroid), andoyer_ps(spheroid), false);
  651. test_distance_point_segment_no_thomas(vincenty_pp(), vincenty_ps());
  652. //test_distance_point_segment_no_thomas(thomas_pp(), thomas_ps());
  653. test_distance_point_segment_no_thomas(andoyer_pp(), andoyer_ps());
  654. test_distance_point_segment_rad_mix(vincenty_pp(), vincenty_ps());
  655. test_distance_point_segment_rad_mix(thomas_pp(), thomas_ps());
  656. test_distance_point_segment_rad_mix(andoyer_pp(), andoyer_ps());
  657. }