Mercurial > hg > vamp-build-and-test
comparison DEPENDENCIES/generic/include/boost/geometry/strategies/spherical/ssf.hpp @ 16:2665513ce2d3
Add boost headers
author | Chris Cannam |
---|---|
date | Tue, 05 Aug 2014 11:11:38 +0100 |
parents | |
children | c530137014c0 |
comparison
equal
deleted
inserted
replaced
15:663ca0da4350 | 16:2665513ce2d3 |
---|---|
1 // Boost.Geometry (aka GGL, Generic Geometry Library) | |
2 | |
3 // Copyright (c) 2011-2012 Barend Gehrels, Amsterdam, the Netherlands. | |
4 | |
5 // Use, modification and distribution is subject to the Boost Software License, | |
6 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at | |
7 // http://www.boost.org/LICENSE_1_0.txt) | |
8 | |
9 #ifndef BOOST_GEOMETRY_STRATEGIES_SPHERICAL_SSF_HPP | |
10 #define BOOST_GEOMETRY_STRATEGIES_SPHERICAL_SSF_HPP | |
11 | |
12 #include <boost/mpl/if.hpp> | |
13 #include <boost/type_traits.hpp> | |
14 | |
15 #include <boost/geometry/core/cs.hpp> | |
16 #include <boost/geometry/core/access.hpp> | |
17 #include <boost/geometry/core/radian_access.hpp> | |
18 | |
19 #include <boost/geometry/util/select_coordinate_type.hpp> | |
20 #include <boost/geometry/util/math.hpp> | |
21 | |
22 #include <boost/geometry/strategies/side.hpp> | |
23 //#include <boost/geometry/strategies/concepts/side_concept.hpp> | |
24 | |
25 | |
26 namespace boost { namespace geometry | |
27 { | |
28 | |
29 | |
30 namespace strategy { namespace side | |
31 { | |
32 | |
33 | |
34 /*! | |
35 \brief Check at which side of a Great Circle segment a point lies | |
36 left of segment (> 0), right of segment (< 0), on segment (0) | |
37 \ingroup strategies | |
38 \tparam CalculationType \tparam_calculation | |
39 */ | |
40 template <typename CalculationType = void> | |
41 class spherical_side_formula | |
42 { | |
43 | |
44 public : | |
45 template <typename P1, typename P2, typename P> | |
46 static inline int apply(P1 const& p1, P2 const& p2, P const& p) | |
47 { | |
48 typedef typename boost::mpl::if_c | |
49 < | |
50 boost::is_void<CalculationType>::type::value, | |
51 | |
52 // Select at least a double... | |
53 typename select_most_precise | |
54 < | |
55 typename select_most_precise | |
56 < | |
57 typename select_most_precise | |
58 < | |
59 typename coordinate_type<P1>::type, | |
60 typename coordinate_type<P2>::type | |
61 >::type, | |
62 typename coordinate_type<P>::type | |
63 >::type, | |
64 double | |
65 >::type, | |
66 CalculationType | |
67 >::type coordinate_type; | |
68 | |
69 // Convenient shortcuts | |
70 typedef coordinate_type ct; | |
71 ct const lambda1 = get_as_radian<0>(p1); | |
72 ct const delta1 = get_as_radian<1>(p1); | |
73 ct const lambda2 = get_as_radian<0>(p2); | |
74 ct const delta2 = get_as_radian<1>(p2); | |
75 ct const lambda = get_as_radian<0>(p); | |
76 ct const delta = get_as_radian<1>(p); | |
77 | |
78 // Create temporary points (vectors) on unit a sphere | |
79 ct const cos_delta1 = cos(delta1); | |
80 ct const c1x = cos_delta1 * cos(lambda1); | |
81 ct const c1y = cos_delta1 * sin(lambda1); | |
82 ct const c1z = sin(delta1); | |
83 | |
84 ct const cos_delta2 = cos(delta2); | |
85 ct const c2x = cos_delta2 * cos(lambda2); | |
86 ct const c2y = cos_delta2 * sin(lambda2); | |
87 ct const c2z = sin(delta2); | |
88 | |
89 // (Third point is converted directly) | |
90 ct const cos_delta = cos(delta); | |
91 | |
92 // Apply the "Spherical Side Formula" as presented on my blog | |
93 ct const dist | |
94 = (c1y * c2z - c1z * c2y) * cos_delta * cos(lambda) | |
95 + (c1z * c2x - c1x * c2z) * cos_delta * sin(lambda) | |
96 + (c1x * c2y - c1y * c2x) * sin(delta); | |
97 | |
98 ct zero = ct(); | |
99 return dist > zero ? 1 | |
100 : dist < zero ? -1 | |
101 : 0; | |
102 } | |
103 }; | |
104 | |
105 | |
106 #ifndef DOXYGEN_NO_STRATEGY_SPECIALIZATIONS | |
107 namespace services | |
108 { | |
109 | |
110 /*template <typename CalculationType> | |
111 struct default_strategy<spherical_polar_tag, CalculationType> | |
112 { | |
113 typedef spherical_side_formula<CalculationType> type; | |
114 };*/ | |
115 | |
116 template <typename CalculationType> | |
117 struct default_strategy<spherical_equatorial_tag, CalculationType> | |
118 { | |
119 typedef spherical_side_formula<CalculationType> type; | |
120 }; | |
121 | |
122 template <typename CalculationType> | |
123 struct default_strategy<geographic_tag, CalculationType> | |
124 { | |
125 typedef spherical_side_formula<CalculationType> type; | |
126 }; | |
127 | |
128 } | |
129 #endif | |
130 | |
131 }} // namespace strategy::side | |
132 | |
133 }} // namespace boost::geometry | |
134 | |
135 | |
136 #endif // BOOST_GEOMETRY_STRATEGIES_SPHERICAL_SSF_HPP |