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-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. // 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/size.hpp>
  18. #include <boost/range/value_type.hpp>
  19. #include <boost/variant/apply_visitor.hpp>
  20. #include <boost/variant/static_visitor.hpp>
  21. #include <boost/variant/variant_fwd.hpp>
  22. #include <boost/geometry/core/tag.hpp>
  23. #include <boost/geometry/core/tags.hpp>
  24. #include <boost/geometry/core/interior_rings.hpp>
  25. #include <boost/geometry/algorithms/detail/counting.hpp>
  26. #include <boost/geometry/geometries/concepts/check.hpp>
  27. namespace boost { namespace geometry
  28. {
  29. #ifndef DOXYGEN_NO_DISPATCH
  30. namespace dispatch
  31. {
  32. template <typename Geometry, typename Tag = typename tag<Geometry>::type>
  33. struct num_interior_rings
  34. : detail::counting::other_count<0>
  35. {};
  36. template <typename Polygon>
  37. struct num_interior_rings<Polygon, polygon_tag>
  38. {
  39. static inline std::size_t apply(Polygon const& polygon)
  40. {
  41. return boost::size(geometry::interior_rings(polygon));
  42. }
  43. };
  44. template <typename MultiPolygon>
  45. struct num_interior_rings<MultiPolygon, multi_polygon_tag>
  46. : detail::counting::multi_count
  47. <
  48. num_interior_rings
  49. <
  50. typename boost::range_value<MultiPolygon const>::type
  51. >
  52. >
  53. {};
  54. } // namespace dispatch
  55. #endif // DOXYGEN_NO_DISPATCH
  56. namespace resolve_variant
  57. {
  58. template <typename Geometry>
  59. struct num_interior_rings
  60. {
  61. static inline std::size_t apply(Geometry const& geometry)
  62. {
  63. concepts::check<Geometry const>();
  64. return dispatch::num_interior_rings<Geometry>::apply(geometry);
  65. }
  66. };
  67. template <BOOST_VARIANT_ENUM_PARAMS(typename T)>
  68. struct num_interior_rings<boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)> >
  69. {
  70. struct visitor: boost::static_visitor<std::size_t>
  71. {
  72. template <typename Geometry>
  73. inline std::size_t operator()(Geometry const& geometry) const
  74. {
  75. return num_interior_rings<Geometry>::apply(geometry);
  76. }
  77. };
  78. static inline std::size_t
  79. apply(boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)> const& geometry)
  80. {
  81. return boost::apply_visitor(visitor(), geometry);
  82. }
  83. };
  84. } // namespace resolve_variant
  85. /*!
  86. \brief \brief_calc{number of interior rings}
  87. \ingroup num_interior_rings
  88. \details \details_calc{num_interior_rings, number of interior rings}.
  89. \tparam Geometry \tparam_geometry
  90. \param geometry \param_geometry
  91. \return \return_calc{number of interior rings}
  92. \qbk{[include reference/algorithms/num_interior_rings.qbk]}
  93. \note Defined by OGC as "numInteriorRing". To be consistent with "numPoints"
  94. letter "s" is appended
  95. */
  96. template <typename Geometry>
  97. inline std::size_t num_interior_rings(Geometry const& geometry)
  98. {
  99. return resolve_variant::num_interior_rings<Geometry>::apply(geometry);
  100. }
  101. }} // namespace boost::geometry
  102. #endif // BOOST_GEOMETRY_ALGORITHMS_NUM_INTERIOR_RINGS_HPP