]>
Commit | Line | Data |
---|---|---|
b32b8144 FG |
1 | // Boost.Geometry (aka GGL, Generic Geometry Library) |
2 | ||
1e59de90 | 3 | // Copyright (c) 2016-2021 Oracle and/or its affiliates. |
b32b8144 FG |
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_CARTESIAN_AZIMUTH_HPP | |
12 | #define BOOST_GEOMETRY_STRATEGIES_CARTESIAN_AZIMUTH_HPP | |
13 | ||
1e59de90 TL |
14 | #include <cmath> |
15 | ||
b32b8144 | 16 | #include <boost/geometry/core/tags.hpp> |
1e59de90 | 17 | #include <boost/geometry/core/coordinate_promotion.hpp> |
b32b8144 | 18 | |
92f5a8d4 TL |
19 | #include <boost/geometry/strategies/azimuth.hpp> |
20 | ||
1e59de90 TL |
21 | #include <boost/geometry/util/select_most_precise.hpp> |
22 | ||
b32b8144 FG |
23 | namespace boost { namespace geometry |
24 | { | |
25 | ||
26 | namespace strategy { namespace azimuth | |
27 | { | |
28 | ||
1e59de90 | 29 | template <typename CalculationType = void> |
b32b8144 | 30 | class cartesian |
1e59de90 TL |
31 | { |
32 | public: | |
33 | template <typename T1, typename T2> | |
34 | struct result_type | |
35 | : geometry::select_most_precise | |
36 | < | |
37 | // NOTE: this promotes any integer type to double | |
38 | typename geometry::promote_floating_point<T1, double>::type, | |
39 | typename geometry::promote_floating_point<T2, double>::type, | |
40 | CalculationType | |
41 | > | |
42 | {}; | |
43 | ||
44 | template <typename T1, typename T2, typename Result> | |
45 | static inline void apply(T1 const& x1, T1 const& y1, | |
46 | T2 const& x2, T2 const& y2, | |
47 | Result& a1, Result& a2) | |
48 | { | |
49 | compute(x1, y1, x2, y2, a1, a2); | |
50 | } | |
51 | template <typename T1, typename T2, typename Result> | |
52 | static inline void apply(T1 const& x1, T1 const& y1, | |
53 | T2 const& x2, T2 const& y2, | |
54 | Result& a1) | |
55 | { | |
56 | compute(x1, y1, x2, y2, a1, a1); | |
57 | } | |
58 | template <typename T1, typename T2, typename Result> | |
59 | static inline void apply_reverse(T1 const& x1, T1 const& y1, | |
60 | T2 const& x2, T2 const& y2, | |
61 | Result& a2) | |
62 | { | |
63 | compute(x1, y1, x2, y2, a2, a2); | |
64 | } | |
65 | ||
66 | private: | |
67 | template <typename T1, typename T2, typename Result> | |
68 | static inline void compute(T1 const& x1, T1 const& y1, | |
69 | T2 const& x2, T2 const& y2, | |
70 | Result& a1, Result& a2) | |
71 | { | |
72 | typedef typename result_type<T1, T2>::type calc_t; | |
73 | ||
74 | // NOTE: azimuth 0 is at Y axis, increasing right | |
75 | // as in spherical/geographic where 0 is at North axis | |
76 | a1 = a2 = atan2(calc_t(x2) - calc_t(x1), calc_t(y2) - calc_t(y1)); | |
77 | } | |
78 | }; | |
b32b8144 FG |
79 | |
80 | #ifndef DOXYGEN_NO_STRATEGY_SPECIALIZATIONS | |
81 | ||
82 | namespace services | |
83 | { | |
84 | ||
1e59de90 TL |
85 | template <> |
86 | struct default_strategy<cartesian_tag> | |
b32b8144 | 87 | { |
1e59de90 | 88 | typedef strategy::azimuth::cartesian<> type; |
b32b8144 FG |
89 | }; |
90 | ||
91 | } | |
92 | ||
93 | #endif // DOXYGEN_NO_STRATEGY_SPECIALIZATIONS | |
94 | ||
95 | }} // namespace strategy::azimuth | |
96 | ||
97 | ||
98 | }} // namespace boost::geometry | |
99 | ||
100 | #endif // BOOST_GEOMETRY_STRATEGIES_CARTESIAN_AZIMUTH_HPP |