content.hpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. // Boost.Geometry Index
  2. //
  3. // n-dimensional content (hypervolume) - 2d area, 3d volume, ...
  4. //
  5. // Copyright (c) 2011-2014 Adam Wulkiewicz, Lodz, Poland.
  6. //
  7. // This file was modified by Oracle on 2020-2023.
  8. // Modifications copyright (c) 2020-2023 Oracle and/or its affiliates.
  9. // Contributed and/or modified by Vissarion Fysikopoulos, on behalf of Oracle
  10. // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
  11. //
  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_INDEX_DETAIL_ALGORITHMS_CONTENT_HPP
  16. #define BOOST_GEOMETRY_INDEX_DETAIL_ALGORITHMS_CONTENT_HPP
  17. #include <boost/geometry/core/access.hpp>
  18. #include <boost/geometry/core/coordinate_dimension.hpp>
  19. #include <boost/geometry/core/coordinate_type.hpp>
  20. #include <boost/geometry/core/static_assert.hpp>
  21. #include <boost/geometry/core/tag.hpp>
  22. #include <boost/geometry/core/tags.hpp>
  23. #include <boost/geometry/util/select_most_precise.hpp>
  24. namespace boost { namespace geometry { namespace index { namespace detail {
  25. template <typename Indexable>
  26. struct default_content_result
  27. {
  28. using type = typename select_most_precise
  29. <
  30. typename coordinate_type<Indexable>::type,
  31. double
  32. >::type;
  33. };
  34. namespace dispatch {
  35. template <typename Box,
  36. std::size_t CurrentDimension = dimension<Box>::value>
  37. struct content_box
  38. {
  39. BOOST_STATIC_ASSERT(0 < CurrentDimension);
  40. static inline typename detail::default_content_result<Box>::type apply(Box const& b)
  41. {
  42. return content_box<Box, CurrentDimension - 1>::apply(b) *
  43. ( get<max_corner, CurrentDimension - 1>(b) - get<min_corner, CurrentDimension - 1>(b) );
  44. }
  45. };
  46. template <typename Box>
  47. struct content_box<Box, 1>
  48. {
  49. static inline typename detail::default_content_result<Box>::type apply(Box const& b)
  50. {
  51. return get<max_corner, 0>(b) - get<min_corner, 0>(b);
  52. }
  53. };
  54. template <typename Indexable, typename Tag>
  55. struct content
  56. {
  57. BOOST_GEOMETRY_STATIC_ASSERT_FALSE(
  58. "Not implemented for this Indexable and Tag.",
  59. Indexable, Tag);
  60. };
  61. template <typename Indexable>
  62. struct content<Indexable, point_tag>
  63. {
  64. static typename detail::default_content_result<Indexable>::type apply(Indexable const&)
  65. {
  66. return 0;
  67. }
  68. };
  69. template <typename Indexable>
  70. struct content<Indexable, box_tag>
  71. {
  72. static typename default_content_result<Indexable>::type apply(Indexable const& b)
  73. {
  74. return dispatch::content_box<Indexable>::apply(b);
  75. }
  76. };
  77. } // namespace dispatch
  78. template <typename Indexable>
  79. typename default_content_result<Indexable>::type content(Indexable const& b)
  80. {
  81. return dispatch::content
  82. <
  83. Indexable,
  84. typename tag<Indexable>::type
  85. >::apply(b);
  86. }
  87. }}}} // namespace boost::geometry::index::detail
  88. #endif // BOOST_GEOMETRY_INDEX_DETAIL_ALGORITHMS_CONTENT_HPP