calculate_sum.hpp 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. // Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
  3. // Copyright (c) 2008-2012 Bruno Lalande, Paris, France.
  4. // Copyright (c) 2009-2012 Mateusz Loskot, London, UK.
  5. // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
  6. // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
  7. // Use, modification and distribution is subject to the Boost Software License,
  8. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  9. // http://www.boost.org/LICENSE_1_0.txt)
  10. #ifndef BOOST_GEOMETRY_ALGORITHMS_DETAIL_CALCULATE_SUM_HPP
  11. #define BOOST_GEOMETRY_ALGORITHMS_DETAIL_CALCULATE_SUM_HPP
  12. #include <boost/range.hpp>
  13. #include <boost/typeof/typeof.hpp>
  14. namespace boost { namespace geometry
  15. {
  16. #ifndef DOXYGEN_NO_DETAIL
  17. namespace detail
  18. {
  19. class calculate_polygon_sum
  20. {
  21. template <typename ReturnType, typename Policy, typename Rings, typename Strategy>
  22. static inline ReturnType sum_interior_rings(Rings const& rings, Strategy const& strategy)
  23. {
  24. ReturnType sum = ReturnType();
  25. for (BOOST_AUTO_TPL(it, boost::begin(rings)); it != boost::end(rings); ++it)
  26. {
  27. sum += Policy::apply(*it, strategy);
  28. }
  29. return sum;
  30. }
  31. public :
  32. template <typename ReturnType, typename Policy, typename Polygon, typename Strategy>
  33. static inline ReturnType apply(Polygon const& poly, Strategy const& strategy)
  34. {
  35. return Policy::apply(exterior_ring(poly), strategy)
  36. + sum_interior_rings<ReturnType, Policy>(interior_rings(poly), strategy)
  37. ;
  38. }
  39. };
  40. } // namespace detail
  41. #endif // DOXYGEN_NO_DETAIL
  42. }} // namespace boost::geometry
  43. #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_CALCULATE_SUM_HPP