radius.hpp 7.0 KB

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