counting.hpp 2.7 KB

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