azimuth.hpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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_SPHERICAL_AZIMUTH_HPP
  9. #define BOOST_GEOMETRY_STRATEGIES_SPHERICAL_AZIMUTH_HPP
  10. #include <type_traits>
  11. #include <boost/geometry/formulas/spherical.hpp>
  12. #include <boost/geometry/strategies/azimuth.hpp>
  13. #include <boost/geometry/util/select_most_precise.hpp>
  14. namespace boost { namespace geometry
  15. {
  16. namespace strategy { namespace azimuth
  17. {
  18. template <typename CalculationType = void>
  19. class spherical
  20. {
  21. public:
  22. template <typename T1, typename T2>
  23. struct result_type
  24. : geometry::select_most_precise
  25. <
  26. T1, T2, CalculationType
  27. >
  28. {};
  29. template <typename T1, typename T2, typename Result>
  30. static inline void apply(T1 const& lon1_rad, T1 const& lat1_rad,
  31. T2 const& lon2_rad, T2 const& lat2_rad,
  32. Result& a1, Result& a2)
  33. {
  34. compute<true, true>(lon1_rad, lat1_rad,
  35. lon2_rad, lat2_rad,
  36. a1, a2);
  37. }
  38. template <typename T1, typename T2, typename Result>
  39. static inline void apply(T1 const& lon1_rad, T1 const& lat1_rad,
  40. T2 const& lon2_rad, T2 const& lat2_rad,
  41. Result& a1)
  42. {
  43. compute<true, false>(lon1_rad, lat1_rad,
  44. lon2_rad, lat2_rad,
  45. a1, a1);
  46. }
  47. template <typename T1, typename T2, typename Result>
  48. static inline void apply_reverse(T1 const& lon1_rad, T1 const& lat1_rad,
  49. T2 const& lon2_rad, T2 const& lat2_rad,
  50. Result& a2)
  51. {
  52. compute<false, true>(lon1_rad, lat1_rad,
  53. lon2_rad, lat2_rad,
  54. a2, a2);
  55. }
  56. private:
  57. template
  58. <
  59. bool EnableAzimuth,
  60. bool EnableReverseAzimuth,
  61. typename T1, typename T2, typename Result
  62. >
  63. static inline void compute(T1 const& lon1_rad, T1 const& lat1_rad,
  64. T2 const& lon2_rad, T2 const& lat2_rad,
  65. Result& a1, Result& a2)
  66. {
  67. typedef typename result_type<T1, T2>::type calc_t;
  68. geometry::formula::result_spherical<calc_t>
  69. result = geometry::formula::spherical_azimuth
  70. <
  71. calc_t,
  72. EnableReverseAzimuth
  73. >(calc_t(lon1_rad), calc_t(lat1_rad),
  74. calc_t(lon2_rad), calc_t(lat2_rad));
  75. if (EnableAzimuth)
  76. {
  77. a1 = result.azimuth;
  78. }
  79. if (EnableReverseAzimuth)
  80. {
  81. a2 = result.reverse_azimuth;
  82. }
  83. }
  84. };
  85. #ifndef DOXYGEN_NO_STRATEGY_SPECIALIZATIONS
  86. namespace services
  87. {
  88. template <>
  89. struct default_strategy<spherical_equatorial_tag>
  90. {
  91. typedef strategy::azimuth::spherical<> type;
  92. };
  93. }
  94. #endif // DOXYGEN_NO_STRATEGY_SPECIALIZATIONS
  95. }} // namespace strategy::azimuth
  96. }} // namespace boost::geometry
  97. #endif // BOOST_GEOMETRY_STRATEGIES_SPHERICAL_AZIMUTH_HPP