Switch to uint64 for distance measurements in StaticRTree

This commit is contained in:
Patrick Niklaus 2016-04-09 01:24:58 +02:00
parent c51ffeb65a
commit 67834def5f
2 changed files with 9 additions and 9 deletions

View File

@ -83,7 +83,7 @@ struct RectangleInt2D
// This code assumes that we are operating in euclidean space! // This code assumes that we are operating in euclidean space!
// That means if you just put unprojected lat/lon in here you will // That means if you just put unprojected lat/lon in here you will
// get invalid results. // get invalid results.
double GetMinSquaredDist(const Coordinate location) const std::uint64_t GetMinSquaredDist(const Coordinate location) const
{ {
const bool is_contained = Contains(location); const bool is_contained = Contains(location);
if (is_contained) if (is_contained)
@ -116,7 +116,7 @@ struct RectangleInt2D
BOOST_ASSERT(d != INVALID); BOOST_ASSERT(d != INVALID);
double min_dist = std::numeric_limits<double>::max(); std::uint64_t min_dist = std::numeric_limits<std::uint64_t>::max();
switch (d) switch (d)
{ {
case NORTH: case NORTH:
@ -155,7 +155,7 @@ struct RectangleInt2D
break; break;
} }
BOOST_ASSERT(min_dist < std::numeric_limits<double>::max()); BOOST_ASSERT(min_dist < std::numeric_limits<std::uint64_t>::max());
return min_dist; return min_dist;
} }

View File

@ -101,7 +101,7 @@ class StaticRTree
return other.squared_min_dist < squared_min_dist; return other.squared_min_dist < squared_min_dist;
} }
double squared_min_dist; std::uint64_t squared_min_dist;
QueryNodeType node; QueryNodeType node;
}; };
@ -408,7 +408,7 @@ class StaticRTree
// initialize queue with root element // initialize queue with root element
std::priority_queue<QueryCandidate> traversal_queue; std::priority_queue<QueryCandidate> traversal_queue;
traversal_queue.push(QueryCandidate{0.f, m_search_tree[0]}); traversal_queue.push(QueryCandidate{0, m_search_tree[0]});
while (!traversal_queue.empty()) while (!traversal_queue.empty())
{ {
@ -421,8 +421,8 @@ class StaticRTree
current_query_node.node.template get<TreeNode>(); current_query_node.node.template get<TreeNode>();
if (current_tree_node.child_is_on_disk) if (current_tree_node.child_is_on_disk)
{ {
ExploreLeafNode(current_tree_node.children[0], projected_coordinate, ExploreLeafNode(current_tree_node.children[0], fixed_projected_coordinate,
traversal_queue); projected_coordinate, traversal_queue);
} }
else else
{ {
@ -459,6 +459,7 @@ class StaticRTree
private: private:
template <typename QueueT> template <typename QueueT>
void ExploreLeafNode(const std::uint32_t leaf_id, void ExploreLeafNode(const std::uint32_t leaf_id,
const Coordinate projected_input_coordinate_fixed,
const FloatCoordinate &projected_input_coordinate, const FloatCoordinate &projected_input_coordinate,
QueueT &traversal_queue) QueueT &traversal_queue)
{ {
@ -480,8 +481,7 @@ class StaticRTree
projected_input_coordinate); projected_input_coordinate);
const auto squared_distance = coordinate_calculation::squaredEuclideanDistance( const auto squared_distance = coordinate_calculation::squaredEuclideanDistance(
projected_nearest, projected_input_coordinate); projected_input_coordinate_fixed, projected_nearest);
// distance must be non-negative // distance must be non-negative
BOOST_ASSERT(0. <= squared_distance); BOOST_ASSERT(0. <= squared_distance);
traversal_queue.push( traversal_queue.push(