]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/boost/geometry/strategies/spherical/ssf.hpp
import new upstream nautilus stable release 14.2.8
[ceph.git] / ceph / src / boost / boost / geometry / strategies / spherical / ssf.hpp
CommitLineData
7c673cae
FG
1// Boost.Geometry (aka GGL, Generic Geometry Library)
2
3// Copyright (c) 2011-2012 Barend Gehrels, Amsterdam, the Netherlands.
4
92f5a8d4
TL
5// This file was modified by Oracle on 2016, 2018, 2019.
6// Modifications copyright (c) 2016-2019, Oracle and/or its affiliates.
7c673cae
FG
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>
b32b8144 26#include <boost/geometry/strategies/spherical/disjoint_segment_box.hpp>
92f5a8d4 27#include <boost/geometry/strategies/spherical/envelope.hpp>
7c673cae 28//#include <boost/geometry/strategies/concepts/side_concept.hpp>
92f5a8d4 29#include <boost/geometry/strategies/spherical/point_in_point.hpp>
7c673cae
FG
30
31
32namespace boost { namespace geometry
33{
34
35
36namespace strategy { namespace side
37{
38
39#ifndef DOXYGEN_NO_DETAIL
40namespace detail
41{
42
43template <typename T>
44int spherical_side_formula(T const& lambda1, T const& delta1,
45 T const& lambda2, T const& delta2,
46 T const& lambda, T const& delta)
47{
48 // Create temporary points (vectors) on unit a sphere
49 T const cos_delta1 = cos(delta1);
50 T const c1x = cos_delta1 * cos(lambda1);
51 T const c1y = cos_delta1 * sin(lambda1);
52 T const c1z = sin(delta1);
53
54 T const cos_delta2 = cos(delta2);
55 T const c2x = cos_delta2 * cos(lambda2);
56 T const c2y = cos_delta2 * sin(lambda2);
57 T const c2z = sin(delta2);
58
59 // (Third point is converted directly)
60 T const cos_delta = cos(delta);
61
62 // Apply the "Spherical Side Formula" as presented on my blog
63 T const dist
64 = (c1y * c2z - c1z * c2y) * cos_delta * cos(lambda)
65 + (c1z * c2x - c1x * c2z) * cos_delta * sin(lambda)
66 + (c1x * c2y - c1y * c2x) * sin(delta);
67
68 T zero = T();
69 return math::equals(dist, zero) ? 0
70 : dist > zero ? 1
71 : -1; // dist < zero
72}
73
74}
75#endif // DOXYGEN_NO_DETAIL
76
77/*!
78\brief Check at which side of a Great Circle segment a point lies
79 left of segment (> 0), right of segment (< 0), on segment (0)
80\ingroup strategies
81\tparam CalculationType \tparam_calculation
82 */
83template <typename CalculationType = void>
84class spherical_side_formula
85{
86
87public :
92f5a8d4
TL
88 typedef spherical_tag cs_tag;
89
90 typedef strategy::envelope::spherical<CalculationType> envelope_strategy_type;
b32b8144
FG
91
92 static inline envelope_strategy_type get_envelope_strategy()
93 {
94 return envelope_strategy_type();
95 }
96
97 typedef strategy::disjoint::segment_box_spherical disjoint_strategy_type;
98
99 static inline disjoint_strategy_type get_disjoint_strategy()
100 {
101 return disjoint_strategy_type();
102 }
103
92f5a8d4
TL
104 typedef strategy::within::spherical_point_point equals_point_point_strategy_type;
105 static inline equals_point_point_strategy_type get_equals_point_point_strategy()
106 {
107 return equals_point_point_strategy_type();
108 }
109
7c673cae
FG
110 template <typename P1, typename P2, typename P>
111 static inline int apply(P1 const& p1, P2 const& p2, P const& p)
112 {
113 typedef typename promote_floating_point
114 <
115 typename select_calculation_type_alt
116 <
117 CalculationType,
118 P1, P2, P
119 >::type
120 >::type calculation_type;
121
122 calculation_type const lambda1 = get_as_radian<0>(p1);
123 calculation_type const delta1 = get_as_radian<1>(p1);
124 calculation_type const lambda2 = get_as_radian<0>(p2);
125 calculation_type const delta2 = get_as_radian<1>(p2);
126 calculation_type const lambda = get_as_radian<0>(p);
127 calculation_type const delta = get_as_radian<1>(p);
128
129 return detail::spherical_side_formula(lambda1, delta1,
130 lambda2, delta2,
131 lambda, delta);
132 }
133};
134
135
136#ifndef DOXYGEN_NO_STRATEGY_SPECIALIZATIONS
137namespace services
138{
139
140/*template <typename CalculationType>
141struct default_strategy<spherical_polar_tag, CalculationType>
142{
143 typedef spherical_side_formula<CalculationType> type;
144};*/
145
146template <typename CalculationType>
147struct default_strategy<spherical_equatorial_tag, CalculationType>
148{
149 typedef spherical_side_formula<CalculationType> type;
150};
151
152template <typename CalculationType>
153struct default_strategy<geographic_tag, CalculationType>
154{
155 typedef spherical_side_formula<CalculationType> type;
156};
157
158}
159#endif
160
161}} // namespace strategy::side
162
163}} // namespace boost::geometry
164
165
166#endif // BOOST_GEOMETRY_STRATEGIES_SPHERICAL_SSF_HPP