num_interior_rings.hpp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. // Copyright (c) 2007-2014 Barend Gehrels, Amsterdam, the Netherlands.
  3. // Copyright (c) 2008-2014 Bruno Lalande, Paris, France.
  4. // Copyright (c) 2009-2014 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. // Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
  9. // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
  10. // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
  11. // Use, modification and distribution is subject to the Boost Software License,
  12. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  13. // http://www.boost.org/LICENSE_1_0.txt)
  14. #ifndef BOOST_GEOMETRY_ALGORITHMS_NUM_INTERIOR_RINGS_HPP
  15. #define BOOST_GEOMETRY_ALGORITHMS_NUM_INTERIOR_RINGS_HPP
  16. #include <cstddef>
  17. #include <boost/range.hpp>
  18. #include <boost/variant/apply_visitor.hpp>
  19. #include <boost/variant/static_visitor.hpp>
  20. #include <boost/variant/variant_fwd.hpp>
  21. #include <boost/geometry/core/tag.hpp>
  22. #include <boost/geometry/core/tags.hpp>
  23. #include <boost/geometry/core/interior_rings.hpp>
  24. #include <boost/geometry/algorithms/detail/counting.hpp>
  25. #include <boost/geometry/geometries/concepts/check.hpp>
  26. namespace boost { namespace geometry
  27. {
  28. #ifndef DOXYGEN_NO_DISPATCH
  29. namespace dispatch
  30. {
  31. template <typename Geometry, typename Tag = typename tag<Geometry>::type>
  32. struct num_interior_rings
  33. : detail::counting::other_count<0>
  34. {};
  35. template <typename Polygon>
  36. struct num_interior_rings<Polygon, polygon_tag>
  37. {
  38. static inline std::size_t apply(Polygon const& polygon)
  39. {
  40. return boost::size(geometry::interior_rings(polygon));
  41. }
  42. };
  43. template <typename MultiPolygon>
  44. struct num_interior_rings<MultiPolygon, multi_polygon_tag>
  45. : detail::counting::multi_count
  46. <
  47. num_interior_rings
  48. <
  49. typename boost::range_value<MultiPolygon const>::type
  50. >
  51. >
  52. {};
  53. } // namespace dispatch
  54. #endif // DOXYGEN_NO_DISPATCH
  55. namespace resolve_variant
  56. {
  57. template <typename Geometry>
  58. struct num_interior_rings
  59. {
  60. static inline std::size_t apply(Geometry const& geometry)
  61. {
  62. concepts::check<Geometry const>();
  63. return dispatch::num_interior_rings<Geometry>::apply(geometry);
  64. }
  65. };
  66. template <BOOST_VARIANT_ENUM_PARAMS(typename T)>
  67. struct num_interior_rings<boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)> >
  68. {
  69. struct visitor: boost::static_visitor<std::size_t>
  70. {
  71. template <typename Geometry>
  72. inline std::size_t operator()(Geometry const& geometry) const
  73. {
  74. return num_interior_rings<Geometry>::apply(geometry);
  75. }
  76. };
  77. static inline std::size_t
  78. apply(boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)> const& geometry)
  79. {
  80. return boost::apply_visitor(visitor(), geometry);
  81. }
  82. };
  83. } // namespace resolve_variant
  84. /*!
  85. \brief \brief_calc{number of interior rings}
  86. \ingroup num_interior_rings
  87. \details \details_calc{num_interior_rings, number of interior rings}.
  88. \tparam Geometry \tparam_geometry
  89. \param geometry \param_geometry
  90. \return \return_calc{number of interior rings}
  91. \qbk{[include reference/algorithms/num_interior_rings.qbk]}
  92. \note Defined by OGC as "numInteriorRing". To be consistent with "numPoints"
  93. letter "s" is appended
  94. */
  95. template <typename Geometry>
  96. inline std::size_t num_interior_rings(Geometry const& geometry)
  97. {
  98. return resolve_variant::num_interior_rings<Geometry>::apply(geometry);
  99. }
  100. }} // namespace boost::geometry
  101. #endif // BOOST_GEOMETRY_ALGORITHMS_NUM_INTERIOR_RINGS_HPP