/libs/geometry/test/strategies/spherical_side.cpp

https://github.com/delalond/boost_1_54_0-bgq · C++ · 142 lines · 84 code · 31 blank · 27 comment · 4 complexity · c1a24e4be97b2862e7e233e0d5f1eb75 MD5 · raw file

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