distance_ca_pl_ar.cpp 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671
  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. // Unit Test
  3. // Copyright (c) 2014-2018, Oracle and/or its affiliates.
  4. // Contributed and/or modified by Vissarion Fysikopoulos, on behalf of Oracle
  5. // Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
  6. // Licensed under the Boost Software License version 1.0.
  7. // http://www.boost.org/users/license.html
  8. #include <iostream>
  9. #ifndef BOOST_TEST_MODULE
  10. #define BOOST_TEST_MODULE test_distance_cartesian_pointlike_areal
  11. #endif
  12. #include <boost/test/included/unit_test.hpp>
  13. #include "test_distance_common.hpp"
  14. typedef bg::model::point<double,2,bg::cs::cartesian> point_type;
  15. typedef bg::model::multi_point<point_type> multi_point_type;
  16. typedef bg::model::point<double,3,bg::cs::cartesian> point_type_3d;
  17. typedef bg::model::multi_point<point_type_3d> multi_point_type_3d;
  18. typedef bg::model::polygon<point_type, false> polygon_type;
  19. typedef bg::model::multi_polygon<polygon_type> multi_polygon_type;
  20. typedef bg::model::ring<point_type, false> ring_type;
  21. typedef bg::model::box<point_type> box_type;
  22. typedef bg::model::box<point_type_3d> box_type_3d;
  23. namespace services = bg::strategy::distance::services;
  24. typedef bg::default_distance_result<point_type>::type return_type;
  25. typedef bg::strategy::distance::pythagoras<> point_point_strategy;
  26. typedef bg::strategy::distance::projected_point<> point_segment_strategy;
  27. typedef bg::strategy::distance::pythagoras_point_box<> point_box_strategy;
  28. //===========================================================================
  29. template <typename Strategy>
  30. void test_distance_point_polygon(Strategy const& strategy)
  31. {
  32. #ifdef BOOST_GEOMETRY_TEST_DEBUG
  33. std::cout << std::endl;
  34. std::cout << "point/polygon distance tests" << std::endl;
  35. #endif
  36. typedef test_distance_of_geometries<point_type, polygon_type> tester;
  37. tester::apply("point(0 -20)",
  38. "polygon((-10 -10,10 -10,10 10,-10 10,-10 -10))",
  39. 10, 100, strategy);
  40. tester::apply("point(12 0)",
  41. "polygon((-10 -10,10 -10,10 10,-10 10,-10 -10))",
  42. 2, 4, strategy);
  43. tester::apply("point(0 0)",
  44. "polygon((-10 -10,10 -10,10 10,-10 10,-10 -10))",
  45. 0, 0, strategy);
  46. tester::apply("point(0 0)",
  47. "polygon((-10 -10,10 -10,10 10,-10 10,-10 -10),\
  48. (-5 -5,-5 5,5 5,5 -5,-5 -5))",
  49. 5, 25, strategy);
  50. // polygons with single-point rings
  51. tester::apply("point(0 0)",
  52. "polygon((-5 5))",
  53. sqrt(50.0), 50, strategy);
  54. tester::apply("point(0 0)",
  55. "polygon((-10 -10,10 -10,10 10,-10 10,-10 -10),(-5 5))",
  56. 0, 0, strategy);
  57. }
  58. //===========================================================================
  59. template <typename Strategy>
  60. void test_distance_point_ring(Strategy const& strategy)
  61. {
  62. #ifdef BOOST_GEOMETRY_TEST_DEBUG
  63. std::cout << std::endl;
  64. std::cout << "point/ring distance tests" << std::endl;
  65. #endif
  66. typedef test_distance_of_geometries<point_type, ring_type> tester;
  67. tester::apply("point(0 -20)",
  68. "polygon((-10 -10,10 -10,10 10,-10 10,-10 -10))",
  69. 10, 100, strategy);
  70. tester::apply("point(12 0)",
  71. "polygon((-10 -10,10 -10,10 10,-10 10,-10 -10))",
  72. 2, 4, strategy);
  73. tester::apply("point(0 0)",
  74. "polygon((-10 -10,10 -10,10 10,-10 10,-10 -10))",
  75. 0, 0, strategy);
  76. // single-point rings
  77. tester::apply("point(0 0)",
  78. "polygon((-10 -10))",
  79. sqrt(200.0), 200, strategy);
  80. }
  81. //===========================================================================
  82. template <typename Strategy>
  83. void test_distance_point_multipolygon(Strategy const& strategy)
  84. {
  85. #ifdef BOOST_GEOMETRY_TEST_DEBUG
  86. std::cout << std::endl;
  87. std::cout << "point/multipolygon distance tests" << std::endl;
  88. #endif
  89. typedef test_distance_of_geometries<point_type, multi_polygon_type> tester;
  90. tester::apply("point(0 -20)",
  91. "multipolygon(((-10 -10,10 -10,10 10,-10 10,-10 -10)),\
  92. ((0 22,-1 30,2 40,0 22)))",
  93. 10, 100, strategy);
  94. tester::apply("point(12 0)",
  95. "multipolygon(((-10 -10,10 -10,10 10,-10 10,-10 -10)),\
  96. ((20 -1,21 2,30 -10,20 -1)))",
  97. 2, 4, strategy);
  98. tester::apply("point(0 0)",
  99. "multipolygon(((-10 -10,10 -10,10 10,-10 10,-10 -10)),\
  100. ((20 -1,21 2,30 -10,20 -1)))",
  101. 0, 0, strategy);
  102. tester::apply("point(0 0)",
  103. "multipolygon(((-10 -10,10 -10,10 10,-10 10,-10 -10),\
  104. (-5 -5,-5 5,5 5,5 -5,-5 -5)),\
  105. ((100 0,101 0,101 1,100 1,100 0)))",
  106. 5, 25, strategy);
  107. }
  108. //===========================================================================
  109. template <typename Strategy>
  110. void test_distance_multipoint_polygon(Strategy const& strategy)
  111. {
  112. #ifdef BOOST_GEOMETRY_TEST_DEBUG
  113. std::cout << std::endl;
  114. std::cout << "multipoint/polygon distance tests" << std::endl;
  115. #endif
  116. typedef test_distance_of_geometries<multi_point_type, polygon_type> tester;
  117. tester::apply("multipoint(0 -20,0 -15)",
  118. "polygon((-10 -10,10 -10,10 10,-10 10,-10 -10))",
  119. 5, 25, strategy);
  120. tester::apply("multipoint(16 0,12 0)",
  121. "polygon((-10 -10,10 -10,10 10,-10 10,-10 -10))",
  122. 2, 4, strategy);
  123. tester::apply("multipoint(0 0,5 5,4 4)",
  124. "polygon((-10 -10,10 -10,10 10,-10 10,-10 -10))",
  125. 0, 0, strategy);
  126. tester::apply("multipoint(0 0,2 0)",
  127. "polygon((-10 -10,10 -10,10 10,-10 10,-10 -10),\
  128. (-5 -5,-5 5,5 5,5 -5,-5 -5))",
  129. 3, 9, strategy);
  130. tester::apply("multipoint(4 4,11 11)",
  131. "polygon((0 0,0 10,10 10,10 0,0 0))",
  132. 0, 0, strategy);
  133. }
  134. //===========================================================================
  135. template <typename Strategy>
  136. void test_distance_multipoint_ring(Strategy const& strategy)
  137. {
  138. #ifdef BOOST_GEOMETRY_TEST_DEBUG
  139. std::cout << std::endl;
  140. std::cout << "multipoint/ring distance tests" << std::endl;
  141. #endif
  142. typedef test_distance_of_geometries<multi_point_type, ring_type> tester;
  143. tester::apply("multipoint(0 -20,0 -15)",
  144. "polygon((-10 -10,10 -10,10 10,-10 10,-10 -10))",
  145. 5, 25, strategy);
  146. tester::apply("multipoint(16 0,12 0)",
  147. "polygon((-10 -10,10 -10,10 10,-10 10,-10 -10))",
  148. 2, 4, strategy);
  149. tester::apply("multipoint(0 0,5 5,4 4)",
  150. "polygon((-10 -10,10 -10,10 10,-10 10,-10 -10))",
  151. 0, 0, strategy);
  152. // single-point ring
  153. tester::apply("multipoint(0 0,5 5,4 4)",
  154. "polygon((10 10))",
  155. sqrt(50.0), 50, strategy);
  156. }
  157. //===========================================================================
  158. template <typename Strategy>
  159. void test_distance_multipoint_multipolygon(Strategy const& strategy)
  160. {
  161. #ifdef BOOST_GEOMETRY_TEST_DEBUG
  162. std::cout << std::endl;
  163. std::cout << "multipoint/multipolygon distance tests" << std::endl;
  164. #endif
  165. typedef test_distance_of_geometries
  166. <
  167. multi_point_type, multi_polygon_type
  168. > tester;
  169. tester::apply("multipoint(0 -20,0 -15)",
  170. "multipolygon(((-10 -10,10 -10,10 10,-10 10,-10 -10)),\
  171. ((0 22,-1 30,2 40,0 22)))",
  172. 5, 25, strategy);
  173. tester::apply("multipoint(16 0,12 0)",
  174. "multipolygon(((-10 -10,10 -10,10 10,-10 10,-10 -10)),\
  175. ((20 -1,21 2,30 -10,20 -1)))",
  176. 2, 4, strategy);
  177. tester::apply("multipoint(0 0,4 4,5 5)",
  178. "multipolygon(((-10 -10,10 -10,10 10,-10 10,-10 -10)),\
  179. ((20 -1,21 2,30 -10,20 -1)))",
  180. 0, 0, strategy);
  181. tester::apply("multipoint(0 0,2 0)",
  182. "multipolygon(((-10 -10,10 -10,10 10,-10 10,-10 -10),\
  183. (-5 -5,-5 5,5 5,5 -5,-5 -5)),\
  184. ((100 0,101 0,101 1,100 1,100 0)))",
  185. 3, 9, strategy);
  186. tester::apply("MULTIPOINT(19 19,100 100)",
  187. "MULTIPOLYGON(((0 0,0 10,10 10,10 0,0 0),\
  188. (4 4,4 6,6 6,6 4,4 4)), ((10 10,10 20,20 20,20 10,10 10),\
  189. (14 14,14 16,16 16,16 14,14 14)))",
  190. 0, 0, strategy);
  191. }
  192. //===========================================================================
  193. template <typename Strategy>
  194. void test_distance_point_box_2d(Strategy const& strategy)
  195. {
  196. #ifdef BOOST_GEOMETRY_TEST_DEBUG
  197. std::cout << std::endl;
  198. std::cout << "2D point/box distance tests" << std::endl;
  199. #endif
  200. typedef test_distance_of_geometries<box_type, point_type> tester;
  201. // point inside box
  202. tester::apply("box(-1 -1,1 1)",
  203. "point(0 0)", 0, 0, strategy);
  204. // points on box corners
  205. tester::apply("box(-1 -1,1 1)",
  206. "point(-1 -1)", 0, 0, strategy);
  207. tester::apply("box(-1 -1,1 1)",
  208. "point(-1 1)", 0, 0, strategy);
  209. tester::apply("box(-1 -1,1 1)",
  210. "point(1 -1)", 0, 0, strategy);
  211. tester::apply("box(-1 -1,1 1)",
  212. "point(1 1)", 0, 0, strategy);
  213. // points on box boundary edges
  214. tester::apply("box(-1 -1,1 1)",
  215. "point(0 -1)", 0, 0, strategy);
  216. tester::apply("box(-1 -1,1 1)",
  217. "point(-1 0)", 0, 0, strategy);
  218. tester::apply("box(-1 -1,1 1)",
  219. "point(1 0)", 0, 0, strategy);
  220. tester::apply("box(-1 -1,1 1)",
  221. "point(0 1)", 0, 0, strategy);
  222. // points outside box
  223. tester::apply("box(-1 -1,1 1)",
  224. "point(0 4)", 3, 9, strategy);
  225. tester::apply("box(-1 -1,1 1)",
  226. "point(0.5 4)", 3, 9, strategy);
  227. tester::apply("box(-1 -1,1 1)",
  228. "point(-0.5 5)", 4, 16, strategy);
  229. tester::apply("box(-1 -1,1 1)",
  230. "point(3 0.25)", 2, 4, strategy);
  231. tester::apply("box(-1 -1,1 1)",
  232. "point(-3 -0.25)", 2, 4, strategy);
  233. tester::apply("box(-1 -1,1 1)",
  234. "point(3 5)", sqrt(20.0), 20, strategy);
  235. tester::apply("box(-1 -1,1 1)",
  236. "point(-5 -4)", 5, 25, strategy);
  237. tester::apply("box(-1 -1,1 1)",
  238. "point(2 -2)", sqrt(2.0), 2, strategy);
  239. tester::apply("box(-1 -1,1 1)",
  240. "point(-3 4)", sqrt(13.0), 13, strategy);
  241. }
  242. //===========================================================================
  243. template <typename Strategy>
  244. void test_distance_point_box_different_point_types(Strategy const& strategy)
  245. {
  246. #ifdef BOOST_GEOMETRY_TEST_DEBUG
  247. std::cout << std::endl;
  248. std::cout << "2D point/box distance tests with different points"
  249. << std::endl;
  250. #endif
  251. typedef point_type double_point;
  252. typedef box_type double_box;
  253. typedef bg::model::point<int,2,bg::cs::cartesian> int_point;
  254. typedef bg::model::box<int_point> int_box;
  255. test_distance_of_geometries
  256. <
  257. int_point, int_box
  258. >::apply("point(0 0)",
  259. "box(1 1, 2 2)",
  260. sqrt(2.0), 2, strategy);
  261. test_distance_of_geometries
  262. <
  263. double_point, int_box
  264. >::apply("point(0.5 0)",
  265. "box(1 -1,2 1)",
  266. 0.5, 0.25, strategy);
  267. test_distance_of_geometries
  268. <
  269. double_point, double_box
  270. >::apply("point(1.5 0)",
  271. "box(1 -1,2 1)",
  272. 0, 0, strategy);
  273. test_distance_of_geometries
  274. <
  275. double_point, int_box
  276. >::apply("point(1.5 0)",
  277. "box(1 -1,2 1)",
  278. 0, 0, strategy);
  279. test_distance_of_geometries
  280. <
  281. int_point, double_box
  282. >::apply("point(1 0)",
  283. "box(0.5 -1,1.5 1)",
  284. 0, 0, strategy);
  285. test_distance_of_geometries
  286. <
  287. int_point, double_box
  288. >::apply("point(0 0)",
  289. "box(0.5, -1,1.5, 1)",
  290. 0.5, 0.25, strategy);
  291. }
  292. //===========================================================================
  293. template <typename Strategy>
  294. void test_distance_point_box_3d(Strategy const& strategy)
  295. {
  296. #ifdef BOOST_GEOMETRY_TEST_DEBUG
  297. std::cout << std::endl;
  298. std::cout << "3D point/box distance tests" << std::endl;
  299. #endif
  300. typedef test_distance_of_geometries<box_type_3d, point_type_3d> tester;
  301. // point inside box
  302. tester::apply("box(-1 -1 -1,1 1 1)",
  303. "point(0 0 0)", 0, 0, strategy);
  304. // points on box corners
  305. tester::apply("box(-1 -1 -1,1 1 1)",
  306. "point(-1 -1 -1)", 0, 0, strategy);
  307. tester::apply("box(-1 -1 -1,1 1 1)",
  308. "point(-1 -1 1)", 0, 0, strategy);
  309. tester::apply("box(-1 -1 -1,1 1 1)",
  310. "point(-1 1 -1)", 0, 0, strategy);
  311. tester::apply("box(-1 -1 -1,1 1 1)",
  312. "point(-1 1 1)", 0, 0, strategy);
  313. tester::apply("box(-1 -1 -1,1 1 1)",
  314. "point(1 -1 -1)", 0, 0, strategy);
  315. tester::apply("box(-1 -1 -1,1 1 1)",
  316. "point(1 -1 1)", 0, 0, strategy);
  317. tester::apply("box(-1 -1 -1,1 1 1)",
  318. "point(1 1 -1)", 0, 0, strategy);
  319. tester::apply("box(-1 -1 -1,1 1 1)",
  320. "point(1 1 1)", 0, 0, strategy);
  321. // points on box boundary edges
  322. tester::apply("box(-1 -1 -1,1 1 1)",
  323. "point(0 -1 -1)", 0, 0, strategy);
  324. tester::apply("box(-1 -1 -1,1 1 1)",
  325. "point(0 -1 1)", 0, 0, strategy);
  326. tester::apply("box(-1 -1 -1,1 1 1)",
  327. "point(0 1 -1)", 0, 0, strategy);
  328. tester::apply("box(-1 -1 -1,1 1 1)",
  329. "point(0 1 1)", 0, 0, strategy);
  330. tester::apply("box(-1 -1 -1,1 1 1)",
  331. "point(-1 0 -1)", 0, 0, strategy);
  332. tester::apply("box(-1 -1 -1,1 1 1)",
  333. "point(-1 0 1)", 0, 0, strategy);
  334. tester::apply("box(-1 -1 -1,1 1 1)",
  335. "point(1 0 -1)", 0, 0, strategy);
  336. tester::apply("box(-1 -1 -1,1 1 1)",
  337. "point(1 0 1)", 0, 0, strategy);
  338. tester::apply("box(-1 -1 -1,1 1 1)",
  339. "point(-1 -1 0)", 0, 0, strategy);
  340. tester::apply("box(-1 -1 -1,1 1 1)",
  341. "point(-1 1 0)", 0, 0, strategy);
  342. tester::apply("box(-1 -1 -1,1 1 1)",
  343. "point(1 -1 0)", 0, 0, strategy);
  344. tester::apply("box(-1 -1 -1,1 1 1)",
  345. "point(1 1 0)", 0, 0, strategy);
  346. // point on box faces
  347. tester::apply("box(-1 -1 -1,1 1 1)",
  348. "point(0 0 -1)", 0, 0, strategy);
  349. tester::apply("box(-1 -1 -1,1 1 1)",
  350. "point(0 0 1)", 0, 0, strategy);
  351. tester::apply("box(-1 -1 -1,1 1 1)",
  352. "point(0 -1 0)", 0, 0, strategy);
  353. tester::apply("box(-1 -1 -1,1 1 1)",
  354. "point(0 1 0)", 0, 0, strategy);
  355. tester::apply("box(-1 -1 -1,1 1 1)",
  356. "point(-1 0 0)", 0, 0, strategy);
  357. tester::apply("box(-1 -1 -1,1 1 1)",
  358. "point(1 0 0)", 0, 0, strategy);
  359. // points outside box -- closer to box corners
  360. tester::apply("box(-1 -1 -1,1 1 1)",
  361. "point(-2 -3 -4)", sqrt(14.0), 14, strategy);
  362. tester::apply("box(-1 -1 -1,1 1 1)",
  363. "point(-2 -3 3)", 3, 9, strategy);
  364. tester::apply("box(-1 -1 -1,1 1 1)",
  365. "point(-2 5 -2)", sqrt(18.0), 18, strategy);
  366. tester::apply("box(-1 -1 -1,1 1 1)",
  367. "point(-2 5 3)", sqrt(21.0), 21, strategy);
  368. tester::apply("box(-1 -1 -1,1 1 1)",
  369. "point(4 -6 -3)", sqrt(38.0), 38, strategy);
  370. tester::apply("box(-1 -1 -1,1 1 1)",
  371. "point(4 -6 4)", sqrt(43.0), 43, strategy);
  372. tester::apply("box(-1 -1 -1,1 1 1)",
  373. "point(4 7 -2)", sqrt(46.0), 46, strategy);
  374. tester::apply("box(-1 -1 -1,1 1 1)",
  375. "point(4 7 8)", sqrt(94.0), 94, strategy);
  376. // points closer to box facets
  377. tester::apply("box(-1 -1 -1,1 1 1)",
  378. "point(0 0 10)", 9, 81, strategy);
  379. tester::apply("box(-1 -1 -1,1 1 1)",
  380. "point(0 0 -5)", 4, 16, strategy);
  381. tester::apply("box(-1 -1 -1,1 1 1)",
  382. "point(0 7 0)", 6, 36, strategy);
  383. tester::apply("box(-1 -1 -1,1 1 1)",
  384. "point(0 -6 0)", 5, 25, strategy);
  385. tester::apply("box(-1 -1 -1,1 1 1)",
  386. "point(4 0 0)", 3, 9, strategy);
  387. tester::apply("box(-1 -1 -1,1 1 1)",
  388. "point(-3 0 0)", 2, 4, strategy);
  389. // points closer to box edges
  390. tester::apply("box(-1 -1 -1,1 1 1)",
  391. "point(0 -4 -5)", 5, 25, strategy);
  392. tester::apply("box(-1 -1 -1,1 1 1)",
  393. "point(0 -3 6)", sqrt(29.0), 29, strategy);
  394. tester::apply("box(-1 -1 -1,1 1 1)",
  395. "point(0 2 -7)", sqrt(37.0), 37, strategy);
  396. tester::apply("box(-1 -1 -1,1 1 1)",
  397. "point(0 8 7)", sqrt(85.0), 85, strategy);
  398. tester::apply("box(-1 -1 -1,1 1 1)",
  399. "point(-4 0 -4)", sqrt(18.0), 18, strategy);
  400. tester::apply("box(-1 -1 -1,1 1 1)",
  401. "point(-3 0 5)", sqrt(20.0), 20, strategy);
  402. tester::apply("box(-1 -1 -1,1 1 1)",
  403. "point(2 0 -6)", sqrt(26.0), 26, strategy);
  404. tester::apply("box(-1 -1 -1,1 1 1)",
  405. "point(8 0 6)", sqrt(74.0), 74, strategy);
  406. tester::apply("box(-1 -1 -1,1 1 1)",
  407. "point(-5 -5 0)", sqrt(32.0), 32, strategy);
  408. tester::apply("box(-1 -1 -1,1 1 1)",
  409. "point(-4 6 0)", sqrt(34.0), 34, strategy);
  410. tester::apply("box(-1 -1 -1,1 1 1)",
  411. "point(3 -7 0)", sqrt(40.0), 40, strategy);
  412. tester::apply("box(-1 -1 -1,1 1 1)",
  413. "point(9 7 0)", 10, 100, strategy);
  414. }
  415. //===========================================================================
  416. template <typename Strategy>
  417. void test_distance_multipoint_box_2d(Strategy const& strategy)
  418. {
  419. #ifdef BOOST_GEOMETRY_TEST_DEBUG
  420. std::cout << std::endl;
  421. std::cout << "2D multipoint/box distance tests" << std::endl;
  422. #endif
  423. typedef test_distance_of_geometries<box_type, multi_point_type> tester;
  424. // at least one point inside the box
  425. tester::apply("box(0 0,10 10)",
  426. "multipoint(0 0,-1 -1,20 20)",
  427. 0, 0, strategy);
  428. tester::apply("box(0 0,10 10)",
  429. "multipoint(1 1,-1 -1,20 20)",
  430. 0, 0, strategy);
  431. tester::apply("box(0 0,10 10)",
  432. "multipoint(1 1,2 2,3 3)",
  433. 0, 0, strategy);
  434. // all points outside the box
  435. tester::apply("box(0 0,10 10)",
  436. "multipoint(-1 -1,20 20)",
  437. sqrt(2.0), 2, strategy);
  438. tester::apply("box(0 0,10 10)",
  439. "multipoint(5 13, 50 50)",
  440. 3, 9, strategy);
  441. }
  442. //===========================================================================
  443. template <typename Strategy>
  444. void test_distance_multipoint_box_3d(Strategy const& strategy)
  445. {
  446. #ifdef BOOST_GEOMETRY_TEST_DEBUG
  447. std::cout << std::endl;
  448. std::cout << "3D multipoint/box distance tests" << std::endl;
  449. #endif
  450. typedef test_distance_of_geometries
  451. <
  452. box_type_3d, multi_point_type_3d
  453. > tester;
  454. // at least one point inside the box
  455. tester::apply("box(0 0 0,10 10 10)",
  456. "multipoint(0 0 0,-1 -1 -1,20 20 20)",
  457. 0, 0, strategy);
  458. tester::apply("box(0 0 0,10 10 10)",
  459. "multipoint(1 1 1,-1 -1 -1,20 20 20)",
  460. 0, 0, strategy);
  461. tester::apply("box(0 0 0,10 10 10)",
  462. "multipoint(1 1 1,2 2 2,3 3 3)",
  463. 0, 0, strategy);
  464. // all points outside the box
  465. tester::apply("box(0 0 0,10 10 10)",
  466. "multipoint(-1 -1 -1,20 20 20)",
  467. sqrt(3.0), 3, strategy);
  468. tester::apply("box(0 0 0,10 10 10)",
  469. "multipoint(5 5 13,50 50 50)",
  470. 3, 9, strategy);
  471. }
  472. //===========================================================================
  473. template <typename Point, typename Strategy>
  474. void test_more_empty_input_pointlike_areal(Strategy const& strategy)
  475. {
  476. #ifdef BOOST_GEOMETRY_TEST_DEBUG
  477. std::cout << std::endl;
  478. std::cout << "testing on empty inputs... " << std::flush;
  479. #endif
  480. bg::model::multi_point<Point> multipoint_empty;
  481. bg::model::polygon<Point> polygon_empty;
  482. bg::model::multi_polygon<bg::model::polygon<Point> > multipolygon_empty;
  483. bg::model::ring<Point> ring_empty;
  484. Point point = from_wkt<Point>("point(0 0)");
  485. bg::model::polygon<Point> polygon =
  486. from_wkt<bg::model::polygon<Point> >("polygon((0 0,1 0,0 1))");
  487. bg::model::ring<Point> ring =
  488. from_wkt<bg::model::ring<Point> >("polygon((0 0,1 0,0 1))");
  489. // 1st geometry is empty
  490. test_empty_input(multipoint_empty, polygon, strategy);
  491. test_empty_input(multipoint_empty, ring, strategy);
  492. // 2nd geometry is empty
  493. test_empty_input(point, polygon_empty, strategy);
  494. test_empty_input(point, multipolygon_empty, strategy);
  495. test_empty_input(point, ring_empty, strategy);
  496. // both geometries are empty
  497. test_empty_input(multipoint_empty, polygon_empty, strategy);
  498. test_empty_input(multipoint_empty, multipolygon_empty, strategy);
  499. test_empty_input(multipoint_empty, ring_empty, strategy);
  500. #ifdef BOOST_GEOMETRY_TEST_DEBUG
  501. std::cout << "done!" << std::endl;
  502. #endif
  503. }
  504. //===========================================================================
  505. BOOST_AUTO_TEST_CASE( test_all_pointlike_polygon )
  506. {
  507. test_distance_point_polygon(point_point_strategy()); // back-compatibility
  508. test_distance_point_polygon(point_segment_strategy());
  509. }
  510. BOOST_AUTO_TEST_CASE( test_all_point_multipolygon )
  511. {
  512. test_distance_point_multipolygon(point_point_strategy()); // back-compatibility
  513. test_distance_point_multipolygon(point_segment_strategy());
  514. }
  515. BOOST_AUTO_TEST_CASE( test_all_point_ring )
  516. {
  517. test_distance_point_ring(point_point_strategy()); // back-compatibility
  518. test_distance_point_ring(point_segment_strategy());
  519. }
  520. BOOST_AUTO_TEST_CASE( test_all_multipoint_polygon )
  521. {
  522. test_distance_multipoint_polygon(point_point_strategy()); // back-compatibility
  523. test_distance_multipoint_polygon(point_segment_strategy());
  524. }
  525. BOOST_AUTO_TEST_CASE( test_all_multipoint_multipolygon )
  526. {
  527. test_distance_multipoint_multipolygon(point_point_strategy()); // back-compatibility
  528. test_distance_multipoint_multipolygon(point_segment_strategy());
  529. }
  530. BOOST_AUTO_TEST_CASE( test_all_multipoint_ring )
  531. {
  532. test_distance_multipoint_ring(point_segment_strategy());
  533. }
  534. BOOST_AUTO_TEST_CASE( test_all_point_box_2d )
  535. {
  536. point_box_strategy pb_strategy;
  537. test_distance_point_box_2d(pb_strategy);
  538. test_distance_point_box_different_point_types(pb_strategy);
  539. }
  540. BOOST_AUTO_TEST_CASE( test_all_point_box_3d )
  541. {
  542. test_distance_point_box_3d(point_box_strategy());
  543. }
  544. BOOST_AUTO_TEST_CASE( test_all_multipoint_box_2d )
  545. {
  546. test_distance_multipoint_box_2d(point_box_strategy());
  547. }
  548. BOOST_AUTO_TEST_CASE( test_all_multipoint_box_3d )
  549. {
  550. test_distance_multipoint_box_3d(point_box_strategy());
  551. }
  552. BOOST_AUTO_TEST_CASE( test_all_empty_input_pointlike_areal )
  553. {
  554. test_more_empty_input_pointlike_areal
  555. <
  556. point_type
  557. >(point_segment_strategy());
  558. }