sum_for_indexable.hpp 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. // Boost.Geometry Index
  2. //
  3. // Sum values calculated for indexable's dimensions, used e.g. in R-tree k nearest neighbors query
  4. //
  5. // Copyright (c) 2011-2013 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_SUM_FOR_INDEXABLE_HPP
  11. #define BOOST_GEOMETRY_INDEX_DETAIL_ALGORITHMS_SUM_FOR_INDEXABLE_HPP
  12. namespace boost { namespace geometry { namespace index { namespace detail {
  13. template <
  14. typename Geometry,
  15. typename Indexable,
  16. typename IndexableTag,
  17. typename AlgoTag,
  18. size_t DimensionIndex>
  19. struct sum_for_indexable_dimension
  20. {
  21. BOOST_MPL_ASSERT_MSG(
  22. (false),
  23. NOT_IMPLEMENTED_FOR_THIS_INDEXABLE_TAG_TYPE,
  24. (sum_for_indexable_dimension));
  25. };
  26. template <
  27. typename Geometry,
  28. typename Indexable,
  29. typename IndexableTag,
  30. typename AlgoTag,
  31. size_t N>
  32. struct sum_for_indexable
  33. {
  34. typedef typename sum_for_indexable_dimension<
  35. Geometry, Indexable, IndexableTag, AlgoTag, N - 1
  36. >::result_type result_type;
  37. inline static result_type apply(Geometry const& g, Indexable const& i)
  38. {
  39. return
  40. sum_for_indexable<
  41. Geometry, Indexable, IndexableTag, AlgoTag, N - 1
  42. >::apply(g, i) +
  43. sum_for_indexable_dimension<
  44. Geometry, Indexable, IndexableTag, AlgoTag, N - 1
  45. >::apply(g, i);
  46. }
  47. };
  48. template <
  49. typename Geometry,
  50. typename Indexable,
  51. typename IndexableTag,
  52. typename AlgoTag>
  53. struct sum_for_indexable<Geometry, Indexable, IndexableTag, AlgoTag, 1>
  54. {
  55. typedef typename sum_for_indexable_dimension<
  56. Geometry, Indexable, IndexableTag, AlgoTag, 0
  57. >::result_type result_type;
  58. inline static result_type apply(Geometry const& g, Indexable const& i)
  59. {
  60. return
  61. sum_for_indexable_dimension<
  62. Geometry, Indexable, IndexableTag, AlgoTag, 0
  63. >::apply(g, i);
  64. }
  65. };
  66. }}}} // namespace boost::geometry::index::detail
  67. #endif // BOOST_GEOMETRY_INDEX_DETAIL_ALGORITHMS_SUM_FOR_INDEXABLE_HPP