File indexing completed on 2025-01-18 09:36:49
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013 #ifndef BOOST_GEOMETRY_STRATEGIES_SPHERICAL_SSF_HPP
0014 #define BOOST_GEOMETRY_STRATEGIES_SPHERICAL_SSF_HPP
0015
0016
0017 #include <boost/geometry/core/cs.hpp>
0018 #include <boost/geometry/core/access.hpp>
0019 #include <boost/geometry/core/coordinate_promotion.hpp>
0020 #include <boost/geometry/core/radian_access.hpp>
0021
0022 #include <boost/geometry/util/math.hpp>
0023 #include <boost/geometry/util/select_calculation_type.hpp>
0024
0025 #include <boost/geometry/strategy/spherical/envelope.hpp>
0026
0027 #include <boost/geometry/strategies/side.hpp>
0028 #include <boost/geometry/strategies/spherical/disjoint_segment_box.hpp>
0029
0030 #include <boost/geometry/strategies/spherical/point_in_point.hpp>
0031
0032
0033 namespace boost { namespace geometry
0034 {
0035
0036
0037 namespace strategy { namespace side
0038 {
0039
0040 #ifndef DOXYGEN_NO_DETAIL
0041 namespace detail
0042 {
0043
0044 template <typename T>
0045 int spherical_side_formula(T const& lambda1, T const& delta1,
0046 T const& lambda2, T const& delta2,
0047 T const& lambda, T const& delta)
0048 {
0049
0050 T const cos_delta1 = cos(delta1);
0051 T const c1x = cos_delta1 * cos(lambda1);
0052 T const c1y = cos_delta1 * sin(lambda1);
0053 T const c1z = sin(delta1);
0054
0055 T const cos_delta2 = cos(delta2);
0056 T const c2x = cos_delta2 * cos(lambda2);
0057 T const c2y = cos_delta2 * sin(lambda2);
0058 T const c2z = sin(delta2);
0059
0060
0061 T const cos_delta = cos(delta);
0062
0063
0064 T const dist
0065 = (c1y * c2z - c1z * c2y) * cos_delta * cos(lambda)
0066 + (c1z * c2x - c1x * c2z) * cos_delta * sin(lambda)
0067 + (c1x * c2y - c1y * c2x) * sin(delta);
0068
0069 T zero = T();
0070 return math::equals(dist, zero) ? 0
0071 : dist > zero ? 1
0072 : -1;
0073 }
0074
0075 }
0076 #endif
0077
0078
0079
0080
0081
0082
0083
0084 template <typename CalculationType = void>
0085 class spherical_side_formula
0086 {
0087
0088 public :
0089 typedef spherical_tag cs_tag;
0090
0091 template <typename P1, typename P2, typename P>
0092 static inline int apply(P1 const& p1, P2 const& p2, P const& p)
0093 {
0094 typedef typename promote_floating_point
0095 <
0096 typename select_calculation_type_alt
0097 <
0098 CalculationType,
0099 P1, P2, P
0100 >::type
0101 >::type calculation_type;
0102
0103 calculation_type const lambda1 = get_as_radian<0>(p1);
0104 calculation_type const delta1 = get_as_radian<1>(p1);
0105 calculation_type const lambda2 = get_as_radian<0>(p2);
0106 calculation_type const delta2 = get_as_radian<1>(p2);
0107 calculation_type const lambda = get_as_radian<0>(p);
0108 calculation_type const delta = get_as_radian<1>(p);
0109
0110 return detail::spherical_side_formula(lambda1, delta1,
0111 lambda2, delta2,
0112 lambda, delta);
0113 }
0114 };
0115
0116
0117 #ifndef DOXYGEN_NO_STRATEGY_SPECIALIZATIONS
0118 namespace services
0119 {
0120
0121
0122
0123
0124
0125
0126
0127 template <typename CalculationType>
0128 struct default_strategy<spherical_equatorial_tag, CalculationType>
0129 {
0130 typedef spherical_side_formula<CalculationType> type;
0131 };
0132
0133 template <typename CalculationType>
0134 struct default_strategy<geographic_tag, CalculationType>
0135 {
0136 typedef spherical_side_formula<CalculationType> type;
0137 };
0138
0139 }
0140 #endif
0141
0142 }}
0143
0144 }}
0145
0146
0147 #endif