azimuth.hpp 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. // Copyright (c) 2016-2017 Oracle and/or its affiliates.
  3. // Contributed and/or modified by Vissarion Fisikopoulos, on behalf of Oracle
  4. // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
  5. // Use, modification and distribution is subject to the Boost Software License,
  6. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  7. // http://www.boost.org/LICENSE_1_0.txt)
  8. #ifndef BOOST_GEOMETRY_STRATEGIES_GEOGRAPHIC_AZIMUTH_HPP
  9. #define BOOST_GEOMETRY_STRATEGIES_GEOGRAPHIC_AZIMUTH_HPP
  10. #include <boost/geometry/srs/spheroid.hpp>
  11. #include <boost/geometry/strategies/azimuth.hpp>
  12. #include <boost/geometry/strategies/geographic/parameters.hpp>
  13. #include <boost/mpl/if.hpp>
  14. #include <boost/type_traits/is_void.hpp>
  15. namespace boost { namespace geometry
  16. {
  17. namespace strategy { namespace azimuth
  18. {
  19. template
  20. <
  21. typename FormulaPolicy = strategy::andoyer,
  22. typename Spheroid = srs::spheroid<double>,
  23. typename CalculationType = void
  24. >
  25. class geographic
  26. {
  27. public :
  28. typedef Spheroid model_type;
  29. inline geographic()
  30. : m_spheroid()
  31. {}
  32. explicit inline geographic(Spheroid const& spheroid)
  33. : m_spheroid(spheroid)
  34. {}
  35. inline model_type const& model() const
  36. {
  37. return m_spheroid;
  38. }
  39. template <typename T>
  40. inline void apply(T const& lon1_rad, T const& lat1_rad,
  41. T const& lon2_rad, T const& lat2_rad,
  42. T& a1, T& a2) const
  43. {
  44. compute<true, true>(lon1_rad, lat1_rad,
  45. lon2_rad, lat2_rad,
  46. a1, a2);
  47. }
  48. template <typename T>
  49. inline void apply(T const& lon1_rad, T const& lat1_rad,
  50. T const& lon2_rad, T const& lat2_rad,
  51. T& a1) const
  52. {
  53. compute<true, false>(lon1_rad, lat1_rad,
  54. lon2_rad, lat2_rad,
  55. a1, a1);
  56. }
  57. template <typename T>
  58. inline void apply_reverse(T const& lon1_rad, T const& lat1_rad,
  59. T const& lon2_rad, T const& lat2_rad,
  60. T& a2) const
  61. {
  62. compute<false, true>(lon1_rad, lat1_rad,
  63. lon2_rad, lat2_rad,
  64. a2, a2);
  65. }
  66. private :
  67. template <
  68. bool EnableAzimuth,
  69. bool EnableReverseAzimuth,
  70. typename T
  71. >
  72. inline void compute(T const& lon1_rad, T const& lat1_rad,
  73. T const& lon2_rad, T const& lat2_rad,
  74. T& a1, T& a2) const
  75. {
  76. typedef typename boost::mpl::if_
  77. <
  78. boost::is_void<CalculationType>, T, CalculationType
  79. >::type calc_t;
  80. typedef typename FormulaPolicy::template inverse
  81. <
  82. calc_t,
  83. false,
  84. EnableAzimuth,
  85. EnableReverseAzimuth,
  86. false,
  87. false
  88. > inverse_type;
  89. typedef typename inverse_type::result_type inverse_result;
  90. inverse_result i_res = inverse_type::apply(calc_t(lon1_rad), calc_t(lat1_rad),
  91. calc_t(lon2_rad), calc_t(lat2_rad),
  92. m_spheroid);
  93. if (EnableAzimuth)
  94. {
  95. a1 = i_res.azimuth;
  96. }
  97. if (EnableReverseAzimuth)
  98. {
  99. a2 = i_res.reverse_azimuth;
  100. }
  101. }
  102. Spheroid m_spheroid;
  103. };
  104. #ifndef DOXYGEN_NO_STRATEGY_SPECIALIZATIONS
  105. namespace services
  106. {
  107. template <typename CalculationType>
  108. struct default_strategy<geographic_tag, CalculationType>
  109. {
  110. typedef strategy::azimuth::geographic
  111. <
  112. strategy::andoyer,
  113. srs::spheroid<double>,
  114. CalculationType
  115. > type;
  116. };
  117. }
  118. #endif // DOXYGEN_NO_STRATEGY_SPECIALIZATIONS
  119. }} // namespace strategy::azimuth
  120. }} // namespace boost::geometry
  121. #endif // BOOST_GEOMETRY_STRATEGIES_GEOGRAPHIC_AZIMUTH_HPP