Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-18 08:43:05

0001 // Boost.Geometry (aka GGL, Generic Geometry Library)
0002 
0003 // Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
0004 // Copyright (c) 2008-2012 Bruno Lalande, Paris, France.
0005 // Copyright (c) 2009-2012 Mateusz Loskot, London, UK.
0006 // Copyright (c) 2024 Adam Wulkiewicz, Lodz, Poland.
0007 
0008 // This file was modified by Oracle on 2014-2020.
0009 // Modifications copyright (c) 2014-2020 Oracle and/or its affiliates.
0010 
0011 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
0012 
0013 // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
0014 // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
0015 
0016 // Use, modification and distribution is subject to the Boost Software License,
0017 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
0018 // http://www.boost.org/LICENSE_1_0.txt)
0019 
0020 
0021 #ifndef BOOST_GEOMETRY_CORE_RADIUS_HPP
0022 #define BOOST_GEOMETRY_CORE_RADIUS_HPP
0023 
0024 
0025 #include <cstddef>
0026 
0027 #include <boost/geometry/core/static_assert.hpp>
0028 #include <boost/geometry/core/tag.hpp>
0029 #include <boost/geometry/core/tags.hpp>
0030 #include <boost/geometry/util/type_traits_std.hpp>
0031 
0032 
0033 namespace boost { namespace geometry
0034 {
0035 
0036 namespace traits
0037 {
0038 
0039 /*!
0040     \brief Traits class to get/set radius of a circle/sphere/(ellipse)
0041     \details the radius access meta-functions give read/write access to the radius of a circle or a sphere,
0042     or to the major/minor axis or an ellipse, or to one of the 3 equatorial radii of an ellipsoid.
0043 
0044     It should be specialized per geometry, in namespace core_dispatch. Those specializations should
0045     forward the call via traits to the geometry class, which could be specified by the user.
0046 
0047     There is a corresponding generic radius_get and radius_set function
0048     \par Geometries:
0049         - n-sphere (circle,sphere)
0050         - upcoming ellipse
0051     \par Specializations should provide:
0052         - inline static T get(Geometry const& geometry)
0053         - inline static void set(Geometry& geometry, T const& radius)
0054     \ingroup traits
0055 */
0056 template <typename Geometry, std::size_t Dimension>
0057 struct radius_access {};
0058 
0059 
0060 /*!
0061     \brief Traits class indicating the type (double,float,...) of the radius of a circle or a sphere
0062     \par Geometries:
0063         - n-sphere (circle,sphere)
0064         - upcoming ellipse
0065     \par Specializations should provide:
0066         - typedef T type (double,float,int,etc)
0067     \ingroup traits
0068 */
0069 template <typename Geometry>
0070 struct radius_type {};
0071 
0072 } // namespace traits
0073 
0074 
0075 #ifndef DOXYGEN_NO_DISPATCH
0076 namespace core_dispatch
0077 {
0078 
0079 template <typename Tag, typename Geometry>
0080 struct radius_type
0081 {
0082     BOOST_GEOMETRY_STATIC_ASSERT_FALSE(
0083         "Not implemented for this Geometry Tag type.",
0084         Geometry, Tag);
0085     //typedef core_dispatch_specialization_required type;
0086 };
0087 
0088 /*!
0089     \brief radius access meta-functions, used by concept n-sphere and upcoming ellipse.
0090 */
0091 template
0092 <
0093     typename Tag,
0094     typename Geometry,
0095     std::size_t Dimension,
0096     bool IsPointer
0097 >
0098 struct radius_access
0099 {
0100     BOOST_GEOMETRY_STATIC_ASSERT_FALSE(
0101         "Not implemented for this Geometry Tag type.",
0102         Geometry, Tag);
0103     //static inline CoordinateType get(Geometry const& ) {}
0104     //static inline void set(Geometry& g, CoordinateType const& value) {}
0105 };
0106 
0107 } // namespace core_dispatch
0108 #endif // DOXYGEN_NO_DISPATCH
0109 
0110 
0111 /*!
0112     \brief Metafunction to get the type of radius of a circle / sphere / ellipse / etc.
0113     \ingroup access
0114     \tparam Geometry the type of geometry
0115 */
0116 template <typename Geometry>
0117 struct radius_type
0118 {
0119     using type = typename core_dispatch::radius_type
0120         <
0121             tag_t<Geometry>,
0122             util::remove_cptrref_t<Geometry>
0123         >::type;
0124 };
0125 
0126 
0127 template <typename Geometry>
0128 using radius_type_t = typename radius_type<Geometry>::type;
0129 
0130 
0131 /*!
0132     \brief Function to get radius of a circle / sphere / ellipse / etc.
0133     \return radius The radius for a given axis
0134     \ingroup access
0135     \param geometry the geometry to get the radius from
0136     \tparam I index of the axis
0137 */
0138 template <std::size_t I, typename Geometry>
0139 inline radius_type_t<Geometry> get_radius(Geometry const& geometry)
0140 {
0141     return core_dispatch::radius_access
0142         <
0143             tag_t<Geometry>,
0144             util::remove_cptrref_t<Geometry>,
0145             I,
0146             std::is_pointer<Geometry>::value
0147         >::get(geometry);
0148 }
0149 
0150 /*!
0151     \brief Function to set the radius of a circle / sphere / ellipse / etc.
0152     \ingroup access
0153     \tparam I index of the axis
0154     \param geometry the geometry to change
0155     \param radius the radius to set
0156 */
0157 template <std::size_t I, typename Geometry>
0158 inline void set_radius(Geometry& geometry,
0159                        radius_type_t<Geometry> const& radius)
0160 {
0161     core_dispatch::radius_access
0162         <
0163             tag_t<Geometry>,
0164             util::remove_cptrref_t<Geometry>,
0165             I,
0166             std::is_pointer<Geometry>::value
0167         >::set(geometry, radius);
0168 }
0169 
0170 
0171 
0172 #ifndef DOXYGEN_NO_DETAIL
0173 namespace detail
0174 {
0175 
0176 template <typename Tag, typename Geometry, std::size_t Dimension>
0177 struct radius_access
0178 {
0179     static inline radius_type_t<Geometry> get(Geometry const& geometry)
0180     {
0181         return traits::radius_access<Geometry, Dimension>::get(geometry);
0182     }
0183     static inline void set(Geometry& geometry,
0184                            radius_type_t<Geometry> const& value)
0185     {
0186         traits::radius_access<Geometry, Dimension>::set(geometry, value);
0187     }
0188 };
0189 
0190 } // namespace detail
0191 #endif // DOXYGEN_NO_DETAIL
0192 
0193 
0194 #ifndef DOXYGEN_NO_DISPATCH
0195 namespace core_dispatch
0196 {
0197 
0198 template
0199 <
0200     typename Tag,
0201     typename Geometry,
0202     std::size_t Dimension
0203 >
0204 struct radius_access<Tag, Geometry, Dimension, true>
0205 {
0206     static inline radius_type_t<Geometry> get(const Geometry * geometry)
0207     {
0208         return radius_access
0209             <
0210                 Tag,
0211                 Geometry,
0212                 Dimension,
0213                 std::is_pointer<Geometry>::value
0214             >::get(*geometry);
0215     }
0216 
0217     static inline void set(Geometry * geometry, radius_type_t<Geometry> const& value)
0218     {
0219         return radius_access
0220             <
0221                 Tag,
0222                 Geometry,
0223                 Dimension,
0224                 std::is_pointer<Geometry>::value
0225             >::set(*geometry, value);
0226     }
0227 };
0228 
0229 
0230 template <typename Geometry>
0231 struct radius_type<srs_sphere_tag, Geometry>
0232 {
0233     using type = typename traits::radius_type<Geometry>::type;
0234 };
0235 
0236 template <typename Geometry, std::size_t Dimension>
0237 struct radius_access<srs_sphere_tag, Geometry, Dimension, false>
0238     : detail::radius_access<srs_sphere_tag, Geometry, Dimension>
0239 {
0240     //BOOST_STATIC_ASSERT(Dimension == 0);
0241     BOOST_STATIC_ASSERT(Dimension < 3);
0242 };
0243 
0244 template <typename Geometry>
0245 struct radius_type<srs_spheroid_tag, Geometry>
0246 {
0247     using type = typename traits::radius_type<Geometry>::type;
0248 };
0249 
0250 template <typename Geometry, std::size_t Dimension>
0251 struct radius_access<srs_spheroid_tag, Geometry, Dimension, false>
0252     : detail::radius_access<srs_spheroid_tag, Geometry, Dimension>
0253 {
0254     //BOOST_STATIC_ASSERT(Dimension == 0 || Dimension == 2);
0255     BOOST_STATIC_ASSERT(Dimension < 3);
0256 };
0257 
0258 } // namespace core_dispatch
0259 #endif // DOXYGEN_NO_DISPATCH
0260 
0261 
0262 }} // namespace boost::geometry
0263 
0264 
0265 #endif // BOOST_GEOMETRY_CORE_RADIUS_HPP