Optimise R-tree queries in the case if there is no need to limit maximum number of results

This commit is contained in:
Siarhei Fedartsou 2024-05-12 12:05:08 +02:00
parent 36c074ca60
commit 8ac393623c
3 changed files with 14 additions and 27 deletions

View File

@ -36,6 +36,13 @@ inline double radToDeg(const double radian)
}
} // 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!
std::uint64_t squaredEuclideanDistance(const Coordinate lhs, const Coordinate rhs);

View File

@ -4,8 +4,8 @@
#include "coordinate.hpp"
#include "util/coordinate.hpp"
#include "util/coordinate_calculation.hpp"
#include <boost/assert.hpp>
#include <boost/math/constants/constants.hpp>
#include <limits>
#include <utility>
@ -170,19 +170,11 @@ struct RectangleInt2D
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)
{
constexpr static double kMetersPerDegreeLat = 110567.0f;
const double lat_offset = meters / kMetersPerDegreeLat;
const double lon_offset = meters / MetersPerLngDegree(coordinate.lat);
const double lat_offset = meters / coordinate_calculation::METERS_PER_DEGREE_LAT;
const double lon_offset =
meters / coordinate_calculation::metersPerLngDegree(coordinate.lat);
return RectangleInt2D{coordinate.lon - toFixed(FloatLongitude{lon_offset}),
coordinate.lon + toFixed(FloatLongitude{lon_offset}),

View File

@ -565,21 +565,9 @@ class StaticRTree
{ return num_results >= max_results; });
}
inline double GetSegmentDistance(const Coordinate input_coordinate,
const CandidateSegment &segment) const
{
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);
}
// NB 1: results are not guaranteed to be sorted by distance
// NB 2: maxDistanceMeters is not a hard limit, it's just a way to reduce the number of edges
// returned
template <typename FilterT>
std::vector<CandidateSegment> SearchInRange(const Coordinate input_coordinate,
double maxDistanceMeters,