diff --git a/track_analyzing/track_analyzer/cmd_table.cpp b/track_analyzing/track_analyzer/cmd_table.cpp index 7642cfee4c..c9b2014bed 100644 --- a/track_analyzing/track_analyzer/cmd_table.cpp +++ b/track_analyzing/track_analyzer/cmd_table.cpp @@ -435,7 +435,6 @@ void CmdTagsTable(string const & filepath, string const & trackExtension, String continue; MoveTypeAggregator aggregator; - // Initializing with base::Underlying(IsCrossroadChecker::Type::None) that means with 0. IsCrossroadChecker::CrossroadInfo info = {}; for (auto subtrackBegin = track.begin(); subtrackBegin != track.end();) { @@ -451,12 +450,8 @@ void CmdTagsTable(string const & filepath, string const & trackExtension, String } // If it's not the end of the track than it could be a crossroad. - IsCrossroadChecker::CrossroadInfo crossroad = {}; if (end != track.end()) - { - crossroad = checker(prev->GetSegment(), end->GetSegment()); - IsCrossroadChecker::MergeCrossroads(crossroad, info); - } + IsCrossroadChecker::MergeCrossroads(checker(prev->GetSegment(), end->GetSegment()), info); aggregator.Add(move(moveType), info, subtrackBegin, end, geometry); subtrackBegin = end; diff --git a/track_analyzing/track_analyzer/crossroad_checker.cpp b/track_analyzing/track_analyzer/crossroad_checker.cpp index 163c4a4ce1..d95252bbf2 100644 --- a/track_analyzing/track_analyzer/crossroad_checker.cpp +++ b/track_analyzing/track_analyzer/crossroad_checker.cpp @@ -75,10 +75,8 @@ bool FromSmallerToBigger(HighwayType lhs, HighwayType rhs) namespace routing { -IsCrossroadChecker::CrossroadInfo IsCrossroadChecker::operator()(Segment const & current, Segment const & next) const +IsCrossroadChecker::Type IsCrossroadChecker::operator()(Segment const & current, Segment const & next) const { - IsCrossroadChecker::CrossroadInfo ret = {}; - auto const currentSegmentFeatureId = current.GetFeatureId(); auto const currentSegmentHwType = m_geometry.GetRoad(currentSegmentFeatureId).GetHighwayType(); auto const nextSegmentFeatureId = next.GetFeatureId(); @@ -86,7 +84,7 @@ IsCrossroadChecker::CrossroadInfo IsCrossroadChecker::operator()(Segment const & auto const currentRoadPoint = current.GetRoadPoint(true /* isFront */); auto const jointId = m_indexGraph.GetJointId(currentRoadPoint); if (jointId == Joint::kInvalidId) - return ret; + return Type::Count; bool const isCurrentLink = IsHighwayLink(currentSegmentHwType); bool const isNextLink = IsHighwayLink(nextSegmentHwType); @@ -97,30 +95,18 @@ IsCrossroadChecker::CrossroadInfo IsCrossroadChecker::operator()(Segment const & { // Changing highway type. if (isCurrentLink && !isNextLink && isNextBig) - { - ++ret[base::Underlying(Type::TurnFromSmallerToBigger)]; - return ret; - } + return Type::TurnFromSmallerToBigger; if (!isCurrentLink && isNextLink && isCurrentBig) - { - ++ret[base::Underlying(Type::TurnFromBiggerToSmaller)]; - return ret; - } + return Type::TurnFromBiggerToSmaller; // It's move without links. if (!isCurrentLink && !isNextLink) { if (isCurrentBig && !isNextBig) - { - ++ret[base::Underlying(Type::TurnFromBiggerToSmaller)]; - return ret; - } + return Type::TurnFromBiggerToSmaller; else if (!isCurrentBig && isNextBig) - { - ++ret[base::Underlying(Type::TurnFromSmallerToBigger)]; - return ret; - } + return Type::TurnFromSmallerToBigger; } } @@ -163,9 +149,14 @@ IsCrossroadChecker::CrossroadInfo IsCrossroadChecker::operator()(Segment const & } }); - if (retType != Type::Count) - ++ret[base::Underlying(retType)]; - return ret; + return retType; +} + +// static +void IsCrossroadChecker::MergeCrossroads(Type from, CrossroadInfo & to) +{ + if (from != Type::Count) + ++to[base::Underlying(from)]; } // static @@ -175,4 +166,16 @@ void IsCrossroadChecker::MergeCrossroads(IsCrossroadChecker::CrossroadInfo const for (size_t i = 0; i < from.size(); ++i) to[i] += from[i]; } + +std::string DebugPrint(IsCrossroadChecker::Type type) +{ + switch (type) + { + case IsCrossroadChecker::Type::TurnFromSmallerToBigger: return "TurnFromSmallerToBigger"; + case IsCrossroadChecker::Type::TurnFromBiggerToSmaller: return "TurnFromBiggerToSmaller"; + case IsCrossroadChecker::Type::IntersectionWithBig: return "IntersectionWithBig"; + case IsCrossroadChecker::Type::Count: return "Count"; + } + UNREACHABLE(); +} } // namespace routing diff --git a/track_analyzing/track_analyzer/crossroad_checker.hpp b/track_analyzing/track_analyzer/crossroad_checker.hpp index ca6b9b53be..f62307a423 100644 --- a/track_analyzing/track_analyzer/crossroad_checker.hpp +++ b/track_analyzing/track_analyzer/crossroad_checker.hpp @@ -7,6 +7,7 @@ #include "base/stl_helpers.hpp" #include +#include namespace routing { @@ -15,14 +16,9 @@ class IsCrossroadChecker public: enum class Type { - None, TurnFromSmallerToBigger, TurnFromBiggerToSmaller, - FromLink, - ToLink, IntersectionWithBig, - IntersectionWithSmall, - IntersectionWithLink, Count }; @@ -31,12 +27,16 @@ public: IsCrossroadChecker(IndexGraph & indexGraph, Geometry & geometry) : m_indexGraph(indexGraph), m_geometry(geometry) {} /// \brief Compares two segments by their highway type to find if there was a crossroad between them. /// Check if current segment is a joint to find and find all intersections with other roads. - CrossroadInfo operator()(Segment const & current, Segment const & next) const; + Type operator()(Segment const & current, Segment const & next) const; - static void MergeCrossroads(CrossroadInfo const & from, CrossroadInfo & to); + static void MergeCrossroads(Type from, CrossroadInfo & to); + static void MergeCrossroads(IsCrossroadChecker::CrossroadInfo const & from, + IsCrossroadChecker::CrossroadInfo & to); private: IndexGraph & m_indexGraph; Geometry & m_geometry; }; + +std::string DebugPrint(IsCrossroadChecker::Type type); } // namespace routing