diff --git a/routing/osrm2feature_map.cpp b/routing/osrm2feature_map.cpp index f42038d8c7..661b64a2de 100644 --- a/routing/osrm2feature_map.cpp +++ b/routing/osrm2feature_map.cpp @@ -122,36 +122,20 @@ bool IsInside(FtSeg const & bigSeg, FtSeg const & smallSeg) (segmentLeft <= smallSeg.m_pointStart && segmentRight >= smallSeg.m_pointEnd); } -FtSeg SplitSegment(FtSeg const & segment, FtSeg const & splitter, bool const resultFromLeft) +FtSeg SplitSegment(FtSeg const & segment, FtSeg const & splitter) { FtSeg resultSeg; resultSeg.m_fid = segment.m_fid; if (segment.m_pointStart < segment.m_pointEnd) { - if (resultFromLeft) - { - resultSeg.m_pointStart = segment.m_pointStart; - resultSeg.m_pointEnd = splitter.m_pointEnd; - } - else - { - resultSeg.m_pointStart = splitter.m_pointStart; - resultSeg.m_pointEnd = segment.m_pointEnd; - } + resultSeg.m_pointStart = segment.m_pointStart; + resultSeg.m_pointEnd = splitter.m_pointEnd; } else { - if (resultFromLeft) - { - resultSeg.m_pointStart = segment.m_pointStart; - resultSeg.m_pointEnd = splitter.m_pointStart; - } - else - { - resultSeg.m_pointStart = splitter.m_pointEnd; - resultSeg.m_pointEnd = segment.m_pointEnd; - } + resultSeg.m_pointStart = segment.m_pointStart; + resultSeg.m_pointEnd = splitter.m_pointStart; } return resultSeg; } diff --git a/routing/osrm2feature_map.hpp b/routing/osrm2feature_map.hpp index 217540d26b..5144ce3dbb 100644 --- a/routing/osrm2feature_map.hpp +++ b/routing/osrm2feature_map.hpp @@ -93,9 +93,9 @@ namespace OsrmMappingTypes bool IsInside(FtSeg const & bigSeg, FtSeg const & smallSeg); /// Splits segment by splitter segment and takes part of it. -/// Warning this function includes a whole splitter segment to a result segment described by the -/// resultFromLeft variable. -FtSeg SplitSegment(FtSeg const & segment, FtSeg const & splitter, bool const resultFromLeft); +/// Warning! This function returns part from the start of the segment to the splitter, including it. +/// Splitter segment points must be ordered. +FtSeg SplitSegment(FtSeg const & segment, FtSeg const & splitter); } // namespace OsrmMappingTypes class OsrmFtSegMapping; diff --git a/routing/osrm_helpers.cpp b/routing/osrm_helpers.cpp index 8a2662e242..9ee1dc7793 100644 --- a/routing/osrm_helpers.cpp +++ b/routing/osrm_helpers.cpp @@ -68,7 +68,7 @@ double Point2PhantomNode::CalculateDistance(FeatureType const & ft, void Point2PhantomNode::CalculateWeight(OsrmMappingTypes::FtSeg const & seg, m2::PointD const & segPt, NodeID const & nodeId, - bool calcFromRight, int & weight, int & offset) const + int & weight, int & offset) const { // nodeId can be INVALID_NODE_ID when reverse node is absent. This node has no weight. if (nodeId == INVALID_NODE_ID) @@ -92,13 +92,8 @@ void Point2PhantomNode::CalculateWeight(OsrmMappingTypes::FtSeg const & seg, auto const range = m_routingMapping.m_segMapping.GetSegmentsRange(nodeId); OsrmMappingTypes::FtSeg segment; - size_t const startIndex = calcFromRight ? range.second - 1 : range.first; - size_t const endIndex = calcFromRight ? range.first - 1 : range.second; - int const indexIncrement = calcFromRight ? -1 : 1; - bool foundSeg = false; - m2::PointD lastPoint; - for (size_t segmentIndex = startIndex; segmentIndex != endIndex; segmentIndex += indexIncrement) + for (size_t segmentIndex = range.first; segmentIndex != range.second; ++segmentIndex) { m_routingMapping.m_segMapping.GetSegmentByIndex(segmentIndex, segment); if (!segment.IsValid()) @@ -120,11 +115,10 @@ void Point2PhantomNode::CalculateWeight(OsrmMappingTypes::FtSeg const & seg, if (segment.m_fid == seg.m_fid && OsrmMappingTypes::IsInside(segment, seg)) { - auto const splittedSegment = OsrmMappingTypes::SplitSegment(segment, seg, !calcFromRight); + auto const splittedSegment = OsrmMappingTypes::SplitSegment(segment, seg); distanceM += CalculateDistance(ft, splittedSegment.m_pointStart, splittedSegment.m_pointEnd); // node.m_seg always forward ordered (m_pointStart < m_pointEnd) - distanceM -= MercatorBounds::DistanceOnEarth( - ft.GetPoint(calcFromRight ? seg.m_pointStart : seg.m_pointEnd), segPt); + distanceM -= MercatorBounds::DistanceOnEarth(ft.GetPoint(seg.m_pointEnd), segPt); foundSeg = true; } @@ -274,9 +268,9 @@ void Point2PhantomNode::CalculateWeights(FeatureGraphNode & node) const // Need to initialize weights for correct work of PhantomNode::GetForwardWeightPlusOffset // and PhantomNode::GetReverseWeightPlusOffset. CalculateWeight(node.segment, node.segmentPoint, node.node.forward_node_id, - false /* calcFromRight */, node.node.forward_weight, node.node.forward_offset); + node.node.forward_weight, node.node.forward_offset); CalculateWeight(node.segment, node.segmentPoint, node.node.reverse_node_id, - true /* calcFromRight */, node.node.reverse_weight, node.node.reverse_offset); + node.node.reverse_weight, node.node.reverse_offset); } void Point2Node::operator()(FeatureType const & ft) diff --git a/routing/osrm_helpers.hpp b/routing/osrm_helpers.hpp index 97168e0c3e..61de9e54a2 100644 --- a/routing/osrm_helpers.hpp +++ b/routing/osrm_helpers.hpp @@ -59,7 +59,7 @@ private: /// Calculates part of a node weight in the OSRM format. Projection point @segPt divides node on /// two parts. So we find weight of a part, set by the @calcFromRight parameter. void CalculateWeight(OsrmMappingTypes::FtSeg const & seg, m2::PointD const & segPt, - NodeID const & nodeId, bool calcFromRight, int & weight, int & offset) const; + NodeID const & nodeId, int & weight, int & offset) const; /// Returns minimal weight of the node. EdgeWeight GetMinNodeWeight(NodeID node, m2::PointD const & point) const; diff --git a/routing/routing_integration_tests/osrm_route_test.cpp b/routing/routing_integration_tests/osrm_route_test.cpp index 45534062c8..55f96eb39c 100644 --- a/routing/routing_integration_tests/osrm_route_test.cpp +++ b/routing/routing_integration_tests/osrm_route_test.cpp @@ -120,6 +120,14 @@ namespace {11.327927635052676, 48.166256203616726}, 2870710.); } + UNIT_TEST(PeruSingleRoadTest) + { + integration::CalculateRouteAndTestRouteLength( + integration::GetOsrmComponents(), + MercatorBounds::FromLatLon(-14.22061, -73.35969), {0., 0.}, + MercatorBounds::FromLatLon(-14.22389, -73.44281), 15900.); + } + UNIT_TEST(RussiaMoscowFranceParisCenterRouteTest) { integration::CalculateRouteAndTestRouteLength( @@ -245,6 +253,6 @@ namespace IRouter::ResultCode const result = routeResult.second; TEST_EQUAL(result, IRouter::NoError, ()); - integration::TestRouteTime(route, 909.); + integration::TestRouteTime(route, 900.); } } // namespace diff --git a/routing/routing_tests/routing_mapping_test.cpp b/routing/routing_tests/routing_mapping_test.cpp index 619af953c7..313abf6250 100644 --- a/routing/routing_tests/routing_mapping_test.cpp +++ b/routing/routing_tests/routing_mapping_test.cpp @@ -118,14 +118,10 @@ UNIT_TEST(FtSegSplitSegmentiTest) OsrmMappingTypes::FtSeg bseg(123, 5, 1); OsrmMappingTypes::FtSeg splitter(123, 2, 3); - OsrmMappingTypes::FtSeg res1(123, 2, 5); - TEST_EQUAL(res1, OsrmMappingTypes::SplitSegment(seg, splitter, false), ()); - OsrmMappingTypes::FtSeg res2(123, 1, 3); - TEST_EQUAL(res2, OsrmMappingTypes::SplitSegment(seg, splitter, true), ()); + OsrmMappingTypes::FtSeg res1(123, 1, 3); + TEST_EQUAL(res1, OsrmMappingTypes::SplitSegment(seg, splitter), ()); - OsrmMappingTypes::FtSeg res3(123, 3, 1); - TEST_EQUAL(res3, OsrmMappingTypes::SplitSegment(bseg, splitter, false), ()); - OsrmMappingTypes::FtSeg res4(123, 5, 2); - TEST_EQUAL(res4, OsrmMappingTypes::SplitSegment(bseg, splitter, true), ()); + OsrmMappingTypes::FtSeg res2(123, 5, 2); + TEST_EQUAL(res2, OsrmMappingTypes::SplitSegment(bseg, splitter), ()); } } // namespace