|
1 | 1 | #ifndef GEOSPATIAL_QUERY_HPP |
2 | 2 | #define GEOSPATIAL_QUERY_HPP |
3 | 3 |
|
| 4 | +#include "extractor/intersection/constants.hpp" |
4 | 5 | #include "engine/approach.hpp" |
5 | 6 | #include "engine/bearing.hpp" |
6 | 7 | #include "engine/phantom_node.hpp" |
@@ -57,12 +58,12 @@ template <typename RTreeT, typename DataFacadeT> class GeospatialQuery |
57 | 58 | { |
58 | 59 | auto results = rtree.SearchInRange( |
59 | 60 | input_coordinate, |
60 | | - max_distance, |
| 61 | + max_distance + datafacade.GetMaxRoadHalfWidth(), |
61 | 62 | [this, approach, &input_coordinate, &bearing_with_range, &use_all_edges, max_distance]( |
62 | 63 | const CandidateSegment &segment) |
63 | 64 | { |
64 | 65 | auto invalidDistance = |
65 | | - CheckSegmentDistance(input_coordinate, segment, max_distance); |
| 66 | + CheckSegmentDistance(input_coordinate, segment, max_distance, true); |
66 | 67 | if (invalidDistance) |
67 | 68 | { |
68 | 69 | return std::make_pair(false, false); |
@@ -106,7 +107,7 @@ template <typename RTreeT, typename DataFacadeT> class GeospatialQuery |
106 | 107 | { |
107 | 108 | return (num_results >= max_results) || |
108 | 109 | (max_distance && max_distance != -1.0 && |
109 | | - CheckSegmentDistance(input_coordinate, segment, *max_distance)); |
| 110 | + CheckSegmentDistance(input_coordinate, segment, *max_distance, false)); |
110 | 111 | }); |
111 | 112 |
|
112 | 113 | return MakePhantomNodes(input_coordinate, results); |
@@ -495,11 +496,44 @@ template <typename RTreeT, typename DataFacadeT> class GeospatialQuery |
495 | 496 | wsg84_coordinate); |
496 | 497 | } |
497 | 498 |
|
| 499 | + double GetRoadHalfWidth(const NodeID node_id) const |
| 500 | + { |
| 501 | + const double road_width = std::min(datafacade.GetRoadWidth(node_id), |
| 502 | + extractor::intersection::MAX_ROAD_SURFACE_WIDTH); |
| 503 | + if (road_width > 0.) |
| 504 | + { |
| 505 | + return 0.5 * road_width; |
| 506 | + } |
| 507 | + |
| 508 | + return 0.5 * std::min<double>(datafacade.GetNumberOfLanes(node_id) * |
| 509 | + extractor::intersection::ASSUMED_LANE_WIDTH, |
| 510 | + extractor::intersection::MAX_ROAD_SURFACE_WIDTH); |
| 511 | + } |
| 512 | + |
| 513 | + double GetRoadHalfWidth(const CandidateSegment &segment) const |
| 514 | + { |
| 515 | + if (segment.data.forward_segment_id.enabled && |
| 516 | + segment.data.forward_segment_id.id != SPECIAL_SEGMENTID) |
| 517 | + { |
| 518 | + return GetRoadHalfWidth(segment.data.forward_segment_id.id); |
| 519 | + } |
| 520 | + |
| 521 | + if (segment.data.reverse_segment_id.enabled && |
| 522 | + segment.data.reverse_segment_id.id != SPECIAL_SEGMENTID) |
| 523 | + { |
| 524 | + return GetRoadHalfWidth(segment.data.reverse_segment_id.id); |
| 525 | + } |
| 526 | + |
| 527 | + return 0.; |
| 528 | + } |
| 529 | + |
498 | 530 | bool CheckSegmentDistance(const Coordinate input_coordinate, |
499 | 531 | const CandidateSegment &segment, |
500 | | - const double max_distance) const |
| 532 | + const double max_distance, |
| 533 | + const bool account_road_surface) const |
501 | 534 | { |
502 | | - return GetSegmentDistance(input_coordinate, segment) > max_distance; |
| 535 | + return GetSegmentDistance(input_coordinate, segment) > |
| 536 | + max_distance + (account_road_surface ? GetRoadHalfWidth(segment) : 0.); |
503 | 537 | } |
504 | 538 |
|
505 | 539 | std::pair<bool, bool> CheckSegmentExclude(const CandidateSegment &segment) const |
|
0 commit comments