azimuth.hpp 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. // Copyright (c) 2016-2021 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 <type_traits>
  11. #include <boost/geometry/srs/spheroid.hpp>
  12. #include <boost/geometry/strategies/azimuth.hpp>
  13. #include <boost/geometry/strategies/geographic/parameters.hpp>
  14. #include <boost/geometry/util/select_most_precise.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. template <typename T1, typename T2>
  29. struct result_type
  30. : geometry::select_most_precise
  31. <
  32. T1, T2, CalculationType
  33. >
  34. {};
  35. typedef Spheroid model_type;
  36. inline geographic()
  37. : m_spheroid()
  38. {}
  39. explicit inline geographic(Spheroid const& spheroid)
  40. : m_spheroid(spheroid)
  41. {}
  42. inline model_type const& model() const
  43. {
  44. return m_spheroid;
  45. }
  46. template <typename T1, typename T2, typename Result>
  47. inline void apply(T1 const& lon1_rad, T1 const& lat1_rad,
  48. T2 const& lon2_rad, T2 const& lat2_rad,
  49. Result& a1, Result& a2) const
  50. {
  51. compute<true, true>(lon1_rad, lat1_rad,
  52. lon2_rad, lat2_rad,
  53. a1, a2);
  54. }
  55. template <typename T1, typename T2, typename Result>
  56. inline void apply(T1 const& lon1_rad, T1 const& lat1_rad,
  57. T2 const& lon2_rad, T2 const& lat2_rad,
  58. Result& a1) const
  59. {
  60. compute<true, false>(lon1_rad, lat1_rad,
  61. lon2_rad, lat2_rad,
  62. a1, a1);
  63. }
  64. template <typename T1, typename T2, typename Result>
  65. inline void apply_reverse(T1 const& lon1_rad, T1 const& lat1_rad,
  66. T2 const& lon2_rad, T2 const& lat2_rad,
  67. Result& a2) const
  68. {
  69. compute<false, true>(lon1_rad, lat1_rad,
  70. lon2_rad, lat2_rad,
  71. a2, a2);
  72. }
  73. private :
  74. template
  75. <
  76. bool EnableAzimuth,
  77. bool EnableReverseAzimuth,
  78. typename T1, typename T2, typename Result
  79. >
  80. inline void compute(T1 const& lon1_rad, T1 const& lat1_rad,
  81. T2 const& lon2_rad, T2 const& lat2_rad,
  82. Result& a1, Result& a2) const
  83. {
  84. typedef typename result_type<T1, T2>::type calc_t;
  85. typedef typename FormulaPolicy::template inverse
  86. <
  87. calc_t,
  88. false,
  89. EnableAzimuth,
  90. EnableReverseAzimuth,
  91. false,
  92. false
  93. > inverse_type;
  94. typedef typename inverse_type::result_type inverse_result;
  95. inverse_result i_res = inverse_type::apply(calc_t(lon1_rad), calc_t(lat1_rad),
  96. calc_t(lon2_rad), calc_t(lat2_rad),
  97. m_spheroid);
  98. if (EnableAzimuth)
  99. {
  100. a1 = i_res.azimuth;
  101. }
  102. if (EnableReverseAzimuth)
  103. {
  104. a2 = i_res.reverse_azimuth;
  105. }
  106. }
  107. Spheroid m_spheroid;
  108. };
  109. #ifndef DOXYGEN_NO_STRATEGY_SPECIALIZATIONS
  110. namespace services
  111. {
  112. template <>
  113. struct default_strategy<geographic_tag>
  114. {
  115. typedef strategy::azimuth::geographic
  116. <
  117. strategy::andoyer,
  118. srs::spheroid<double>
  119. > type;
  120. };
  121. }
  122. #endif // DOXYGEN_NO_STRATEGY_SPECIALIZATIONS
  123. }} // namespace strategy::azimuth
  124. }} // namespace boost::geometry
  125. #endif // BOOST_GEOMETRY_STRATEGIES_GEOGRAPHIC_AZIMUTH_HPP