content.hpp 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. // 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_INDEX_DETAIL_ALGORITHMS_CONTENT_HPP
  11. #define BOOST_GEOMETRY_INDEX_DETAIL_ALGORITHMS_CONTENT_HPP
  12. namespace boost { namespace geometry { namespace index { namespace detail {
  13. template <typename Indexable>
  14. struct default_content_result
  15. {
  16. typedef typename select_most_precise<
  17. typename coordinate_type<Indexable>::type,
  18. long double
  19. >::type type;
  20. };
  21. namespace dispatch {
  22. template <typename Box,
  23. std::size_t CurrentDimension = dimension<Box>::value>
  24. struct content_box
  25. {
  26. BOOST_STATIC_ASSERT(0 < CurrentDimension);
  27. static inline typename detail::default_content_result<Box>::type apply(Box const& b)
  28. {
  29. return content_box<Box, CurrentDimension - 1>::apply(b) *
  30. ( get<max_corner, CurrentDimension - 1>(b) - get<min_corner, CurrentDimension - 1>(b) );
  31. }
  32. };
  33. template <typename Box>
  34. struct content_box<Box, 1>
  35. {
  36. static inline typename detail::default_content_result<Box>::type apply(Box const& b)
  37. {
  38. return get<max_corner, 0>(b) - get<min_corner, 0>(b);
  39. }
  40. };
  41. template <typename Indexable, typename Tag>
  42. struct content
  43. {
  44. BOOST_MPL_ASSERT_MSG(false, NOT_IMPLEMENTED_FOR_THIS_INDEXABLE_AND_TAG, (Indexable, Tag));
  45. };
  46. template <typename Indexable>
  47. struct content<Indexable, point_tag>
  48. {
  49. static typename detail::default_content_result<Indexable>::type apply(Indexable const&)
  50. {
  51. return 0;
  52. }
  53. };
  54. template <typename Indexable>
  55. struct content<Indexable, box_tag>
  56. {
  57. static typename default_content_result<Indexable>::type apply(Indexable const& b)
  58. {
  59. return dispatch::content_box<Indexable>::apply(b);
  60. }
  61. };
  62. } // namespace dispatch
  63. template <typename Indexable>
  64. typename default_content_result<Indexable>::type content(Indexable const& b)
  65. {
  66. return dispatch::content
  67. <
  68. Indexable,
  69. typename tag<Indexable>::type
  70. >::apply(b);
  71. }
  72. }}}} // namespace boost::geometry::index::detail
  73. #endif // BOOST_GEOMETRY_INDEX_DETAIL_ALGORITHMS_CONTENT_HPP