From 539c40d0fb0cc00849428ce71d5f97b93fa005e3 Mon Sep 17 00:00:00 2001 From: Vladimir Byko-Ianko Date: Mon, 21 May 2018 10:42:42 +0300 Subject: [PATCH] Processing the case when the start and the finish of the route is near an Segment with zero length. --- routing/index_graph_starter.cpp | 7 ++++-- .../routing_integration_tests/route_test.cpp | 22 +++++++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/routing/index_graph_starter.cpp b/routing/index_graph_starter.cpp index 4a58e7787c..14108423ba 100644 --- a/routing/index_graph_starter.cpp +++ b/routing/index_graph_starter.cpp @@ -233,8 +233,11 @@ RouteWeight IndexGraphStarter::CalcSegmentWeight(Segment const & segment) const auto const partLen = MercatorBounds::DistanceOnEarth(vertex.GetPointFrom(), vertex.GetPointTo()); auto const fullLen = MercatorBounds::DistanceOnEarth(GetPoint(real, false /* front */), GetPoint(real, true /* front */)); - CHECK_GREATER(fullLen, 0.0, ()); - return partLen / fullLen * m_graph.CalcSegmentWeight(real); + // Note. |fullLen| == 0.0 in case of Segment(s) with the same ends. + if (fullLen == 0.0) + return 0.0 * m_graph.CalcSegmentWeight(real); + + return (partLen / fullLen) * m_graph.CalcSegmentWeight(real); } return m_graph.CalcOffroadWeight(vertex.GetPointFrom(), vertex.GetPointTo()); diff --git a/routing/routing_integration_tests/route_test.cpp b/routing/routing_integration_tests/route_test.cpp index ce6f291cd1..b8733302e2 100644 --- a/routing/routing_integration_tests/route_test.cpp +++ b/routing/routing_integration_tests/route_test.cpp @@ -379,4 +379,26 @@ namespace IRouter::ResultCode const result = routeResult.second; TEST_EQUAL(result, IRouter::NoError, ()); } + + // Test on the route with the finish near zero length edge. + UNIT_TEST(BelarusSlonimFinishNearZeroEdgeTest) + { + TRouteResult const routeResult = + integration::CalculateRoute(integration::GetVehicleComponents(), + MercatorBounds::FromLatLon(53.08279, 25.30036), {0.0, 0.0}, + MercatorBounds::FromLatLon(53.09443, 25.34356)); + IRouter::ResultCode const result = routeResult.second; + TEST_EQUAL(result, IRouter::NoError, ()); + } + + // Test on the route with the start near zero length edge. + UNIT_TEST(BelarusSlonimStartNearZeroEdgeTest) + { + TRouteResult const routeResult = + integration::CalculateRoute(integration::GetVehicleComponents(), + MercatorBounds::FromLatLon(53.09422, 25.34411), {0.0, 0.0}, + MercatorBounds::FromLatLon(53.09271, 25.3467)); + IRouter::ResultCode const result = routeResult.second; + TEST_EQUAL(result, IRouter::NoError, ()); + } } // namespace