Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:36:42

0001 // Boost.Geometry (aka GGL, Generic Geometry Library)
0002 
0003 // Copyright (c) 2016-2021 Oracle and/or its affiliates.
0004 // Contributed and/or modified by Vissarion Fisikopoulos, on behalf of Oracle
0005 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
0006 
0007 // Use, modification and distribution is subject to the Boost Software License,
0008 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
0009 // http://www.boost.org/LICENSE_1_0.txt)
0010 
0011 #ifndef BOOST_GEOMETRY_STRATEGIES_CARTESIAN_AZIMUTH_HPP
0012 #define BOOST_GEOMETRY_STRATEGIES_CARTESIAN_AZIMUTH_HPP
0013 
0014 #include <cmath>
0015 
0016 #include <boost/geometry/core/tags.hpp>
0017 #include <boost/geometry/core/coordinate_promotion.hpp>
0018 
0019 #include <boost/geometry/strategies/azimuth.hpp>
0020 
0021 #include <boost/geometry/util/select_most_precise.hpp>
0022 
0023 namespace boost { namespace geometry
0024 {
0025 
0026 namespace strategy { namespace azimuth
0027 {
0028 
0029 template <typename CalculationType = void>
0030 class cartesian
0031 {
0032 public:
0033     template <typename T1, typename T2>
0034     struct result_type
0035         : geometry::select_most_precise
0036               <
0037                   // NOTE: this promotes any integer type to double
0038                   typename geometry::promote_floating_point<T1, double>::type,
0039                   typename geometry::promote_floating_point<T2, double>::type,
0040                   CalculationType
0041               >
0042     {};
0043 
0044     template <typename T1, typename T2, typename Result>
0045     static inline void apply(T1 const& x1, T1 const& y1,
0046                              T2 const& x2, T2 const& y2,
0047                              Result& a1, Result& a2)
0048     {
0049         compute(x1, y1, x2, y2, a1, a2);
0050     }
0051     template <typename T1, typename T2, typename Result>
0052     static inline void apply(T1 const& x1, T1 const& y1,
0053                              T2 const& x2, T2 const& y2,
0054                              Result& a1)
0055     {
0056         compute(x1, y1, x2, y2, a1, a1);
0057     }
0058     template <typename T1, typename T2, typename Result>
0059     static inline void apply_reverse(T1 const& x1, T1 const& y1,
0060                                      T2 const& x2, T2 const& y2,
0061                                      Result& a2)
0062     {
0063         compute(x1, y1, x2, y2, a2, a2);
0064     }
0065 
0066 private:
0067     template <typename T1, typename T2, typename Result>
0068     static inline void compute(T1 const& x1, T1 const& y1,
0069                                T2 const& x2, T2 const& y2,
0070                                Result& a1, Result& a2)
0071     {
0072         typedef typename result_type<T1, T2>::type calc_t;
0073 
0074         // NOTE: azimuth 0 is at Y axis, increasing right
0075         // as in spherical/geographic where 0 is at North axis
0076         a1 = a2 = atan2(calc_t(x2) - calc_t(x1), calc_t(y2) - calc_t(y1));
0077     }
0078 };
0079 
0080 #ifndef DOXYGEN_NO_STRATEGY_SPECIALIZATIONS
0081 
0082 namespace services
0083 {
0084 
0085 template <>
0086 struct default_strategy<cartesian_tag>
0087 {
0088     typedef strategy::azimuth::cartesian<> type;
0089 };
0090 
0091 }
0092 
0093 #endif // DOXYGEN_NO_STRATEGY_SPECIALIZATIONS
0094 
0095 }} // namespace strategy::azimuth
0096 
0097 
0098 }} // namespace boost::geometry
0099 
0100 #endif // BOOST_GEOMETRY_STRATEGIES_CARTESIAN_AZIMUTH_HPP