radius.hpp 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  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.
  6. // Modifications copyright (c) 2014 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/type_traits/is_pointer.hpp>
  18. #include <boost/geometry/core/tag.hpp>
  19. #include <boost/geometry/core/tags.hpp>
  20. #include <boost/geometry/util/bare_type.hpp>
  21. namespace boost { namespace geometry
  22. {
  23. namespace traits
  24. {
  25. /*!
  26. \brief Traits class to get/set radius of a circle/sphere/(ellipse)
  27. \details the radius access meta-functions give read/write access to the radius of a circle or a sphere,
  28. or to the major/minor axis or an ellipse, or to one of the 3 equatorial radii of an ellipsoid.
  29. It should be specialized per geometry, in namespace core_dispatch. Those specializations should
  30. forward the call via traits to the geometry class, which could be specified by the user.
  31. There is a corresponding generic radius_get and radius_set function
  32. \par Geometries:
  33. - n-sphere (circle,sphere)
  34. - upcoming ellipse
  35. \par Specializations should provide:
  36. - inline static T get(Geometry const& geometry)
  37. - inline static void set(Geometry& geometry, T const& radius)
  38. \ingroup traits
  39. */
  40. template <typename Geometry, std::size_t Dimension>
  41. struct radius_access {};
  42. /*!
  43. \brief Traits class indicating the type (double,float,...) of the radius of a circle or a sphere
  44. \par Geometries:
  45. - n-sphere (circle,sphere)
  46. - upcoming ellipse
  47. \par Specializations should provide:
  48. - typedef T type (double,float,int,etc)
  49. \ingroup traits
  50. */
  51. template <typename Geometry>
  52. struct radius_type {};
  53. } // namespace traits
  54. #ifndef DOXYGEN_NO_DISPATCH
  55. namespace core_dispatch
  56. {
  57. template <typename Tag, typename Geometry>
  58. struct radius_type
  59. {
  60. //typedef core_dispatch_specialization_required type;
  61. };
  62. /*!
  63. \brief radius access meta-functions, used by concept n-sphere and upcoming ellipse.
  64. */
  65. template <typename Tag,
  66. typename Geometry,
  67. std::size_t Dimension,
  68. typename IsPointer>
  69. struct radius_access
  70. {
  71. //static inline CoordinateType get(Geometry const& ) {}
  72. //static inline void set(Geometry& g, CoordinateType const& value) {}
  73. };
  74. } // namespace core_dispatch
  75. #endif // DOXYGEN_NO_DISPATCH
  76. /*!
  77. \brief Metafunction to get the type of radius of a circle / sphere / ellipse / etc.
  78. \ingroup access
  79. \tparam Geometry the type of geometry
  80. */
  81. template <typename Geometry>
  82. struct radius_type
  83. {
  84. typedef typename core_dispatch::radius_type
  85. <
  86. typename tag<Geometry>::type,
  87. typename util::bare_type<Geometry>::type
  88. >::type type;
  89. };
  90. /*!
  91. \brief Function to get radius of a circle / sphere / ellipse / etc.
  92. \return radius The radius for a given axis
  93. \ingroup access
  94. \param geometry the geometry to get the radius from
  95. \tparam I index of the axis
  96. */
  97. template <std::size_t I, typename Geometry>
  98. inline typename radius_type<Geometry>::type get_radius(Geometry const& geometry)
  99. {
  100. return core_dispatch::radius_access
  101. <
  102. typename tag<Geometry>::type,
  103. typename util::bare_type<Geometry>::type,
  104. I,
  105. typename boost::is_pointer<Geometry>::type
  106. >::get(geometry);
  107. }
  108. /*!
  109. \brief Function to set the radius of a circle / sphere / ellipse / etc.
  110. \ingroup access
  111. \tparam I index of the axis
  112. \param geometry the geometry to change
  113. \param radius the radius to set
  114. */
  115. template <std::size_t I, typename Geometry>
  116. inline void set_radius(Geometry& geometry,
  117. typename radius_type<Geometry>::type const& radius)
  118. {
  119. core_dispatch::radius_access
  120. <
  121. typename tag<Geometry>::type,
  122. typename util::bare_type<Geometry>::type,
  123. I,
  124. typename boost::is_pointer<Geometry>::type
  125. >::set(geometry, radius);
  126. }
  127. #ifndef DOXYGEN_NO_DETAIL
  128. namespace detail
  129. {
  130. template <typename Tag, typename Geometry, std::size_t Dimension>
  131. struct radius_access
  132. {
  133. static inline typename radius_type<Geometry>::type get(Geometry const& geometry)
  134. {
  135. return traits::radius_access<Geometry, Dimension>::get(geometry);
  136. }
  137. static inline void set(Geometry& geometry,
  138. typename radius_type<Geometry>::type const& value)
  139. {
  140. traits::radius_access<Geometry, Dimension>::set(geometry, value);
  141. }
  142. };
  143. } // namespace detail
  144. #endif // DOXYGEN_NO_DETAIL
  145. #ifndef DOXYGEN_NO_DISPATCH
  146. namespace core_dispatch
  147. {
  148. template <typename Tag,
  149. typename Geometry,
  150. std::size_t Dimension>
  151. struct radius_access<Tag, Geometry, Dimension, boost::true_type>
  152. {
  153. typedef typename geometry::radius_type<Geometry>::type radius_type;
  154. static inline radius_type get(const Geometry * geometry)
  155. {
  156. return radius_access
  157. <
  158. Tag,
  159. Geometry,
  160. Dimension,
  161. typename boost::is_pointer<Geometry>::type
  162. >::get(*geometry);
  163. }
  164. static inline void set(Geometry * geometry, radius_type const& value)
  165. {
  166. return radius_access
  167. <
  168. Tag,
  169. Geometry,
  170. Dimension,
  171. typename boost::is_pointer<Geometry>::type
  172. >::set(*geometry, value);
  173. }
  174. };
  175. template <typename Geometry>
  176. struct radius_type<srs_sphere_tag, Geometry>
  177. {
  178. typedef typename traits::radius_type<Geometry>::type type;
  179. };
  180. template <typename Geometry, std::size_t Dimension>
  181. struct radius_access<srs_sphere_tag, Geometry, Dimension, boost::false_type>
  182. : detail::radius_access<srs_sphere_tag, Geometry, Dimension>
  183. {
  184. //BOOST_STATIC_ASSERT(Dimension == 0);
  185. BOOST_STATIC_ASSERT(Dimension < 3);
  186. };
  187. template <typename Geometry>
  188. struct radius_type<srs_spheroid_tag, Geometry>
  189. {
  190. typedef typename traits::radius_type<Geometry>::type type;
  191. };
  192. template <typename Geometry, std::size_t Dimension>
  193. struct radius_access<srs_spheroid_tag, Geometry, Dimension, boost::false_type>
  194. : detail::radius_access<srs_spheroid_tag, Geometry, Dimension>
  195. {
  196. //BOOST_STATIC_ASSERT(Dimension == 0 || Dimension == 2);
  197. BOOST_STATIC_ASSERT(Dimension < 3);
  198. };
  199. } // namespace core_dispatch
  200. #endif // DOXYGEN_NO_DISPATCH
  201. }} // namespace boost::geometry
  202. #endif // BOOST_GEOMETRY_CORE_RADIUS_HPP