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