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 // This file was modified by Oracle on 2020.
8 // Modifications copyright (c) 2020 Oracle and/or its affiliates.
9 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
10 //
11 // Use, modification and distribution is subject to the Boost Software License,
12 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
13 // http://www.boost.org/LICENSE_1_0.txt)
14 
15 #ifndef BOOST_GEOMETRY_INDEX_DETAIL_ALGORITHMS_SMALLEST_FOR_INDEXABLE_HPP
16 #define BOOST_GEOMETRY_INDEX_DETAIL_ALGORITHMS_SMALLEST_FOR_INDEXABLE_HPP
17 
18 #include <boost/geometry/core/static_assert.hpp>
19 
20 namespace boost { namespace geometry { namespace index { namespace detail {
21 
22 template <
23     typename Geometry,
24     typename Indexable,
25     typename IndexableTag,
26     typename AlgoTag,
27     size_t DimensionIndex>
28 struct smallest_for_indexable_dimension
29 {
30     BOOST_GEOMETRY_STATIC_ASSERT_FALSE(
31         "Not implemented for this Indexable type.",
32         Geometry, Indexable, IndexableTag, AlgoTag);
33 };
34 
35 template <
36     typename Geometry,
37     typename Indexable,
38     typename IndexableTag,
39     typename AlgoTag,
40     size_t N>
41 struct smallest_for_indexable
42 {
43     typedef typename smallest_for_indexable_dimension<
44         Geometry, Indexable, IndexableTag, AlgoTag, N - 1
45     >::result_type result_type;
46 
47     template <typename Data>
applyboost::geometry::index::detail::smallest_for_indexable48     inline static result_type apply(Geometry const& g, Indexable const& i, Data const& data)
49     {
50         result_type r1 = smallest_for_indexable<
51             Geometry, Indexable, IndexableTag, AlgoTag, N - 1
52         >::apply(g, i, data);
53 
54         result_type r2 = smallest_for_indexable_dimension<
55             Geometry, Indexable, IndexableTag, AlgoTag, N - 1
56         >::apply(g, i, data);
57 
58         return r1 < r2 ? r1 : r2;
59     }
60 };
61 
62 template <
63     typename Geometry,
64     typename Indexable,
65     typename IndexableTag,
66     typename AlgoTag>
67 struct smallest_for_indexable<Geometry, Indexable, IndexableTag, AlgoTag, 1>
68 {
69     typedef typename smallest_for_indexable_dimension<
70         Geometry, Indexable, IndexableTag, AlgoTag, 0
71     >::result_type result_type;
72 
73     template <typename Data>
applyboost::geometry::index::detail::smallest_for_indexable74     inline static result_type apply(Geometry const& g, Indexable const& i, Data const& data)
75     {
76         return
77             smallest_for_indexable_dimension<
78                 Geometry, Indexable, IndexableTag, AlgoTag, 0
79             >::apply(g, i, data);
80     }
81 };
82 
83 }}}} // namespace boost::geometry::index::detail
84 
85 #endif // BOOST_GEOMETRY_INDEX_DETAIL_ALGORITHMS_SMALLEST_FOR_INDEXABLE_HPP
86