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-2020.
8 // Modifications copyright (c) 2014-2020 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>
28 #include <boost/geometry/core/tag.hpp>
29 #include <boost/geometry/core/tags.hpp>
30 #include <boost/geometry/util/type_traits_std.hpp>
33 namespace boost { namespace geometry
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.
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.
47 There is a corresponding generic radius_get and radius_set function
49 - n-sphere (circle,sphere)
51 \par Specializations should provide:
52 - inline static T get(Geometry const& geometry)
53 - inline static void set(Geometry& geometry, T const& radius)
56 template <typename Geometry, std::size_t Dimension>
57 struct radius_access {};
61 \brief Traits class indicating the type (double,float,...) of the radius of a circle or a sphere
63 - n-sphere (circle,sphere)
65 \par Specializations should provide:
66 - typedef T type (double,float,int,etc)
69 template <typename Geometry>
70 struct radius_type {};
75 #ifndef DOXYGEN_NO_DISPATCH
76 namespace core_dispatch
79 template <typename Tag, typename Geometry>
82 //typedef core_dispatch_specialization_required type;
86 \brief radius access meta-functions, used by concept n-sphere and upcoming ellipse.
88 template <typename Tag,
90 std::size_t Dimension,
94 //static inline CoordinateType get(Geometry const& ) {}
95 //static inline void set(Geometry& g, CoordinateType const& value) {}
98 } // namespace core_dispatch
99 #endif // DOXYGEN_NO_DISPATCH
103 \brief Metafunction to get the type of radius of a circle / sphere / ellipse / etc.
105 \tparam Geometry the type of geometry
107 template <typename Geometry>
110 typedef typename core_dispatch::radius_type
112 typename tag<Geometry>::type,
113 typename util::remove_cptrref<Geometry>::type
118 \brief Function to get radius of a circle / sphere / ellipse / etc.
119 \return radius The radius for a given axis
121 \param geometry the geometry to get the radius from
122 \tparam I index of the axis
124 template <std::size_t I, typename Geometry>
125 inline typename radius_type<Geometry>::type get_radius(Geometry const& geometry)
127 return core_dispatch::radius_access
129 typename tag<Geometry>::type,
130 typename util::remove_cptrref<Geometry>::type,
132 typename std::is_pointer<Geometry>::type
137 \brief Function to set the radius of a circle / sphere / ellipse / etc.
139 \tparam I index of the axis
140 \param geometry the geometry to change
141 \param radius the radius to set
143 template <std::size_t I, typename Geometry>
144 inline void set_radius(Geometry& geometry,
145 typename radius_type<Geometry>::type const& radius)
147 core_dispatch::radius_access
149 typename tag<Geometry>::type,
150 typename util::remove_cptrref<Geometry>::type,
152 typename std::is_pointer<Geometry>::type
153 >::set(geometry, radius);
158 #ifndef DOXYGEN_NO_DETAIL
162 template <typename Tag, typename Geometry, std::size_t Dimension>
165 static inline typename radius_type<Geometry>::type get(Geometry const& geometry)
167 return traits::radius_access<Geometry, Dimension>::get(geometry);
169 static inline void set(Geometry& geometry,
170 typename radius_type<Geometry>::type const& value)
172 traits::radius_access<Geometry, Dimension>::set(geometry, value);
176 } // namespace detail
177 #endif // DOXYGEN_NO_DETAIL
180 #ifndef DOXYGEN_NO_DISPATCH
181 namespace core_dispatch
184 template <typename Tag,
186 std::size_t Dimension>
187 struct radius_access<Tag, Geometry, Dimension, std::true_type>
189 typedef typename geometry::radius_type<Geometry>::type radius_type;
191 static inline radius_type get(const Geometry * geometry)
198 typename std::is_pointer<Geometry>::type
202 static inline void set(Geometry * geometry, radius_type const& value)
209 typename std::is_pointer<Geometry>::type
210 >::set(*geometry, value);
215 template <typename Geometry>
216 struct radius_type<srs_sphere_tag, Geometry>
218 typedef typename traits::radius_type<Geometry>::type type;
221 template <typename Geometry, std::size_t Dimension>
222 struct radius_access<srs_sphere_tag, Geometry, Dimension, std::false_type>
223 : detail::radius_access<srs_sphere_tag, Geometry, Dimension>
225 //BOOST_STATIC_ASSERT(Dimension == 0);
226 BOOST_STATIC_ASSERT(Dimension < 3);
229 template <typename Geometry>
230 struct radius_type<srs_spheroid_tag, Geometry>
232 typedef typename traits::radius_type<Geometry>::type type;
235 template <typename Geometry, std::size_t Dimension>
236 struct radius_access<srs_spheroid_tag, Geometry, Dimension, std::false_type>
237 : detail::radius_access<srs_spheroid_tag, Geometry, Dimension>
239 //BOOST_STATIC_ASSERT(Dimension == 0 || Dimension == 2);
240 BOOST_STATIC_ASSERT(Dimension < 3);
243 } // namespace core_dispatch
244 #endif // DOXYGEN_NO_DISPATCH
247 }} // namespace boost::geometry
250 #endif // BOOST_GEOMETRY_CORE_RADIUS_HPP