smallest_for_indexable.hpp 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. // Boost.Geometry Index
  2. //
  3. // Get smallest value calculated for indexable's dimensions, used 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_SMALLEST_FOR_INDEXABLE_HPP
  11. #define BOOST_GEOMETRY_INDEX_DETAIL_ALGORITHMS_SMALLEST_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 smallest_for_indexable_dimension
  20. {
  21. BOOST_MPL_ASSERT_MSG(
  22. (false),
  23. NOT_IMPLEMENTED_FOR_THIS_INDEXABLE_TAG_TYPE,
  24. (smallest_for_indexable_dimension));
  25. };
  26. template <
  27. typename Geometry,
  28. typename Indexable,
  29. typename IndexableTag,
  30. typename AlgoTag,
  31. size_t N>
  32. struct smallest_for_indexable
  33. {
  34. typedef typename smallest_for_indexable_dimension<
  35. Geometry, Indexable, IndexableTag, AlgoTag, N - 1
  36. >::result_type result_type;
  37. template <typename Data>
  38. inline static result_type apply(Geometry const& g, Indexable const& i, Data const& data)
  39. {
  40. result_type r1 = smallest_for_indexable<
  41. Geometry, Indexable, IndexableTag, AlgoTag, N - 1
  42. >::apply(g, i, data);
  43. result_type r2 = smallest_for_indexable_dimension<
  44. Geometry, Indexable, IndexableTag, AlgoTag, N - 1
  45. >::apply(g, i, data);
  46. return r1 < r2 ? r1 : r2;
  47. }
  48. };
  49. template <
  50. typename Geometry,
  51. typename Indexable,
  52. typename IndexableTag,
  53. typename AlgoTag>
  54. struct smallest_for_indexable<Geometry, Indexable, IndexableTag, AlgoTag, 1>
  55. {
  56. typedef typename smallest_for_indexable_dimension<
  57. Geometry, Indexable, IndexableTag, AlgoTag, 0
  58. >::result_type result_type;
  59. template <typename Data>
  60. inline static result_type apply(Geometry const& g, Indexable const& i, Data const& data)
  61. {
  62. return
  63. smallest_for_indexable_dimension<
  64. Geometry, Indexable, IndexableTag, AlgoTag, 0
  65. >::apply(g, i, data);
  66. }
  67. };
  68. }}}} // namespace boost::geometry::index::detail
  69. #endif // BOOST_GEOMETRY_INDEX_DETAIL_ALGORITHMS_SMALLEST_FOR_INDEXABLE_HPP