]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/geometry/include/boost/geometry/strategies/spherical/ssf.hpp
bump version to 12.2.2-pve1
[ceph.git] / ceph / src / boost / libs / geometry / include / boost / geometry / strategies / spherical / ssf.hpp
1 // Boost.Geometry (aka GGL, Generic Geometry Library)
2
3 // Copyright (c) 2011-2012 Barend Gehrels, Amsterdam, the Netherlands.
4
5 // This file was modified by Oracle on 2016.
6 // Modifications copyright (c) 2016, Oracle and/or its affiliates.
7 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
8
9 // Use, modification and distribution is subject to the Boost Software License,
10 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
11 // http://www.boost.org/LICENSE_1_0.txt)
12
13 #ifndef BOOST_GEOMETRY_STRATEGIES_SPHERICAL_SSF_HPP
14 #define BOOST_GEOMETRY_STRATEGIES_SPHERICAL_SSF_HPP
15
16
17 #include <boost/geometry/core/cs.hpp>
18 #include <boost/geometry/core/access.hpp>
19 #include <boost/geometry/core/radian_access.hpp>
20
21 #include <boost/geometry/util/math.hpp>
22 #include <boost/geometry/util/promote_floating_point.hpp>
23 #include <boost/geometry/util/select_calculation_type.hpp>
24
25 #include <boost/geometry/strategies/side.hpp>
26 //#include <boost/geometry/strategies/concepts/side_concept.hpp>
27
28
29 namespace boost { namespace geometry
30 {
31
32
33 namespace strategy { namespace side
34 {
35
36 #ifndef DOXYGEN_NO_DETAIL
37 namespace detail
38 {
39
40 template <typename T>
41 int spherical_side_formula(T const& lambda1, T const& delta1,
42 T const& lambda2, T const& delta2,
43 T const& lambda, T const& delta)
44 {
45 // Create temporary points (vectors) on unit a sphere
46 T const cos_delta1 = cos(delta1);
47 T const c1x = cos_delta1 * cos(lambda1);
48 T const c1y = cos_delta1 * sin(lambda1);
49 T const c1z = sin(delta1);
50
51 T const cos_delta2 = cos(delta2);
52 T const c2x = cos_delta2 * cos(lambda2);
53 T const c2y = cos_delta2 * sin(lambda2);
54 T const c2z = sin(delta2);
55
56 // (Third point is converted directly)
57 T const cos_delta = cos(delta);
58
59 // Apply the "Spherical Side Formula" as presented on my blog
60 T const dist
61 = (c1y * c2z - c1z * c2y) * cos_delta * cos(lambda)
62 + (c1z * c2x - c1x * c2z) * cos_delta * sin(lambda)
63 + (c1x * c2y - c1y * c2x) * sin(delta);
64
65 T zero = T();
66 return math::equals(dist, zero) ? 0
67 : dist > zero ? 1
68 : -1; // dist < zero
69 }
70
71 }
72 #endif // DOXYGEN_NO_DETAIL
73
74 /*!
75 \brief Check at which side of a Great Circle segment a point lies
76 left of segment (> 0), right of segment (< 0), on segment (0)
77 \ingroup strategies
78 \tparam CalculationType \tparam_calculation
79 */
80 template <typename CalculationType = void>
81 class spherical_side_formula
82 {
83
84 public :
85 template <typename P1, typename P2, typename P>
86 static inline int apply(P1 const& p1, P2 const& p2, P const& p)
87 {
88 typedef typename promote_floating_point
89 <
90 typename select_calculation_type_alt
91 <
92 CalculationType,
93 P1, P2, P
94 >::type
95 >::type calculation_type;
96
97 calculation_type const lambda1 = get_as_radian<0>(p1);
98 calculation_type const delta1 = get_as_radian<1>(p1);
99 calculation_type const lambda2 = get_as_radian<0>(p2);
100 calculation_type const delta2 = get_as_radian<1>(p2);
101 calculation_type const lambda = get_as_radian<0>(p);
102 calculation_type const delta = get_as_radian<1>(p);
103
104 return detail::spherical_side_formula(lambda1, delta1,
105 lambda2, delta2,
106 lambda, delta);
107 }
108 };
109
110
111 #ifndef DOXYGEN_NO_STRATEGY_SPECIALIZATIONS
112 namespace services
113 {
114
115 /*template <typename CalculationType>
116 struct default_strategy<spherical_polar_tag, CalculationType>
117 {
118 typedef spherical_side_formula<CalculationType> type;
119 };*/
120
121 template <typename CalculationType>
122 struct default_strategy<spherical_equatorial_tag, CalculationType>
123 {
124 typedef spherical_side_formula<CalculationType> type;
125 };
126
127 template <typename CalculationType>
128 struct default_strategy<geographic_tag, CalculationType>
129 {
130 typedef spherical_side_formula<CalculationType> type;
131 };
132
133 }
134 #endif
135
136 }} // namespace strategy::side
137
138 }} // namespace boost::geometry
139
140
141 #endif // BOOST_GEOMETRY_STRATEGIES_SPHERICAL_SSF_HPP