From 207d6c833d1f004a5be42b3f3d82cd8728eec78d Mon Sep 17 00:00:00 2001 From: mvglasow Date: Thu, 30 Oct 2025 21:50:19 +0200 Subject: [PATCH] [traffic] Pass toJunctions parameter to TruncateRoute() Signed-off-by: mvglasow --- libs/traffxml/traff_decoder.cpp | 18 ++++++++++-------- libs/traffxml/traff_decoder.hpp | 9 ++++++--- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/libs/traffxml/traff_decoder.cpp b/libs/traffxml/traff_decoder.cpp index 1b84077dd..0d1b39eb5 100644 --- a/libs/traffxml/traff_decoder.cpp +++ b/libs/traffxml/traff_decoder.cpp @@ -878,7 +878,7 @@ void RoutingTraffDecoder::AddDecodedSegment(traffxml::MultiMwmColoring & decoded } void RoutingTraffDecoder::TruncateRoute(std::vector & rsegments, - routing::Checkpoints const & checkpoints) + routing::Checkpoints const & checkpoints, bool toJunctions) { double const endWeight = rsegments.back().GetTimeFromBeginningSec(); @@ -901,8 +901,8 @@ void RoutingTraffDecoder::TruncateRoute(std::vector & rse // Cost saved by omitting the last `end` segments. double endSaving = 0; - TruncateStart(rsegments, checkpoints, start, startSaving); - TruncateEnd(rsegments, checkpoints, end, endSaving, endWeight); + TruncateStart(rsegments, checkpoints, start, startSaving, toJunctions); + TruncateEnd(rsegments, checkpoints, end, endSaving, endWeight, toJunctions); /* * If start <= end, we can truncate both ends at the same time. @@ -920,7 +920,7 @@ void RoutingTraffDecoder::TruncateRoute(std::vector & rse rsegments.erase(rsegments.begin(), rsegments.begin() + start); end = rsegments.size() - 1; endSaving = 0; - TruncateEnd(rsegments, checkpoints, end, endSaving, endWeight); + TruncateEnd(rsegments, checkpoints, end, endSaving, endWeight, toJunctions); rsegments.erase(rsegments.begin() + end + 1, rsegments.end()); } else @@ -929,7 +929,7 @@ void RoutingTraffDecoder::TruncateRoute(std::vector & rse rsegments.erase(rsegments.begin() + end + 1, rsegments.end()); start = 0; startSaving = 0; - TruncateStart(rsegments, checkpoints, start, startSaving); + TruncateStart(rsegments, checkpoints, start, startSaving, toJunctions); rsegments.erase(rsegments.begin(), rsegments.begin() + start); } } @@ -1028,7 +1028,9 @@ void RoutingTraffDecoder::DecodeLocationDirection(traffxml::TraffMessage & messa { std::vector rsegments(route->GetRouteSegments()); - TruncateRoute(rsegments, checkpoints); + TruncateRoute(rsegments, checkpoints, + message.m_location.value().m_fuzziness + && (message.m_location.value().m_fuzziness.value() == traffxml::Fuzziness::LowRes)); /* * `m_onRoundabout` is set only for the first segment after the junction. In order to identify @@ -1291,7 +1293,7 @@ std::vector ParseRef(std::string & ref) void TruncateStart(std::vector & rsegments, routing::Checkpoints const & checkpoints, - size_t & start, double & startSaving) + size_t & start, double & startSaving, bool toJunction) { for (size_t i = 0; i < rsegments.size(); i++) { @@ -1308,7 +1310,7 @@ void TruncateStart(std::vector & rsegments, void TruncateEnd(std::vector & rsegments, routing::Checkpoints const & checkpoints, - size_t & end, double & endSaving, double const endWeight) + size_t & end, double & endSaving, double const endWeight, bool toJunction) { for (size_t i = 0; i < rsegments.size(); i++) { diff --git a/libs/traffxml/traff_decoder.hpp b/libs/traffxml/traff_decoder.hpp index c32ade1b7..753abec7c 100644 --- a/libs/traffxml/traff_decoder.hpp +++ b/libs/traffxml/traff_decoder.hpp @@ -415,9 +415,10 @@ protected: * * @param rsegments The segments of the route * @param checkpoints The reference points (at least two) + * @param toJunctions Whether the truncated route should begin and end at a junction */ void TruncateRoute(std::vector & rsegments, - routing::Checkpoints const & checkpoints); + routing::Checkpoints const & checkpoints, bool toJunctions); private: static void LogCode(routing::RouterResultCode code, double const elapsedSec); @@ -483,10 +484,11 @@ std::vector ParseRef(std::string & ref); * @param checkpoints The reference points (at least two) * @param start Index of the first segment to keep * @param startSaving Cost saved by truncating + * @param toJunction Whether the truncated route should start at a junction */ void TruncateStart(std::vector & rsegments, routing::Checkpoints const & checkpoints, - size_t & start, double & startSaving); + size_t & start, double & startSaving, bool toJunction); /** * @brief Calculates the segments to truncate at the start of the route. @@ -501,8 +503,9 @@ void TruncateStart(std::vector & rsegments, * @param checkpoints The reference points (at least two) * @param end Index of the last segment to keep * @param endSaving Cost saved by truncating + * @param toJunction Whether the truncated route should end at a junction */ void TruncateEnd(std::vector & rsegments, routing::Checkpoints const & checkpoints, - size_t & end, double & endSaving, double const endWeight); + size_t & end, double & endSaving, double const endWeight, bool ToJunction); } // namespace traffxml