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