counting.hpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. // Copyright (c) 2014 Adam Wulkiewicz, Lodz, Poland.
  6. // This file was modified by Oracle on 2014-2020.
  7. // Modifications copyright (c) 2014-2020, Oracle and/or its affiliates.
  8. // Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
  9. // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
  10. // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
  11. // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
  12. // Use, modification and distribution is subject to the Boost Software License,
  13. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  14. // http://www.boost.org/LICENSE_1_0.txt)
  15. #ifndef BOOST_GEOMETRY_ALGORITHMS_DETAIL_COUNTING_HPP
  16. #define BOOST_GEOMETRY_ALGORITHMS_DETAIL_COUNTING_HPP
  17. #include <cstddef>
  18. #include <boost/range/begin.hpp>
  19. #include <boost/range/end.hpp>
  20. #include <boost/geometry/core/exterior_ring.hpp>
  21. #include <boost/geometry/core/interior_rings.hpp>
  22. #include <boost/geometry/util/range.hpp>
  23. namespace boost { namespace geometry
  24. {
  25. #ifndef DOXYGEN_NO_DETAIL
  26. namespace detail { namespace counting
  27. {
  28. template <std::size_t D>
  29. struct other_count
  30. {
  31. template <typename Geometry>
  32. static inline std::size_t apply(Geometry const&)
  33. {
  34. return D;
  35. }
  36. template <typename Geometry>
  37. static inline std::size_t apply(Geometry const&, bool)
  38. {
  39. return D;
  40. }
  41. };
  42. template <typename RangeCount>
  43. struct polygon_count
  44. {
  45. template <typename Polygon>
  46. static inline std::size_t apply(Polygon const& poly)
  47. {
  48. std::size_t n = RangeCount::apply(exterior_ring(poly));
  49. auto const& rings = interior_rings(poly);
  50. for (auto it = boost::begin(rings); it != boost::end(rings); ++it)
  51. {
  52. n += RangeCount::apply(*it);
  53. }
  54. return n;
  55. }
  56. };
  57. template <typename SingleCount>
  58. struct multi_count
  59. {
  60. template <typename MultiGeometry>
  61. static inline std::size_t apply(MultiGeometry const& multi)
  62. {
  63. std::size_t n = 0;
  64. for (auto it = boost::begin(multi); it != boost::end(multi); ++it)
  65. {
  66. n += SingleCount::apply(*it);
  67. }
  68. return n;
  69. }
  70. };
  71. }} // namespace detail::counting
  72. #endif // DOXYGEN_NO_DETAIL
  73. }} // namespace boost::geometry
  74. #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_COUNTING_HPP