calculate_sum.hpp 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. // Copyright (c) 2014 Adam Wulkiewicz, Lodz, Poland.
  6. // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
  7. // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
  8. // This file was modified by Oracle on 2016-2020.
  9. // Modifications copyright (c) 2016-2020 Oracle and/or its affiliates.
  10. // Contributed and/or modified by Vissarion Fysikopoulos, on behalf of Oracle
  11. // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
  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_CALCULATE_SUM_HPP
  16. #define BOOST_GEOMETRY_ALGORITHMS_DETAIL_CALCULATE_SUM_HPP
  17. #include <boost/range/begin.hpp>
  18. #include <boost/range/end.hpp>
  19. namespace boost { namespace geometry
  20. {
  21. #ifndef DOXYGEN_NO_DETAIL
  22. namespace detail
  23. {
  24. class calculate_polygon_sum
  25. {
  26. template <typename ReturnType, typename Policy, typename Rings, typename Strategy>
  27. static inline ReturnType sum_interior_rings(Rings const& rings, Strategy const& strategy)
  28. {
  29. ReturnType sum = ReturnType(0);
  30. for (auto it = boost::begin(rings); it != boost::end(rings); ++it)
  31. {
  32. sum += Policy::apply(*it, strategy);
  33. }
  34. return sum;
  35. }
  36. public :
  37. template <typename ReturnType, typename Policy, typename Polygon, typename Strategy>
  38. static inline ReturnType apply(Polygon const& poly, Strategy const& strategy)
  39. {
  40. return Policy::apply(exterior_ring(poly), strategy)
  41. + sum_interior_rings<ReturnType, Policy>(interior_rings(poly), strategy)
  42. ;
  43. }
  44. };
  45. } // namespace detail
  46. #endif // DOXYGEN_NO_DETAIL
  47. }} // namespace boost::geometry
  48. #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_CALCULATE_SUM_HPP