diff --git a/routing/osrm_helpers.cpp b/routing/osrm_helpers.cpp index f63c50a107..729efa5a26 100644 --- a/routing/osrm_helpers.cpp +++ b/routing/osrm_helpers.cpp @@ -11,14 +11,14 @@ namespace helpers { // static void Point2PhantomNode::FindNearestSegment(FeatureType const & ft, m2::PointD const & point, - Candidate & res) + Candidate & res, size_t start_idx, size_t stop_idx) { ft.ParseGeometry(FeatureType::BEST_GEOMETRY); - size_t const count = ft.GetPointsCount(); + size_t const count = min(ft.GetPointsCount() - 1, stop_idx); uint32_t const featureId = ft.GetID().m_index; - ASSERT_GREATER(count, 1, ()); - for (size_t i = 1; i < count; ++i) + ASSERT_GREATER_OR_EQUAL(count, 1, ()); + for (size_t i = start_idx + 1; i <= count; ++i) { m2::ProjectionToSection segProj; segProj.SetBounds(ft.GetPoint(i - 1), ft.GetPoint(i)); diff --git a/routing/osrm_helpers.hpp b/routing/osrm_helpers.hpp index 61de9e54a2..23cb9b2261 100644 --- a/routing/osrm_helpers.hpp +++ b/routing/osrm_helpers.hpp @@ -37,7 +37,8 @@ public: }; // Finds nearest segment to a feature geometry. - static void FindNearestSegment(FeatureType const & ft, m2::PointD const & point, Candidate & res); + static void FindNearestSegment(FeatureType const & ft, m2::PointD const & point, Candidate & res, + size_t start_idx = 0, size_t stop_idx = numeric_limits::max()); // Sets point from where weights are calculated. void SetPoint(m2::PointD const & pt) { m_point = pt; } diff --git a/routing/osrm_router.cpp b/routing/osrm_router.cpp index 387dd03d9b..cf5760e532 100644 --- a/routing/osrm_router.cpp +++ b/routing/osrm_router.cpp @@ -115,7 +115,9 @@ void FindGraphNodeOffsets(uint32_t const nodeId, m2::PointD const & point, loader.GetFeatureByIndex(s.m_fid, ft); helpers::Point2PhantomNode::Candidate mappedSeg; - helpers::Point2PhantomNode::FindNearestSegment(ft, point, mappedSeg); + size_t start_idx = min(s.m_pointStart, s.m_pointEnd); + size_t stop_idx = max(s.m_pointStart, s.m_pointEnd); + helpers::Point2PhantomNode::FindNearestSegment(ft, point, mappedSeg, start_idx, stop_idx); OsrmMappingTypes::FtSeg seg; seg.m_fid = mappedSeg.m_fid;