distance_se_geo_l_l.cpp 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. // Unit Test
  3. // Copyright (c) 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_linear
  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. //===========================================================================
  19. template <typename Point, typename Strategy>
  20. void test_distance_segment_segment(Strategy const& strategy_ps)
  21. {
  22. #ifdef BOOST_GEOMETRY_TEST_DEBUG
  23. std::cout << std::endl;
  24. std::cout << "segment/segment distance tests" << std::endl;
  25. #endif
  26. typedef bg::model::segment<Point> segment_type;
  27. typedef test_distance_of_geometries<segment_type, segment_type> tester;
  28. tester::apply("s-s-01",
  29. "SEGMENT(0 0,1 1)",
  30. "SEGMENT(2 0,3 0)",
  31. ps_distance<Point>("POINT(2 0)",
  32. "SEGMENT(0 0,1 1)", strategy_ps),
  33. strategy_ps, true, true, false);
  34. tester::apply("s-s-02",
  35. "SEGMENT(2 1,3 1)",
  36. "SEGMENT(2 0,3 0)",
  37. ps_distance<Point>("POINT(2 0)",
  38. "SEGMENT(2 1,3 1)", strategy_ps),
  39. strategy_ps, true, true, false);
  40. tester::apply("s-s-03",
  41. "SEGMENT(2.5 1,3.5 1)",
  42. "SEGMENT(2 0,3 0)",
  43. ps_distance<Point>("POINT(2.5 0)",
  44. "SEGMENT(2.5 1,3.5 1)", strategy_ps),
  45. strategy_ps, true, true, false);
  46. tester::apply("s-s-04",
  47. "SEGMENT(2.5 1,3.5 1)",
  48. "SEGMENT(2 2,3 2)",
  49. ps_distance<Point>("POINT(3 2)",
  50. "SEGMENT(2.5 1,3.5 1)", strategy_ps),
  51. strategy_ps, true, true, false);
  52. tester::apply("s-s-05",
  53. "SEGMENT(2.5 2.1,3.5 1)",
  54. "SEGMENT(2 2,3 2)",
  55. 0, strategy_ps, true, true, false);
  56. tester::apply("s-s-06",
  57. "SEGMENT(2.5 2.1,3.5 1)",
  58. "SEGMENT(2 2,3.5 1)",
  59. 0, strategy_ps, true, true, false);
  60. }
  61. //===========================================================================
  62. template <typename Point, typename Strategy>
  63. void test_distance_segment_linestring(Strategy const& strategy_ps)
  64. {
  65. #ifdef BOOST_GEOMETRY_TEST_DEBUG
  66. std::cout << std::endl;
  67. std::cout << "segment/linestring distance tests" << std::endl;
  68. #endif
  69. typedef bg::model::segment<Point> segment_type;
  70. typedef bg::model::linestring<Point> linestring_type;
  71. typedef test_distance_of_geometries<segment_type, linestring_type> tester;
  72. tester::apply("s-l-01",
  73. "SEGMENT(0 0,1 1)",
  74. "LINESTRING(2 0,3 0)",
  75. ps_distance<Point>("POINT(2 0)",
  76. "SEGMENT(0 0,1 1)", strategy_ps),
  77. strategy_ps, true, true, false);
  78. tester::apply("s-l-02",
  79. "SEGMENT(0 0,1 1)",
  80. "LINESTRING(2 0,3 0,2 2,0.5 0.7)",
  81. ps_distance<Point>("POINT(1 1)",
  82. "SEGMENT(0.5 0.7,2 2)", strategy_ps),
  83. strategy_ps, true, true, false);
  84. tester::apply("s-l-03",
  85. "SEGMENT(0 0,2 2)",
  86. "LINESTRING(2 0,3 0,2 2,0.5 0.7)",
  87. 0, strategy_ps, true, true, false);
  88. }
  89. //===========================================================================
  90. template <typename Point, typename Strategy>
  91. void test_distance_linestring_linestring(Strategy const& strategy_ps)
  92. {
  93. #ifdef BOOST_GEOMETRY_TEST_DEBUG
  94. std::cout << std::endl;
  95. std::cout << "linestring/linestring distance tests" << std::endl;
  96. #endif
  97. typedef bg::model::linestring<Point> linestring_type;
  98. typedef test_distance_of_geometries
  99. <
  100. linestring_type, linestring_type
  101. > tester;
  102. tester::apply("l-l-01",
  103. "LINESTRING(0 0,1 1)",
  104. "LINESTRING(2 0,3 0)",
  105. ps_distance<Point>("POINT(2 0)",
  106. "SEGMENT(0 0,1 1)", strategy_ps),
  107. strategy_ps, true, true, false);
  108. tester::apply("l-l-02",
  109. "LINESTRING(0 0,1 1,2 2)",
  110. "LINESTRING(2 0,3 0,4 1)",
  111. ps_distance<Point>("POINT(2 0)",
  112. "SEGMENT(1 1,2 2)", strategy_ps),
  113. strategy_ps, true, true, false);
  114. tester::apply("l-l-03",
  115. "LINESTRING(0 0,1 1,2 2)",
  116. "LINESTRING(2 0)",
  117. ps_distance<Point>("POINT(2 0)",
  118. "SEGMENT(1 1,2 2)", strategy_ps),
  119. strategy_ps, true, true, false);
  120. tester::apply("l-l-04",
  121. "LINESTRING(0 0,1 1,2 2)",
  122. "LINESTRING(3 3,1 1)",
  123. 0, strategy_ps, true, true, false);
  124. }
  125. //===========================================================================
  126. template <typename Point, typename Strategy>
  127. void test_distance_segment_multilinestring(Strategy const& strategy_ps)
  128. {
  129. #ifdef BOOST_GEOMETRY_TEST_DEBUG
  130. std::cout << std::endl;
  131. std::cout << "segment/multilinestring distance tests" << std::endl;
  132. #endif
  133. typedef bg::model::segment<Point> segment_type;
  134. typedef bg::model::linestring<Point> linestring_type;
  135. typedef bg::model::multi_linestring<linestring_type> multi_linestring_type;
  136. typedef test_distance_of_geometries
  137. <
  138. segment_type, multi_linestring_type
  139. > tester;
  140. tester::apply("s-ml-01",
  141. "SEGMENT(0 0,1 1)",
  142. "MULTILINESTRING((2 0,3 0)(2 5, 5 5, 2 -1))",
  143. ps_distance<Point>("POINT(2 0)",
  144. "SEGMENT(0 0,1 1)", strategy_ps),
  145. strategy_ps, true, true, false);
  146. tester::apply("s-ml-02",
  147. "SEGMENT(0 0,1 1)",
  148. "MULTILINESTRING((2 0,3 0))",
  149. ps_distance<Point>("POINT(2 0)",
  150. "SEGMENT(0 0,1 1)", strategy_ps),
  151. strategy_ps, true, true, false);
  152. tester::apply("s-ml-03",
  153. "SEGMENT(0 0,2 0)",
  154. "MULTILINESTRING((2 0,3 0)(2 5, 5 5, 2 -1))",
  155. 0, strategy_ps, true, true, false);
  156. }
  157. //===========================================================================
  158. template <typename Point, typename Strategy>
  159. void test_distance_linestring_multilinestring(Strategy const& strategy_ps)
  160. {
  161. #ifdef BOOST_GEOMETRY_TEST_DEBUG
  162. std::cout << std::endl;
  163. std::cout << "linestring/multilinestring distance tests" << std::endl;
  164. #endif
  165. typedef bg::model::linestring<Point> linestring_type;
  166. typedef bg::model::multi_linestring<linestring_type> multi_linestring_type;
  167. typedef test_distance_of_geometries
  168. <
  169. linestring_type, multi_linestring_type
  170. > tester;
  171. tester::apply("l-ml-01",
  172. "LINESTRING(0 0,1 1,2 2,3 3,4 4,6 6)",
  173. "MULTILINESTRING((2 0,3 0)(2 1, 5 5))",
  174. ps_distance<Point>("POINT(5 5)",
  175. "SEGMENT(4 4,6 6)", strategy_ps),
  176. strategy_ps, true, true, false);
  177. tester::apply("l-ml-02",
  178. "LINESTRING(0 0,1 1,2 2,3 3,4 4,6 6)",
  179. "MULTILINESTRING((2 0,3 0)(2 5, 5 5))",
  180. 0,
  181. strategy_ps, true, true, false);
  182. }
  183. //===========================================================================
  184. template <typename Point, typename Strategy>
  185. void test_distance_multilinestring_multilinestring(Strategy const& strategy_ps)
  186. {
  187. #ifdef BOOST_GEOMETRY_TEST_DEBUG
  188. std::cout << std::endl;
  189. std::cout << "multilinestring/multilinestring distance tests" << std::endl;
  190. #endif
  191. typedef bg::model::linestring<Point> linestring_type;
  192. typedef bg::model::multi_linestring<linestring_type> multi_linestring_type;
  193. typedef test_distance_of_geometries
  194. <
  195. multi_linestring_type, multi_linestring_type
  196. > tester;
  197. tester::apply("s-ml-01",
  198. "MULTILINESTRING((0 0,1 1)(-1 0, -1 -1))",
  199. "MULTILINESTRING((2 0,3 0)(2 5, 5 5))",
  200. ps_distance<Point>("POINT(2 0)",
  201. "SEGMENT(0 0,1 1)", strategy_ps),
  202. strategy_ps, true, true, false);
  203. tester::apply("s-ml-02",
  204. "MULTILINESTRING((0 0,1 1)(-1 0, -1 -1)(5 0, 5 6))",
  205. "MULTILINESTRING((2 0,3 0)(2 5, 5 5))",
  206. 0,
  207. strategy_ps, true, true, false);
  208. }
  209. //===========================================================================
  210. //===========================================================================
  211. //===========================================================================
  212. template <typename Point, typename Strategy>
  213. void test_all_l_l(Strategy ps_strategy)
  214. {
  215. test_distance_segment_segment<Point>(ps_strategy);
  216. test_distance_segment_linestring<Point>(ps_strategy);
  217. test_distance_linestring_linestring<Point>(ps_strategy);
  218. test_distance_segment_multilinestring<Point>(ps_strategy);
  219. test_distance_linestring_multilinestring<Point>(ps_strategy);
  220. test_distance_multilinestring_multilinestring<Point>(ps_strategy);
  221. test_more_empty_input_linear_linear<Point>(ps_strategy);
  222. }
  223. BOOST_AUTO_TEST_CASE( test_all_linear_linear )
  224. {
  225. typedef bg::model::point
  226. <
  227. double, 2,
  228. bg::cs::spherical_equatorial<bg::degree>
  229. > sph_point;
  230. test_all_l_l<sph_point>(spherical_ps());
  231. typedef bg::model::point
  232. <
  233. double, 2,
  234. bg::cs::geographic<bg::degree>
  235. > geo_point;
  236. test_all_l_l<geo_point>(vincenty_ps());
  237. test_all_l_l<geo_point>(thomas_ps());
  238. test_all_l_l<geo_point>(andoyer_ps());
  239. }