azimuth.hpp 3.4 KB

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