Optimise R-tree queries in the case if there is no need to limit maximum number of results
This commit is contained in:
parent
36c074ca60
commit
8ac393623c
@ -36,6 +36,13 @@ inline double radToDeg(const double radian)
|
|||||||
}
|
}
|
||||||
} // namespace detail
|
} // namespace detail
|
||||||
|
|
||||||
|
const constexpr static double METERS_PER_DEGREE_LAT = 110567.0;
|
||||||
|
|
||||||
|
inline double metersPerLngDegree(const FixedLatitude lat)
|
||||||
|
{
|
||||||
|
return std::cos(detail::degToRad(static_cast<double>(toFloating(lat)))) * METERS_PER_DEGREE_LAT;
|
||||||
|
}
|
||||||
|
|
||||||
//! Takes the squared euclidean distance of the input coordinates. Does not return meters!
|
//! Takes the squared euclidean distance of the input coordinates. Does not return meters!
|
||||||
std::uint64_t squaredEuclideanDistance(const Coordinate lhs, const Coordinate rhs);
|
std::uint64_t squaredEuclideanDistance(const Coordinate lhs, const Coordinate rhs);
|
||||||
|
|
||||||
|
@ -4,8 +4,8 @@
|
|||||||
#include "coordinate.hpp"
|
#include "coordinate.hpp"
|
||||||
#include "util/coordinate.hpp"
|
#include "util/coordinate.hpp"
|
||||||
#include "util/coordinate_calculation.hpp"
|
#include "util/coordinate_calculation.hpp"
|
||||||
|
|
||||||
#include <boost/assert.hpp>
|
#include <boost/assert.hpp>
|
||||||
|
#include <boost/math/constants/constants.hpp>
|
||||||
|
|
||||||
#include <limits>
|
#include <limits>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
@ -170,19 +170,11 @@ struct RectangleInt2D
|
|||||||
max_lat != FixedLatitude{std::numeric_limits<std::int32_t>::min()};
|
max_lat != FixedLatitude{std::numeric_limits<std::int32_t>::min()};
|
||||||
}
|
}
|
||||||
|
|
||||||
static double MetersPerLngDegree(const FixedLatitude lat)
|
|
||||||
{
|
|
||||||
constexpr static double kMetersPerDegreeLat = 110567.0f;
|
|
||||||
|
|
||||||
constexpr float kRadPerDeg = (3.14 /* TODO */ / 180.0f);
|
|
||||||
|
|
||||||
return std::cos(kRadPerDeg * static_cast<double>(toFloating(lat))) * kMetersPerDegreeLat;
|
|
||||||
}
|
|
||||||
static RectangleInt2D ExpandMeters(const Coordinate &coordinate, const double meters)
|
static RectangleInt2D ExpandMeters(const Coordinate &coordinate, const double meters)
|
||||||
{
|
{
|
||||||
constexpr static double kMetersPerDegreeLat = 110567.0f;
|
const double lat_offset = meters / coordinate_calculation::METERS_PER_DEGREE_LAT;
|
||||||
const double lat_offset = meters / kMetersPerDegreeLat;
|
const double lon_offset =
|
||||||
const double lon_offset = meters / MetersPerLngDegree(coordinate.lat);
|
meters / coordinate_calculation::metersPerLngDegree(coordinate.lat);
|
||||||
|
|
||||||
return RectangleInt2D{coordinate.lon - toFixed(FloatLongitude{lon_offset}),
|
return RectangleInt2D{coordinate.lon - toFixed(FloatLongitude{lon_offset}),
|
||||||
coordinate.lon + toFixed(FloatLongitude{lon_offset}),
|
coordinate.lon + toFixed(FloatLongitude{lon_offset}),
|
||||||
|
@ -565,21 +565,9 @@ class StaticRTree
|
|||||||
{ return num_results >= max_results; });
|
{ return num_results >= max_results; });
|
||||||
}
|
}
|
||||||
|
|
||||||
inline double GetSegmentDistance(const Coordinate input_coordinate,
|
// NB 1: results are not guaranteed to be sorted by distance
|
||||||
const CandidateSegment &segment) const
|
// NB 2: maxDistanceMeters is not a hard limit, it's just a way to reduce the number of edges
|
||||||
{
|
// returned
|
||||||
BOOST_ASSERT(segment.data.forward_segment_id.id != SPECIAL_SEGMENTID ||
|
|
||||||
!segment.data.forward_segment_id.enabled);
|
|
||||||
BOOST_ASSERT(segment.data.reverse_segment_id.id != SPECIAL_SEGMENTID ||
|
|
||||||
!segment.data.reverse_segment_id.enabled);
|
|
||||||
|
|
||||||
Coordinate wsg84_coordinate =
|
|
||||||
util::web_mercator::toWGS84(segment.fixed_projected_coordinate);
|
|
||||||
|
|
||||||
return util::coordinate_calculation::greatCircleDistance(input_coordinate,
|
|
||||||
wsg84_coordinate);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename FilterT>
|
template <typename FilterT>
|
||||||
std::vector<CandidateSegment> SearchInRange(const Coordinate input_coordinate,
|
std::vector<CandidateSegment> SearchInRange(const Coordinate input_coordinate,
|
||||||
double maxDistanceMeters,
|
double maxDistanceMeters,
|
||||||
|
Loading…
Reference in New Issue
Block a user