spherical_side.cpp 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. // Unit Test
  3. // Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
  4. // This file was modified by Oracle on 2014, 2015.
  5. // Modifications copyright (c) 2014-2015, Oracle and/or its affiliates.
  6. // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
  7. // Use, modification and distribution is subject to the Boost Software License,
  8. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  9. // http://www.boost.org/LICENSE_1_0.txt)
  10. #include <geometry_test_common.hpp>
  11. #include <boost/geometry/algorithms/assign.hpp>
  12. #include <boost/geometry/core/coordinate_type.hpp>
  13. #include <boost/geometry/core/cs.hpp>
  14. #include <boost/geometry/geometries/point.hpp>
  15. #include <boost/geometry/geometries/segment.hpp>
  16. #include <boost/geometry/strategies/spherical/side_by_cross_track.hpp>
  17. //#include <boost/geometry/strategies/spherical/side_via_plane.hpp>
  18. #include <boost/geometry/strategies/spherical/ssf.hpp>
  19. #include <boost/geometry/strategies/cartesian/side_by_triangle.hpp>
  20. #include <boost/geometry/strategies/geographic/mapping_ssf.hpp>
  21. #include <boost/geometry/strategies/geographic/side_andoyer.hpp>
  22. #include <boost/geometry/strategies/geographic/side_thomas.hpp>
  23. #include <boost/geometry/strategies/geographic/side_vincenty.hpp>
  24. #include <boost/geometry/util/math.hpp>
  25. namespace boost { namespace geometry {
  26. template <typename Vector, typename Point1, typename Point2>
  27. static inline Vector create_vector(Point1 const& p1, Point2 const& p2)
  28. {
  29. Vector v;
  30. convert(p1, v);
  31. subtract_point(v, p2);
  32. return v;
  33. }
  34. }}
  35. inline char side_char(int side)
  36. {
  37. return side == 1 ? 'L'
  38. : side == -1 ? 'R'
  39. : '-'
  40. ;
  41. }
  42. template <typename Point>
  43. void test_side1(std::string const& /*case_id*/, Point const& p1, Point const& p2, Point const& p3,
  44. int expected, int expected_cartesian)
  45. {
  46. namespace bgss = bg::strategy::side;
  47. // std::cout << case_id << ": ";
  48. //int s = bgss::side_via_plane<>::apply(p1, p2, p3);
  49. int side_ssf = bgss::spherical_side_formula<>::apply(p1, p2, p3);
  50. //int side2 = bgss::side_via_plane<>::apply(p1, p2, p3);
  51. int side_ct = bgss::side_by_cross_track<>::apply(p1, p2, p3);
  52. // non-official
  53. typedef bg::srs::spheroid<double> spheroid;
  54. spheroid const sph(1.0, 1.0);
  55. int side_mssf1 = bgss::mapping_spherical_side_formula<spheroid>(sph).apply(p1, p2, p3);
  56. int side_mssf2 = bgss::mapping_spherical_side_formula<spheroid, bgss::mapping_reduced>(sph).apply(p1, p2, p3);
  57. int side_mssf3 = bgss::mapping_spherical_side_formula<spheroid, bgss::mapping_geocentric>(sph).apply(p1, p2, p3);
  58. int side_andoyer = bgss::andoyer<spheroid>(sph).apply(p1, p2, p3);
  59. int side_thomas = bgss::thomas<spheroid>(sph).apply(p1, p2, p3);
  60. int side_vincenty = bgss::vincenty<spheroid>(sph).apply(p1, p2, p3);
  61. // cartesian
  62. typedef bg::strategy::side::services::default_strategy<bg::cartesian_tag>::type cartesian_strategy;
  63. int side_cart = cartesian_strategy::apply(p1, p2, p3);
  64. BOOST_CHECK_EQUAL(side_ssf, expected);
  65. BOOST_CHECK_EQUAL(side_ct, expected);
  66. BOOST_CHECK_EQUAL(side_mssf1, expected);
  67. BOOST_CHECK_EQUAL(side_mssf2, expected);
  68. BOOST_CHECK_EQUAL(side_mssf3, expected);
  69. BOOST_CHECK_EQUAL(side_andoyer, expected);
  70. BOOST_CHECK_EQUAL(side_thomas, expected);
  71. BOOST_CHECK_EQUAL(side_vincenty, expected);
  72. BOOST_CHECK_EQUAL(side_cart, expected_cartesian);
  73. /*
  74. std::cout
  75. << "exp: " << side_char(expected)
  76. << " ssf: " << side_char(side1)
  77. << " pln: " << side_char(side2)
  78. << " ct: " << side_char(side3)
  79. //<< " def: " << side_char(side4)
  80. << " cart: " << side_char(side5)
  81. << std::endl;
  82. */
  83. }
  84. template <typename Point>
  85. void test_side(std::string const& case_id, Point const& p1, Point const& p2, Point const& p3,
  86. int expected, int expected_cartesian = -999)
  87. {
  88. if (expected_cartesian == -999)
  89. {
  90. expected_cartesian = expected;
  91. }
  92. test_side1(case_id, p1, p2, p3, expected, expected_cartesian);
  93. test_side1(case_id, p2, p1, p3, -expected, -expected_cartesian);
  94. }
  95. template <typename Point>
  96. void test_all()
  97. {
  98. typedef typename bg::coordinate_type<Point>::type CT;
  99. Point amsterdam(bg::math::rounding_cast<CT>(5.9), bg::math::rounding_cast<CT>(52.4));
  100. Point barcelona(2.0, 41.0);
  101. Point paris(2.0, 48.0);
  102. Point milan(7.0, 45.0);
  103. //goto wrong;
  104. test_side<Point>("bp-m", barcelona, paris, milan, -1);
  105. test_side<Point>("bm-p", barcelona, milan, paris, 1);
  106. test_side<Point>("mp-b", milan, paris, barcelona, 1);
  107. test_side<Point>("am-p", amsterdam, milan, paris, -1);
  108. test_side<Point>("pm-a", paris, milan, amsterdam, 1);
  109. // http://www.gcmap.com/mapui?P=30N+10E-50N+50E,39N+30E
  110. Point gcmap_p1(10.0, 30.0);
  111. Point gcmap_p2(50.0, 50.0);
  112. test_side<Point>("blog1", gcmap_p1, gcmap_p2, Point(30.0, 41.0), -1, 1);
  113. test_side<Point>("blog1", gcmap_p1, gcmap_p2, Point(30.0, 42.0), -1, 1);
  114. test_side<Point>("blog1", gcmap_p1, gcmap_p2, Point(30.0, 43.0), -1, 1);
  115. test_side<Point>("blog1", gcmap_p1, gcmap_p2, Point(30.0, 44.0), 1);
  116. // http://www.gcmap.com/mapui?P=50N+80E-60N+50W,65N+30E
  117. Point gcmap_np1(80.0, 50.0);
  118. Point gcmap_np2(-50.0, 60.0);
  119. // http://www.gcmap.com/mapui?P=50N+140E-60N+10E,65N+30E
  120. //Point gcmap_np1(140.0, 50.0);
  121. //Point gcmap_np2(10.0, 60.0);
  122. //test_side<Point>(gcmap_np1, gcmap_np2, gcmap_np, 1);
  123. test_side<Point>("40", gcmap_np1, gcmap_np2, Point(30.0, 60.0), 1, -1);
  124. test_side<Point>("45", gcmap_np1, gcmap_np2, Point(30.0, 65.0), 1, -1);
  125. test_side<Point>("70", gcmap_np1, gcmap_np2, Point(30.0, 70.0), 1, -1);
  126. test_side<Point>("75", gcmap_np1, gcmap_np2, Point(30.0, 75.0), -1);
  127. }
  128. int test_main(int, char* [])
  129. {
  130. test_all<bg::model::point<int, 2, bg::cs::spherical<bg::degree> > >();
  131. test_all<bg::model::point<double, 2, bg::cs::spherical_equatorial<bg::degree> > >();
  132. #if defined(HAVE_TTMATH)
  133. typedef ttmath::Big<1,4> tt;
  134. test_all<bg::model::point<tt, 2, bg::cs::spherical_equatorial<bg::degree> > >();
  135. #endif
  136. return 0;
  137. }