mirror of
https://github.com/boostorg/geometry.git
synced 2026-02-13 12:32:09 +00:00
Fixed error in nearest_query() - for Iterator which is not an inserter - operator++ call added.
[SVN r82371]
This commit is contained in:
@@ -938,7 +938,7 @@ private:
|
||||
|
||||
detail::rtree::apply_visitor(nearest_v, *m_root);
|
||||
|
||||
return result.get(v);
|
||||
return result.finish();
|
||||
}
|
||||
|
||||
/*!
|
||||
@@ -958,10 +958,11 @@ private:
|
||||
typedef detail::rtree::visitors::nearest_query_result_k<
|
||||
value_type,
|
||||
translator_type,
|
||||
point_type
|
||||
point_type,
|
||||
OutIter
|
||||
> result_type;
|
||||
|
||||
result_type result(k);
|
||||
result_type result(k, out_it);
|
||||
|
||||
detail::rtree::visitors::nearest_query<
|
||||
value_type,
|
||||
@@ -976,7 +977,7 @@ private:
|
||||
|
||||
detail::rtree::apply_visitor(nearest_v, *m_root);
|
||||
|
||||
return result.get(out_it);
|
||||
return result.finish();
|
||||
}
|
||||
|
||||
translator_type m_translator;
|
||||
|
||||
@@ -33,7 +33,7 @@ public:
|
||||
typename translator::indexable_type<Translator>::type
|
||||
>::type distance_type;
|
||||
|
||||
inline nearest_query_result_one(Value const& value)
|
||||
inline nearest_query_result_one(Value & value)
|
||||
: m_value(value)
|
||||
, m_comp_dist((std::numeric_limits<distance_type>::max)())
|
||||
{}
|
||||
@@ -57,18 +57,17 @@ public:
|
||||
return m_comp_dist;
|
||||
}
|
||||
|
||||
inline size_t get(Value & v)
|
||||
inline size_t finish()
|
||||
{
|
||||
v = m_value;
|
||||
return is_comparable_distance_valid() ? 1 : 0;
|
||||
}
|
||||
|
||||
private:
|
||||
Value m_value;
|
||||
Value & m_value;
|
||||
distance_type m_comp_dist;
|
||||
};
|
||||
|
||||
template <typename Value, typename Translator, typename Point>
|
||||
template <typename Value, typename Translator, typename Point, typename OutIt>
|
||||
struct nearest_query_result_k
|
||||
{
|
||||
public:
|
||||
@@ -77,8 +76,8 @@ public:
|
||||
typename translator::indexable_type<Translator>::type
|
||||
>::type distance_type;
|
||||
|
||||
inline explicit nearest_query_result_k(size_t k)
|
||||
: m_count(k)
|
||||
inline explicit nearest_query_result_k(size_t k, OutIt out_it)
|
||||
: m_count(k), m_out_it(out_it)
|
||||
{
|
||||
BOOST_GEOMETRY_INDEX_ASSERT(0 < m_count, "Number of neighbors should be greater than 0");
|
||||
|
||||
@@ -122,12 +121,11 @@ public:
|
||||
: m_neighbors.front().first;
|
||||
}
|
||||
|
||||
template <typename OutIter>
|
||||
inline size_t get(OutIter & out_it)
|
||||
inline size_t finish()
|
||||
{
|
||||
typedef typename std::vector< std::pair<distance_type, Value> >::const_iterator neighbors_iterator;
|
||||
for ( neighbors_iterator it = m_neighbors.begin() ; it != m_neighbors.end() ; ++it )
|
||||
*out_it = it->second;
|
||||
for ( neighbors_iterator it = m_neighbors.begin() ; it != m_neighbors.end() ; ++it, ++m_out_it )
|
||||
*m_out_it = it->second;
|
||||
|
||||
return m_neighbors.size();
|
||||
}
|
||||
@@ -141,6 +139,8 @@ private:
|
||||
}
|
||||
|
||||
size_t m_count;
|
||||
OutIt m_out_it;
|
||||
|
||||
std::vector< std::pair<distance_type, Value> > m_neighbors;
|
||||
distance_type m_biggest_comp_dist;
|
||||
};
|
||||
|
||||
@@ -857,6 +857,12 @@ void test_nearest_query_k(Rtree const& rtree, std::vector<Value> const& input, P
|
||||
}
|
||||
|
||||
test_exactly_the_same_outputs(rtree, output, rtree | bgi::adaptors::nearest_queried(pt, k));
|
||||
|
||||
std::vector<Value> output2(k, generate_value_default<Value>::apply());
|
||||
size_t found_count = rtree.nearest_query(pt, k, output2.begin());
|
||||
output2.resize(found_count, generate_value_default<Value>::apply());
|
||||
|
||||
test_exactly_the_same_outputs(rtree, output, output2);
|
||||
}
|
||||
|
||||
// rtree nearest not found
|
||||
|
||||
@@ -94,6 +94,7 @@ int main()
|
||||
|
||||
std::vector<B> result;
|
||||
result.reserve(100);
|
||||
B result_one;
|
||||
|
||||
// query test
|
||||
{
|
||||
@@ -117,7 +118,7 @@ int main()
|
||||
|
||||
// searching test
|
||||
{
|
||||
std::cout << "nearest 5 searching time test... ("
|
||||
std::cout << "nearest 10 searching time test... ("
|
||||
<< queries_count / 10 << ")\n";
|
||||
tim.restart();
|
||||
size_t temp = 0;
|
||||
@@ -131,6 +132,21 @@ int main()
|
||||
std::cout << "time: " << tim.elapsed() << "s\n";
|
||||
std::cout << "found: " << temp << "\n";
|
||||
}
|
||||
|
||||
{
|
||||
std::cout << "nearest 1 searching time test... ("
|
||||
<< queries_count / 10 << ")\n";
|
||||
tim.restart();
|
||||
size_t temp = 0;
|
||||
for (size_t i = 0 ; i < queries_count / 10 ; ++i )
|
||||
{
|
||||
float x = coords[i].first + 100;
|
||||
float y = coords[i].second + 100;
|
||||
temp += t.nearest_query(P(x, y), result_one);
|
||||
}
|
||||
std::cout << "time: " << tim.elapsed() << "s\n";
|
||||
std::cout << "found: " << temp << "\n";
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
Reference in New Issue
Block a user