counting.hpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. #include <boost/geometry/algorithms/detail/interior_iterator.hpp>
  24. namespace boost { namespace geometry
  25. {
  26. #ifndef DOXYGEN_NO_DETAIL
  27. namespace detail { namespace counting
  28. {
  29. template <std::size_t D>
  30. struct other_count
  31. {
  32. template <typename Geometry>
  33. static inline std::size_t apply(Geometry const&)
  34. {
  35. return D;
  36. }
  37. template <typename Geometry>
  38. static inline std::size_t apply(Geometry const&, bool)
  39. {
  40. return D;
  41. }
  42. };
  43. template <typename RangeCount>
  44. struct polygon_count
  45. {
  46. template <typename Polygon>
  47. static inline std::size_t apply(Polygon const& poly)
  48. {
  49. std::size_t n = RangeCount::apply(exterior_ring(poly));
  50. typename interior_return_type<Polygon const>::type
  51. rings = interior_rings(poly);
  52. for (typename detail::interior_iterator<Polygon const>::type
  53. it = boost::begin(rings); it != boost::end(rings); ++it)
  54. {
  55. n += RangeCount::apply(*it);
  56. }
  57. return n;
  58. }
  59. };
  60. template <typename SingleCount>
  61. struct multi_count
  62. {
  63. template <typename MultiGeometry>
  64. static inline std::size_t apply(MultiGeometry const& geometry)
  65. {
  66. std::size_t n = 0;
  67. for (typename boost::range_iterator<MultiGeometry const>::type
  68. it = boost::begin(geometry);
  69. it != boost::end(geometry);
  70. ++it)
  71. {
  72. n += SingleCount::apply(*it);
  73. }
  74. return n;
  75. }
  76. };
  77. }} // namespace detail::counting
  78. #endif // DOXYGEN_NO_DETAIL
  79. }} // namespace boost::geometry
  80. #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_COUNTING_HPP