]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | // Boost.Geometry (aka GGL, Generic Geometry Library) |
2 | ||
3 | // Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands. | |
4 | // Copyright (c) 2008-2012 Bruno Lalande, Paris, France. | |
5 | // Copyright (c) 2009-2012 Mateusz Loskot, London, UK. | |
6 | ||
20effc67 TL |
7 | // This file was modified by Oracle on 2014-2020. |
8 | // Modifications copyright (c) 2014-2020 Oracle and/or its affiliates. | |
7c673cae FG |
9 | |
10 | // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle | |
11 | ||
12 | // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library | |
13 | // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands. | |
14 | ||
15 | // Use, modification and distribution is subject to the Boost Software License, | |
16 | // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at | |
17 | // http://www.boost.org/LICENSE_1_0.txt) | |
18 | ||
19 | ||
20 | #ifndef BOOST_GEOMETRY_CORE_RADIUS_HPP | |
21 | #define BOOST_GEOMETRY_CORE_RADIUS_HPP | |
22 | ||
23 | ||
24 | #include <cstddef> | |
25 | ||
26 | #include <boost/static_assert.hpp> | |
7c673cae FG |
27 | |
28 | #include <boost/geometry/core/tag.hpp> | |
29 | #include <boost/geometry/core/tags.hpp> | |
20effc67 | 30 | #include <boost/geometry/util/type_traits_std.hpp> |
7c673cae FG |
31 | |
32 | ||
33 | namespace boost { namespace geometry | |
34 | { | |
35 | ||
36 | namespace traits | |
37 | { | |
38 | ||
39 | /*! | |
40 | \brief Traits class to get/set radius of a circle/sphere/(ellipse) | |
41 | \details the radius access meta-functions give read/write access to the radius of a circle or a sphere, | |
42 | or to the major/minor axis or an ellipse, or to one of the 3 equatorial radii of an ellipsoid. | |
43 | ||
44 | It should be specialized per geometry, in namespace core_dispatch. Those specializations should | |
45 | forward the call via traits to the geometry class, which could be specified by the user. | |
46 | ||
47 | There is a corresponding generic radius_get and radius_set function | |
48 | \par Geometries: | |
49 | - n-sphere (circle,sphere) | |
50 | - upcoming ellipse | |
51 | \par Specializations should provide: | |
52 | - inline static T get(Geometry const& geometry) | |
53 | - inline static void set(Geometry& geometry, T const& radius) | |
54 | \ingroup traits | |
55 | */ | |
56 | template <typename Geometry, std::size_t Dimension> | |
57 | struct radius_access {}; | |
58 | ||
59 | ||
60 | /*! | |
61 | \brief Traits class indicating the type (double,float,...) of the radius of a circle or a sphere | |
62 | \par Geometries: | |
63 | - n-sphere (circle,sphere) | |
64 | - upcoming ellipse | |
65 | \par Specializations should provide: | |
66 | - typedef T type (double,float,int,etc) | |
67 | \ingroup traits | |
68 | */ | |
69 | template <typename Geometry> | |
70 | struct radius_type {}; | |
71 | ||
72 | } // namespace traits | |
73 | ||
74 | ||
75 | #ifndef DOXYGEN_NO_DISPATCH | |
76 | namespace core_dispatch | |
77 | { | |
78 | ||
79 | template <typename Tag, typename Geometry> | |
80 | struct radius_type | |
81 | { | |
82 | //typedef core_dispatch_specialization_required type; | |
83 | }; | |
84 | ||
85 | /*! | |
86 | \brief radius access meta-functions, used by concept n-sphere and upcoming ellipse. | |
87 | */ | |
88 | template <typename Tag, | |
89 | typename Geometry, | |
90 | std::size_t Dimension, | |
91 | typename IsPointer> | |
92 | struct radius_access | |
93 | { | |
94 | //static inline CoordinateType get(Geometry const& ) {} | |
95 | //static inline void set(Geometry& g, CoordinateType const& value) {} | |
96 | }; | |
97 | ||
98 | } // namespace core_dispatch | |
99 | #endif // DOXYGEN_NO_DISPATCH | |
100 | ||
101 | ||
102 | /*! | |
103 | \brief Metafunction to get the type of radius of a circle / sphere / ellipse / etc. | |
104 | \ingroup access | |
105 | \tparam Geometry the type of geometry | |
106 | */ | |
107 | template <typename Geometry> | |
108 | struct radius_type | |
109 | { | |
110 | typedef typename core_dispatch::radius_type | |
111 | < | |
112 | typename tag<Geometry>::type, | |
20effc67 | 113 | typename util::remove_cptrref<Geometry>::type |
7c673cae FG |
114 | >::type type; |
115 | }; | |
116 | ||
117 | /*! | |
118 | \brief Function to get radius of a circle / sphere / ellipse / etc. | |
119 | \return radius The radius for a given axis | |
120 | \ingroup access | |
121 | \param geometry the geometry to get the radius from | |
122 | \tparam I index of the axis | |
123 | */ | |
124 | template <std::size_t I, typename Geometry> | |
125 | inline typename radius_type<Geometry>::type get_radius(Geometry const& geometry) | |
126 | { | |
127 | return core_dispatch::radius_access | |
128 | < | |
129 | typename tag<Geometry>::type, | |
20effc67 | 130 | typename util::remove_cptrref<Geometry>::type, |
7c673cae | 131 | I, |
20effc67 | 132 | typename std::is_pointer<Geometry>::type |
7c673cae FG |
133 | >::get(geometry); |
134 | } | |
135 | ||
136 | /*! | |
137 | \brief Function to set the radius of a circle / sphere / ellipse / etc. | |
138 | \ingroup access | |
139 | \tparam I index of the axis | |
140 | \param geometry the geometry to change | |
141 | \param radius the radius to set | |
142 | */ | |
143 | template <std::size_t I, typename Geometry> | |
144 | inline void set_radius(Geometry& geometry, | |
145 | typename radius_type<Geometry>::type const& radius) | |
146 | { | |
147 | core_dispatch::radius_access | |
148 | < | |
149 | typename tag<Geometry>::type, | |
20effc67 | 150 | typename util::remove_cptrref<Geometry>::type, |
7c673cae | 151 | I, |
20effc67 | 152 | typename std::is_pointer<Geometry>::type |
7c673cae FG |
153 | >::set(geometry, radius); |
154 | } | |
155 | ||
156 | ||
157 | ||
158 | #ifndef DOXYGEN_NO_DETAIL | |
159 | namespace detail | |
160 | { | |
161 | ||
162 | template <typename Tag, typename Geometry, std::size_t Dimension> | |
163 | struct radius_access | |
164 | { | |
165 | static inline typename radius_type<Geometry>::type get(Geometry const& geometry) | |
166 | { | |
167 | return traits::radius_access<Geometry, Dimension>::get(geometry); | |
168 | } | |
169 | static inline void set(Geometry& geometry, | |
170 | typename radius_type<Geometry>::type const& value) | |
171 | { | |
172 | traits::radius_access<Geometry, Dimension>::set(geometry, value); | |
173 | } | |
174 | }; | |
175 | ||
176 | } // namespace detail | |
177 | #endif // DOXYGEN_NO_DETAIL | |
178 | ||
179 | ||
180 | #ifndef DOXYGEN_NO_DISPATCH | |
181 | namespace core_dispatch | |
182 | { | |
183 | ||
184 | template <typename Tag, | |
185 | typename Geometry, | |
186 | std::size_t Dimension> | |
20effc67 | 187 | struct radius_access<Tag, Geometry, Dimension, std::true_type> |
7c673cae FG |
188 | { |
189 | typedef typename geometry::radius_type<Geometry>::type radius_type; | |
190 | ||
191 | static inline radius_type get(const Geometry * geometry) | |
192 | { | |
193 | return radius_access | |
194 | < | |
195 | Tag, | |
196 | Geometry, | |
197 | Dimension, | |
20effc67 | 198 | typename std::is_pointer<Geometry>::type |
7c673cae FG |
199 | >::get(*geometry); |
200 | } | |
201 | ||
202 | static inline void set(Geometry * geometry, radius_type const& value) | |
203 | { | |
204 | return radius_access | |
205 | < | |
206 | Tag, | |
207 | Geometry, | |
208 | Dimension, | |
20effc67 | 209 | typename std::is_pointer<Geometry>::type |
7c673cae FG |
210 | >::set(*geometry, value); |
211 | } | |
212 | }; | |
213 | ||
214 | ||
215 | template <typename Geometry> | |
216 | struct radius_type<srs_sphere_tag, Geometry> | |
217 | { | |
218 | typedef typename traits::radius_type<Geometry>::type type; | |
219 | }; | |
220 | ||
221 | template <typename Geometry, std::size_t Dimension> | |
20effc67 | 222 | struct radius_access<srs_sphere_tag, Geometry, Dimension, std::false_type> |
7c673cae FG |
223 | : detail::radius_access<srs_sphere_tag, Geometry, Dimension> |
224 | { | |
11fdf7f2 TL |
225 | //BOOST_STATIC_ASSERT(Dimension == 0); |
226 | BOOST_STATIC_ASSERT(Dimension < 3); | |
7c673cae FG |
227 | }; |
228 | ||
229 | template <typename Geometry> | |
230 | struct radius_type<srs_spheroid_tag, Geometry> | |
231 | { | |
232 | typedef typename traits::radius_type<Geometry>::type type; | |
233 | }; | |
234 | ||
235 | template <typename Geometry, std::size_t Dimension> | |
20effc67 | 236 | struct radius_access<srs_spheroid_tag, Geometry, Dimension, std::false_type> |
7c673cae FG |
237 | : detail::radius_access<srs_spheroid_tag, Geometry, Dimension> |
238 | { | |
11fdf7f2 TL |
239 | //BOOST_STATIC_ASSERT(Dimension == 0 || Dimension == 2); |
240 | BOOST_STATIC_ASSERT(Dimension < 3); | |
7c673cae FG |
241 | }; |
242 | ||
243 | } // namespace core_dispatch | |
244 | #endif // DOXYGEN_NO_DISPATCH | |
245 | ||
246 | ||
247 | }} // namespace boost::geometry | |
248 | ||
249 | ||
250 | #endif // BOOST_GEOMETRY_CORE_RADIUS_HPP |