1 // Boost.Geometry (aka GGL, Generic Geometry Library)
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.
7 // This file was modified by Oracle on 2014.
8 // Modifications copyright (c) 2014 Oracle and/or its affiliates.
10 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
12 // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
13 // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
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)
20 #ifndef BOOST_GEOMETRY_CORE_RADIUS_HPP
21 #define BOOST_GEOMETRY_CORE_RADIUS_HPP
26 #include <boost/static_assert.hpp>
27 #include <boost/type_traits/is_pointer.hpp>
29 #include <boost/geometry/core/tag.hpp>
30 #include <boost/geometry/core/tags.hpp>
31 #include <boost/geometry/util/bare_type.hpp>
34 namespace boost { namespace geometry
41 \brief Traits class to get/set radius of a circle/sphere/(ellipse)
42 \details the radius access meta-functions give read/write access to the radius of a circle or a sphere,
43 or to the major/minor axis or an ellipse, or to one of the 3 equatorial radii of an ellipsoid.
45 It should be specialized per geometry, in namespace core_dispatch. Those specializations should
46 forward the call via traits to the geometry class, which could be specified by the user.
48 There is a corresponding generic radius_get and radius_set function
50 - n-sphere (circle,sphere)
52 \par Specializations should provide:
53 - inline static T get(Geometry const& geometry)
54 - inline static void set(Geometry& geometry, T const& radius)
57 template <typename Geometry, std::size_t Dimension>
58 struct radius_access {};
62 \brief Traits class indicating the type (double,float,...) of the radius of a circle or a sphere
64 - n-sphere (circle,sphere)
66 \par Specializations should provide:
67 - typedef T type (double,float,int,etc)
70 template <typename Geometry>
71 struct radius_type {};
76 #ifndef DOXYGEN_NO_DISPATCH
77 namespace core_dispatch
80 template <typename Tag, typename Geometry>
83 //typedef core_dispatch_specialization_required type;
87 \brief radius access meta-functions, used by concept n-sphere and upcoming ellipse.
89 template <typename Tag,
91 std::size_t Dimension,
95 //static inline CoordinateType get(Geometry const& ) {}
96 //static inline void set(Geometry& g, CoordinateType const& value) {}
99 } // namespace core_dispatch
100 #endif // DOXYGEN_NO_DISPATCH
104 \brief Metafunction to get the type of radius of a circle / sphere / ellipse / etc.
106 \tparam Geometry the type of geometry
108 template <typename Geometry>
111 typedef typename core_dispatch::radius_type
113 typename tag<Geometry>::type,
114 typename util::bare_type<Geometry>::type
119 \brief Function to get radius of a circle / sphere / ellipse / etc.
120 \return radius The radius for a given axis
122 \param geometry the geometry to get the radius from
123 \tparam I index of the axis
125 template <std::size_t I, typename Geometry>
126 inline typename radius_type<Geometry>::type get_radius(Geometry const& geometry)
128 return core_dispatch::radius_access
130 typename tag<Geometry>::type,
131 typename util::bare_type<Geometry>::type,
133 typename boost::is_pointer<Geometry>::type
138 \brief Function to set the radius of a circle / sphere / ellipse / etc.
140 \tparam I index of the axis
141 \param geometry the geometry to change
142 \param radius the radius to set
144 template <std::size_t I, typename Geometry>
145 inline void set_radius(Geometry& geometry,
146 typename radius_type<Geometry>::type const& radius)
148 core_dispatch::radius_access
150 typename tag<Geometry>::type,
151 typename util::bare_type<Geometry>::type,
153 typename boost::is_pointer<Geometry>::type
154 >::set(geometry, radius);
159 #ifndef DOXYGEN_NO_DETAIL
163 template <typename Tag, typename Geometry, std::size_t Dimension>
166 static inline typename radius_type<Geometry>::type get(Geometry const& geometry)
168 return traits::radius_access<Geometry, Dimension>::get(geometry);
170 static inline void set(Geometry& geometry,
171 typename radius_type<Geometry>::type const& value)
173 traits::radius_access<Geometry, Dimension>::set(geometry, value);
177 } // namespace detail
178 #endif // DOXYGEN_NO_DETAIL
181 #ifndef DOXYGEN_NO_DISPATCH
182 namespace core_dispatch
185 template <typename Tag,
187 std::size_t Dimension>
188 struct radius_access<Tag, Geometry, Dimension, boost::true_type>
190 typedef typename geometry::radius_type<Geometry>::type radius_type;
192 static inline radius_type get(const Geometry * geometry)
199 typename boost::is_pointer<Geometry>::type
203 static inline void set(Geometry * geometry, radius_type const& value)
210 typename boost::is_pointer<Geometry>::type
211 >::set(*geometry, value);
216 template <typename Geometry>
217 struct radius_type<srs_sphere_tag, Geometry>
219 typedef typename traits::radius_type<Geometry>::type type;
222 template <typename Geometry, std::size_t Dimension>
223 struct radius_access<srs_sphere_tag, Geometry, Dimension, boost::false_type>
224 : detail::radius_access<srs_sphere_tag, Geometry, Dimension>
226 BOOST_STATIC_ASSERT(Dimension == 0);
227 //BOOST_STATIC_ASSERT(Dimension < 3);
230 template <typename Geometry>
231 struct radius_type<srs_spheroid_tag, Geometry>
233 typedef typename traits::radius_type<Geometry>::type type;
236 template <typename Geometry, std::size_t Dimension>
237 struct radius_access<srs_spheroid_tag, Geometry, Dimension, boost::false_type>
238 : detail::radius_access<srs_spheroid_tag, Geometry, Dimension>
240 BOOST_STATIC_ASSERT(Dimension == 0 || Dimension == 2);
241 //BOOST_STATIC_ASSERT(Dimension < 3);
244 } // namespace core_dispatch
245 #endif // DOXYGEN_NO_DISPATCH
248 }} // namespace boost::geometry
251 #endif // BOOST_GEOMETRY_CORE_RADIUS_HPP