equals_on_spheroid.cpp 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. // Unit test
  3. // Copyright (c) 2015, Oracle and/or its affiliates.
  4. // Licensed under the Boost Software License version 1.0.
  5. // http://www.boost.org/users/license.html
  6. // Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
  7. #ifndef BOOST_TEST_MODULE
  8. #define BOOST_TEST_MODULE test_equals_on_spheroid
  9. #endif
  10. #include <iostream>
  11. #include <boost/test/included/unit_test.hpp>
  12. #include "test_equals.hpp"
  13. #include <boost/geometry/geometries/geometries.hpp>
  14. #include <boost/geometry/core/cs.hpp>
  15. namespace bgm = bg::model;
  16. template <typename P1, typename P2 = P1>
  17. struct test_point_point
  18. {
  19. static inline void apply(std::string const& header)
  20. {
  21. std::string const str = header + "-";
  22. test_geometry<P1, P2>(str + "pp_01", "POINT(0 0)", "POINT(0 0)", true);
  23. test_geometry<P1, P2>(str + "pp_02", "POINT(0 0)", "POINT(10 0)", false);
  24. // points whose longitudes differ by 360 degrees
  25. test_geometry<P1, P2>(str + "pp_03", "POINT(0 0)", "POINT(360 0)", true);
  26. test_geometry<P1, P2>(str + "pp_04", "POINT(10 0)", "POINT(370 0)", true);
  27. test_geometry<P1, P2>(str + "pp_05", "POINT(10 0)", "POINT(-350 0)", true);
  28. test_geometry<P1, P2>(str + "pp_06", "POINT(180 10)", "POINT(-180 10)", true);
  29. test_geometry<P1, P2>(str + "pp_06a", "POINT(540 10)", "POINT(-540 10)", true);
  30. #ifdef BOOST_GEOMETRY_NORMALIZE_LATITUDE
  31. test_geometry<P1, P2>(str + "pp_06b", "POINT(540 370)", "POINT(-540 -350)", true);
  32. test_geometry<P1, P2>(str + "pp_06c", "POINT(1260 370)", "POINT(-1260 -350)", true);
  33. test_geometry<P1, P2>(str + "pp_06d", "POINT(2340 370)", "POINT(-2340 -350)", true);
  34. #endif
  35. test_geometry<P1, P2>(str + "pp_06e", "POINT(-180 10)", "POINT(-540 10)", true);
  36. test_geometry<P1, P2>(str + "pp_06f", "POINT(180 10)", "POINT(-540 10)", true);
  37. // north & south pole
  38. test_geometry<P1, P2>(str + "pp_07", "POINT(0 90)", "POINT(0 90)", true);
  39. #ifdef BOOST_GEOMETRY_NORMALIZE_LATITUDE
  40. test_geometry<P1, P2>(str + "pp_07a", "POINT(0 450)", "POINT(10 -270)", true);
  41. test_geometry<P1, P2>(str + "pp_07b", "POINT(0 270)", "POINT(10 90)", false);
  42. test_geometry<P1, P2>(str + "pp_07c", "POINT(0 -450)", "POINT(10 90)", false);
  43. #endif
  44. test_geometry<P1, P2>(str + "pp_08", "POINT(0 90)", "POINT(10 90)", true);
  45. test_geometry<P1, P2>(str + "pp_09", "POINT(0 90)", "POINT(0 -90)", false);
  46. test_geometry<P1, P2>(str + "pp_10", "POINT(0 -90)", "POINT(0 -90)", true);
  47. test_geometry<P1, P2>(str + "pp_11", "POINT(0 -90)", "POINT(10 -90)", true);
  48. test_geometry<P1, P2>(str + "pp_11a", "POINT(0 -90)", "POINT(10 90)", false);
  49. test_geometry<P1, P2>(str + "pp_12", "POINT(0 -90)", "POINT(0 -85)", false);
  50. test_geometry<P1, P2>(str + "pp_13", "POINT(0 90)", "POINT(0 85)", false);
  51. test_geometry<P1, P2>(str + "pp_14", "POINT(0 90)", "POINT(10 85)", false);
  52. // symmetric wrt prime meridian
  53. test_geometry<P1, P2>(str + "pp_15", "POINT(-10 45)", "POINT(10 45)", false);
  54. test_geometry<P1, P2>(str + "pp_16", "POINT(-170 45)", "POINT(170 45)", false);
  55. // other points
  56. test_geometry<P1, P2>(str + "pp_17", "POINT(-10 45)", "POINT(10 -45)", false);
  57. test_geometry<P1, P2>(str + "pp_18", "POINT(-10 -45)", "POINT(10 45)", false);
  58. test_geometry<P1, P2>(str + "pp_19", "POINT(10 -135)", "POINT(10 45)", false);
  59. #ifdef BOOST_GEOMETRY_NORMALIZE_LATITUDE
  60. test_geometry<P1, P2>(str + "pp_20", "POINT(190 135)", "POINT(10 45)", true);
  61. test_geometry<P1, P2>(str + "pp_21", "POINT(190 150)", "POINT(10 30)", true);
  62. test_geometry<P1, P2>(str + "pp_21a", "POINT(-170 150)", "POINT(10 30)", true);
  63. test_geometry<P1, P2>(str + "pp_22", "POINT(190 -135)", "POINT(10 -45)", true);
  64. test_geometry<P1, P2>(str + "pp_23", "POINT(190 -150)", "POINT(10 -30)", true);
  65. test_geometry<P1, P2>(str + "pp_23a", "POINT(-170 -150)", "POINT(10 -30)", true);
  66. #endif
  67. }
  68. };
  69. template <typename P1, typename P2 = P1>
  70. struct test_point_point_with_height
  71. {
  72. static inline void apply(std::string const& header)
  73. {
  74. std::string const str = header + "-";
  75. test_geometry<P1, P2>(str + "pp_01",
  76. "POINT(0 0 10)",
  77. "POINT(0 0 20)",
  78. true);
  79. test_geometry<P1, P2>(str + "pp_02",
  80. "POINT(0 0 10)",
  81. "POINT(10 0 10)",
  82. false);
  83. // points whose longitudes differ by 360 degrees
  84. test_geometry<P1, P2>(str + "pp_03",
  85. "POINT(0 0 10)",
  86. "POINT(360 0 10)",
  87. true);
  88. // points whose longitudes differ by 360 degrees
  89. test_geometry<P1, P2>(str + "pp_04",
  90. "POINT(10 0 10)",
  91. "POINT(370 0 10)",
  92. true);
  93. test_geometry<P1, P2>(str + "pp_05",
  94. "POINT(10 0 10)",
  95. "POINT(10 0 370)",
  96. false);
  97. }
  98. };
  99. template <typename P>
  100. void test_segment_segment(std::string const& header)
  101. {
  102. typedef bgm::segment<P> seg;
  103. std::string const str = header + "-";
  104. test_geometry<seg, seg>(str + "ss_01",
  105. "SEGMENT(10 0,180 0)",
  106. "SEGMENT(10 0,-180 0)",
  107. true);
  108. test_geometry<seg, seg>(str + "ss_02",
  109. "SEGMENT(0 90,180 0)",
  110. "SEGMENT(10 90,-180 0)",
  111. true);
  112. test_geometry<seg, seg>(str + "ss_03",
  113. "SEGMENT(0 90,0 -90)",
  114. "SEGMENT(10 90,20 -90)",
  115. true);
  116. test_geometry<seg, seg>(str + "ss_04",
  117. "SEGMENT(10 80,10 -80)",
  118. "SEGMENT(10 80,20 -80)",
  119. false);
  120. test_geometry<seg, seg>(str + "ss_05",
  121. "SEGMENT(170 10,-170 10)",
  122. "SEGMENT(170 10,350 10)",
  123. false);
  124. }
  125. BOOST_AUTO_TEST_CASE( equals_point_point_se )
  126. {
  127. typedef bg::cs::spherical_equatorial<bg::degree> cs_type;
  128. test_point_point<bgm::point<int, 2, cs_type> >::apply("se");
  129. test_point_point<bgm::point<double, 2, cs_type> >::apply("se");
  130. test_point_point<bgm::point<long double, 2, cs_type> >::apply("se");
  131. // mixed point types
  132. test_point_point
  133. <
  134. bgm::point<double, 2, cs_type>, bgm::point<int, 2, cs_type>
  135. >::apply("se");
  136. test_point_point
  137. <
  138. bgm::point<double, 2, cs_type>, bgm::point<long double, 2, cs_type>
  139. >::apply("se");
  140. #if defined(HAVE_TTMATH)
  141. test_point_point<bgm::point<ttmath_big, 2, cs_type> >::apply("se");
  142. #endif
  143. }
  144. BOOST_AUTO_TEST_CASE( equals_point_point_with_height_se )
  145. {
  146. typedef bg::cs::spherical_equatorial<bg::degree> cs_type;
  147. test_point_point<bgm::point<int, 3, cs_type> >::apply("seh");
  148. test_point_point<bgm::point<double, 3, cs_type> >::apply("seh");
  149. test_point_point<bgm::point<long double, 3, cs_type> >::apply("seh");
  150. // mixed point types
  151. test_point_point
  152. <
  153. bgm::point<double, 3, cs_type>, bgm::point<int, 3, cs_type>
  154. >::apply("seh");
  155. test_point_point
  156. <
  157. bgm::point<double, 3, cs_type>, bgm::point<long double, 3, cs_type>
  158. >::apply("seh");
  159. #if defined(HAVE_TTMATH)
  160. test_point_point<bgm::point<ttmath_big, 3, cs_type> >::apply("seh");
  161. #endif
  162. }
  163. BOOST_AUTO_TEST_CASE( equals_point_point_geo )
  164. {
  165. typedef bg::cs::geographic<bg::degree> cs_type;
  166. test_point_point<bgm::point<int, 2, cs_type> >::apply("geo");
  167. test_point_point<bgm::point<double, 2, cs_type> >::apply("geo");
  168. test_point_point<bgm::point<long double, 2, cs_type> >::apply("geo");
  169. // mixed point types
  170. test_point_point
  171. <
  172. bgm::point<double, 2, cs_type>, bgm::point<int, 2, cs_type>
  173. >::apply("se");
  174. test_point_point
  175. <
  176. bgm::point<double, 2, cs_type>, bgm::point<long double, 2, cs_type>
  177. >::apply("se");
  178. #if defined(HAVE_TTMATH)
  179. test_point_point<bgm::point<ttmath_big, 2, cs_type> >::apply("geo");
  180. #endif
  181. }
  182. BOOST_AUTO_TEST_CASE( equals_segment_segment_se )
  183. {
  184. typedef bg::cs::spherical_equatorial<bg::degree> cs_type;
  185. test_segment_segment<bgm::point<int, 2, cs_type> >("se");
  186. test_segment_segment<bgm::point<double, 2, cs_type> >("se");
  187. test_segment_segment<bgm::point<long double, 2, cs_type> >("se");
  188. #if defined(HAVE_TTMATH)
  189. test_segment_segment<bgm::point<ttmath_big, 2, cs_type> >("se");
  190. #endif
  191. }
  192. BOOST_AUTO_TEST_CASE( equals_segment_segment_geo )
  193. {
  194. typedef bg::cs::geographic<bg::degree> cs_type;
  195. test_segment_segment<bgm::point<int, 2, cs_type> >("geo");
  196. test_segment_segment<bgm::point<double, 2, cs_type> >("geo");
  197. test_segment_segment<bgm::point<long double, 2, cs_type> >("geo");
  198. #if defined(HAVE_TTMATH)
  199. test_segment_segment<bgm::point<ttmath_big, 2, cs_type> >("geo");
  200. #endif
  201. }