segment_intersection_geo.hpp 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. // Boost.Geometry
  2. // Unit Test
  3. // Copyright (c) 2017 Adam Wulkiewicz, Lodz, Poland.
  4. // Copyright (c) 2016, Oracle and/or its affiliates.
  5. // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
  6. // Use, modification and distribution is subject to the Boost Software License,
  7. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  8. // http://www.boost.org/LICENSE_1_0.txt)
  9. #ifndef BOOST_GEOMETRY_TEST_STRATEGIES_SEGMENT_INTERSECTION_GEO_HPP
  10. #define BOOST_GEOMETRY_TEST_STRATEGIES_SEGMENT_INTERSECTION_GEO_HPP
  11. #include "segment_intersection_sph.hpp"
  12. #include <boost/geometry/strategies/geographic/intersection.hpp>
  13. #include <boost/geometry/strategies/geographic/intersection_elliptic.hpp>
  14. template <typename S, typename P>
  15. void test_default_strategy(std::string const& s1_wkt, std::string const& s2_wkt,
  16. char m, std::size_t expected_count,
  17. std::string const& ip0_wkt = "", std::string const& ip1_wkt = "",
  18. int opposite_id = -1)
  19. {
  20. typename bg::strategy::intersection::services::default_strategy
  21. <
  22. bg::geographic_tag
  23. >::type strategy;
  24. test_strategy<S, S, P>(s1_wkt, s2_wkt, strategy, m, expected_count, ip0_wkt, ip1_wkt, opposite_id);
  25. }
  26. template <typename S, typename P>
  27. void test_great_elliptic(std::string const& s1_wkt, std::string const& s2_wkt,
  28. char m, std::size_t expected_count,
  29. std::string const& ip0_wkt = "", std::string const& ip1_wkt = "",
  30. int opposite_id = -1)
  31. {
  32. bg::strategy::intersection::great_elliptic_segments<> strategy;
  33. test_strategy<S, S, P>(s1_wkt, s2_wkt, strategy, m, expected_count, ip0_wkt, ip1_wkt, opposite_id);
  34. }
  35. /*
  36. template <typename S, typename P>
  37. void test_experimental_elliptic(std::string const& s1_wkt, std::string const& s2_wkt,
  38. char m, std::size_t expected_count,
  39. std::string const& ip0_wkt = "", std::string const& ip1_wkt = "",
  40. int opposite_id = -1)
  41. {
  42. bg::strategy::intersection::experimental_elliptic_segments<> strategy;
  43. test_strategy<S, S, P>(s1_wkt, s2_wkt, strategy, m, expected_count, ip0_wkt, ip1_wkt, opposite_id);
  44. }
  45. */
  46. template <typename S, typename P>
  47. void test_geodesic_vincenty(std::string const& s1_wkt, std::string const& s2_wkt,
  48. char m, std::size_t expected_count,
  49. std::string const& ip0_wkt = "", std::string const& ip1_wkt = "",
  50. int opposite_id = -1)
  51. {
  52. bg::strategy::intersection::geographic_segments<bg::strategy::vincenty, 4> strategy;
  53. test_strategy<S, S, P>(s1_wkt, s2_wkt, strategy, m, expected_count, ip0_wkt, ip1_wkt, opposite_id);
  54. }
  55. template <typename S, typename P>
  56. void test_geodesic_thomas(std::string const& s1_wkt, std::string const& s2_wkt,
  57. char m, std::size_t expected_count,
  58. std::string const& ip0_wkt = "", std::string const& ip1_wkt = "",
  59. int opposite_id = -1)
  60. {
  61. bg::strategy::intersection::geographic_segments<bg::strategy::thomas, 2> strategy;
  62. test_strategy<S, S, P>(s1_wkt, s2_wkt, strategy, m, expected_count, ip0_wkt, ip1_wkt, opposite_id);
  63. }
  64. template <typename S, typename P>
  65. void test_geodesic_andoyer(std::string const& s1_wkt, std::string const& s2_wkt,
  66. char m, std::size_t expected_count,
  67. std::string const& ip0_wkt = "", std::string const& ip1_wkt = "",
  68. int opposite_id = -1)
  69. {
  70. bg::strategy::intersection::geographic_segments<bg::strategy::andoyer, 1> strategy;
  71. test_strategy<S, S, P>(s1_wkt, s2_wkt, strategy, m, expected_count, ip0_wkt, ip1_wkt, opposite_id);
  72. }
  73. struct strategy_base
  74. {
  75. strategy_base(char m_)
  76. : m(m_), expected_count(0), opposite(-1)
  77. {}
  78. strategy_base(char m_, std::string const& wkt1_)
  79. : m(m_), expected_count(1), wkt1(wkt1_), opposite(-1)
  80. {}
  81. strategy_base(char m_, std::string const& wkt1_, std::string const& wkt2_, bool opposite_)
  82. : m(m_), expected_count(1), wkt1(wkt1_), wkt2(wkt2_), opposite(opposite_ ? 1 : 0)
  83. {}
  84. char m;
  85. std::size_t expected_count;
  86. std::string wkt1, wkt2;
  87. int opposite;
  88. };
  89. struct strategy_default : strategy_base
  90. {
  91. strategy_default(char m)
  92. : strategy_base(m)
  93. {}
  94. strategy_default(char m, std::string const& wkt1)
  95. : strategy_base(m, wkt1)
  96. {}
  97. strategy_default(char m, std::string const& wkt1, std::string const& wkt2, bool opposite)
  98. : strategy_base(m, wkt1, wkt2, opposite)
  99. {}
  100. };
  101. struct geodesic_vincenty : strategy_base
  102. {
  103. geodesic_vincenty(char m)
  104. : strategy_base(m)
  105. {}
  106. geodesic_vincenty(char m, std::string const& wkt1)
  107. : strategy_base(m, wkt1)
  108. {}
  109. geodesic_vincenty(char m, std::string const& wkt1, std::string const& wkt2, bool opposite)
  110. : strategy_base(m, wkt1, wkt2, opposite)
  111. {}
  112. };
  113. struct geodesic_thomas : strategy_base
  114. {
  115. geodesic_thomas(char m)
  116. : strategy_base(m)
  117. {}
  118. geodesic_thomas(char m, std::string const& wkt1)
  119. : strategy_base(m, wkt1)
  120. {}
  121. geodesic_thomas(char m, std::string const& wkt1, std::string const& wkt2, bool opposite)
  122. : strategy_base(m, wkt1, wkt2, opposite)
  123. {}
  124. };
  125. struct geodesic_andoyer : strategy_base
  126. {
  127. geodesic_andoyer(char m)
  128. : strategy_base(m)
  129. {}
  130. geodesic_andoyer(char m, std::string const& wkt1)
  131. : strategy_base(m, wkt1)
  132. {}
  133. geodesic_andoyer(char m, std::string const& wkt1, std::string const& wkt2, bool opposite)
  134. : strategy_base(m, wkt1, wkt2, opposite)
  135. {}
  136. };
  137. struct great_elliptic : strategy_base
  138. {
  139. great_elliptic(char m)
  140. : strategy_base(m)
  141. {}
  142. great_elliptic(char m, std::string const& wkt1)
  143. : strategy_base(m, wkt1)
  144. {}
  145. great_elliptic(char m, std::string const& wkt1, std::string const& wkt2, bool opposite)
  146. : strategy_base(m, wkt1, wkt2, opposite)
  147. {}
  148. };
  149. template <typename S, typename P>
  150. void test_strategy(std::string const& s1_wkt, std::string const& s2_wkt,
  151. strategy_default const& s)
  152. {
  153. test_default_strategy<S, P>(s1_wkt, s2_wkt, s.m, s.expected_count, s.wkt1, s.wkt2);
  154. }
  155. template <typename S, typename P>
  156. void test_strategy(std::string const& s1_wkt, std::string const& s2_wkt,
  157. great_elliptic const& s)
  158. {
  159. test_great_elliptic<S, P>(s1_wkt, s2_wkt, s.m, s.expected_count, s.wkt1, s.wkt2);
  160. }
  161. template <typename S, typename P>
  162. void test_strategy(std::string const& s1_wkt, std::string const& s2_wkt,
  163. geodesic_vincenty const& s)
  164. {
  165. test_geodesic_vincenty<S, P>(s1_wkt, s2_wkt, s.m, s.expected_count, s.wkt1, s.wkt2);
  166. }
  167. template <typename S, typename P>
  168. void test_strategy(std::string const& s1_wkt, std::string const& s2_wkt,
  169. geodesic_thomas const& s)
  170. {
  171. test_geodesic_thomas<S, P>(s1_wkt, s2_wkt, s.m, s.expected_count, s.wkt1, s.wkt2);
  172. }
  173. template <typename S, typename P>
  174. void test_strategy(std::string const& s1_wkt, std::string const& s2_wkt,
  175. geodesic_andoyer const& s)
  176. {
  177. test_geodesic_andoyer<S, P>(s1_wkt, s2_wkt, s.m, s.expected_count, s.wkt1, s.wkt2);
  178. }
  179. template <typename S, typename P, typename SR1>
  180. void test_strategies(std::string const& s1_wkt, std::string const& s2_wkt,
  181. SR1 const& sr1)
  182. {
  183. test_strategy<S, P>(s1_wkt, s2_wkt, sr1);
  184. }
  185. template <typename S, typename P, typename SR1, typename SR2>
  186. void test_strategies(std::string const& s1_wkt, std::string const& s2_wkt,
  187. SR1 const& sr1, SR2 const& sr2)
  188. {
  189. test_strategy<S, P>(s1_wkt, s2_wkt, sr1);
  190. test_strategy<S, P>(s1_wkt, s2_wkt, sr2);
  191. }
  192. template <typename S, typename P, typename SR1, typename SR2, typename SR3>
  193. void test_strategies(std::string const& s1_wkt, std::string const& s2_wkt,
  194. SR1 const& sr1, SR2 const& sr2, SR3 const& sr3)
  195. {
  196. test_strategy<S, P>(s1_wkt, s2_wkt, sr1);
  197. test_strategy<S, P>(s1_wkt, s2_wkt, sr2);
  198. test_strategy<S, P>(s1_wkt, s2_wkt, sr3);
  199. }
  200. template <typename S, typename P, typename SR1, typename SR2, typename SR3, typename SR4>
  201. void test_strategies(std::string const& s1_wkt, std::string const& s2_wkt,
  202. SR1 const& sr1, SR2 const& sr2, SR3 const& sr3, SR4 const& sr4)
  203. {
  204. test_strategy<S, P>(s1_wkt, s2_wkt, sr1);
  205. test_strategy<S, P>(s1_wkt, s2_wkt, sr2);
  206. test_strategy<S, P>(s1_wkt, s2_wkt, sr3);
  207. test_strategy<S, P>(s1_wkt, s2_wkt, sr4);
  208. }
  209. template <typename S, typename P>
  210. void test_all_strategies(std::string const& s1_wkt, std::string const& s2_wkt,
  211. char m, std::string const& ip0_wkt = "")
  212. {
  213. std::size_t expected_count = ip0_wkt.empty() ? 0 : 1;
  214. test_default_strategy<S, P>(s1_wkt, s2_wkt, m, expected_count, ip0_wkt);
  215. test_great_elliptic<S, P>(s1_wkt, s2_wkt, m, expected_count, ip0_wkt);
  216. //test_experimental_elliptic<S, P>(s1_wkt, s2_wkt, m, expected_count, ip0_wkt);
  217. test_geodesic_vincenty<S, P>(s1_wkt, s2_wkt, m, expected_count, ip0_wkt);
  218. test_geodesic_thomas<S, P>(s1_wkt, s2_wkt, m, expected_count, ip0_wkt);
  219. test_geodesic_andoyer<S, P>(s1_wkt, s2_wkt, m, expected_count, ip0_wkt);
  220. }
  221. template <typename S, typename P>
  222. void test_all_strategies(std::string const& s1_wkt, std::string const& s2_wkt,
  223. char m,
  224. std::string const& ip0_wkt, std::string const& ip1_wkt,
  225. bool opposite)
  226. {
  227. int opposite_id = opposite ? 1 : 0;
  228. test_default_strategy<S, P>(s1_wkt, s2_wkt, m, 2, ip0_wkt, ip1_wkt, opposite_id);
  229. test_great_elliptic<S, P>(s1_wkt, s2_wkt, m, 2, ip0_wkt, ip1_wkt, opposite_id);
  230. //test_experimental_elliptic<S, P>(s1_wkt, s2_wkt, m, 2, ip0_wkt, ip1_wkt, opposite_id);
  231. test_geodesic_vincenty<S, P>(s1_wkt, s2_wkt, m, 2, ip0_wkt, ip1_wkt, opposite_id);
  232. test_geodesic_thomas<S, P>(s1_wkt, s2_wkt, m, 2, ip0_wkt, ip1_wkt, opposite_id);
  233. test_geodesic_andoyer<S, P>(s1_wkt, s2_wkt, m, 2, ip0_wkt, ip1_wkt, opposite_id);
  234. }
  235. #endif // BOOST_GEOMETRY_TEST_STRATEGIES_SEGMENT_INTERSECTION_GEO_HPP