diff --git a/routing/CMakeLists.txt b/routing/CMakeLists.txt index 7476229885..7400119494 100644 --- a/routing/CMakeLists.txt +++ b/routing/CMakeLists.txt @@ -122,6 +122,7 @@ set( routing_session.hpp routing_settings.cpp routing_settings.hpp + segment.cpp segment.hpp segmented_route.cpp segmented_route.hpp diff --git a/routing/segment.cpp b/routing/segment.cpp new file mode 100644 index 0000000000..3cc552dd39 --- /dev/null +++ b/routing/segment.cpp @@ -0,0 +1,75 @@ +#include "routing/segment.hpp" + +#include "routing/fake_feature_ids.hpp" + +#include + +namespace routing +{ +// Segment ----------------------------------------------------------------------------------------- +uint32_t Segment::GetPointId(bool front) const +{ + return m_forward == front ? m_segmentIdx + 1 : m_segmentIdx; +} + +bool Segment::operator<(Segment const & seg) const +{ + if (m_featureId != seg.m_featureId) + return m_featureId < seg.m_featureId; + + if (m_segmentIdx != seg.m_segmentIdx) + return m_segmentIdx < seg.m_segmentIdx; + + if (m_mwmId != seg.m_mwmId) + return m_mwmId < seg.m_mwmId; + + return m_forward < seg.m_forward; +} + +bool Segment::operator==(Segment const & seg) const +{ + return m_featureId == seg.m_featureId && m_segmentIdx == seg.m_segmentIdx && + m_mwmId == seg.m_mwmId && m_forward == seg.m_forward; +} + +bool Segment::operator!=(Segment const & seg) const { return !(*this == seg); } + +bool Segment::IsInverse(Segment const & seg) const +{ + return m_featureId == seg.m_featureId && m_segmentIdx == seg.m_segmentIdx && + m_mwmId == seg.m_mwmId && m_forward != seg.m_forward; +} + +bool Segment::IsRealSegment() const +{ + return m_mwmId != kFakeNumMwmId && !FakeFeatureIds::IsTransitFeature(m_featureId); +} + +// SegmentEdge ------------------------------------------------------------------------------------- +bool SegmentEdge::operator==(SegmentEdge const & edge) const +{ + return m_target == edge.m_target && m_weight == edge.m_weight; +} + +bool SegmentEdge::operator<(SegmentEdge const & edge) const +{ + if (m_target != edge.m_target) + return m_target < edge.m_target; + return m_weight < edge.m_weight; +} + +std::string DebugPrint(Segment const & segment) +{ + std::ostringstream out; + out << std::boolalpha << "Segment(" << segment.GetMwmId() << ", " << segment.GetFeatureId() << ", " + << segment.GetSegmentIdx() << ", " << segment.IsForward() << ")"; + return out.str(); +} + +std::string DebugPrint(SegmentEdge const & edge) +{ + std::ostringstream out; + out << "Edge(" << DebugPrint(edge.GetTarget()) << ", " << edge.GetWeight() << ")"; + return out.str(); +} +} // namespace routing diff --git a/routing/segment.hpp b/routing/segment.hpp index a811730770..689e374490 100644 --- a/routing/segment.hpp +++ b/routing/segment.hpp @@ -1,6 +1,5 @@ #pragma once -#include "routing/fake_feature_ids.hpp" #include "routing/road_point.hpp" #include "routing/route_weight.hpp" @@ -8,7 +7,6 @@ #include #include -#include #include namespace routing @@ -38,57 +36,23 @@ public: uint32_t GetSegmentIdx() const { return m_segmentIdx; } bool IsForward() const { return m_forward; } - uint32_t GetPointId(bool front) const - { - return m_forward == front ? m_segmentIdx + 1 : m_segmentIdx; - } + uint32_t GetPointId(bool front) const; uint32_t GetMinPointId() const { return m_segmentIdx; } uint32_t GetMaxPointId() const { return m_segmentIdx + 1; } RoadPoint GetRoadPoint(bool front) const { return RoadPoint(m_featureId, GetPointId(front)); } - bool operator<(Segment const & seg) const - { - if (m_featureId != seg.m_featureId) - return m_featureId < seg.m_featureId; - - if (m_segmentIdx != seg.m_segmentIdx) - return m_segmentIdx < seg.m_segmentIdx; - - if (m_mwmId != seg.m_mwmId) - return m_mwmId < seg.m_mwmId; - - return m_forward < seg.m_forward; - } - - uint32_t GetStartSegmentId() const { return 0; } - - bool operator==(Segment const & seg) const - { - return m_featureId == seg.m_featureId && m_segmentIdx == seg.m_segmentIdx && - m_mwmId == seg.m_mwmId && m_forward == seg.m_forward; - } - - bool operator!=(Segment const & seg) const { return !(*this == seg); } - - bool IsInverse(Segment const & seg) const - { - return m_featureId == seg.m_featureId && m_segmentIdx == seg.m_segmentIdx && - m_mwmId == seg.m_mwmId && m_forward != seg.m_forward; - } + bool operator<(Segment const & seg) const; + bool operator==(Segment const & seg) const; + bool operator!=(Segment const & seg) const; + bool IsInverse(Segment const & seg) const; void Inverse() { m_forward = !m_forward; } - bool IsRealSegment() const - { - return m_mwmId != kFakeNumMwmId && !FakeFeatureIds::IsTransitFeature(m_featureId); - } + bool IsRealSegment() const; - void Next(bool forward) - { - forward ? ++m_segmentIdx : --m_segmentIdx; - } + void Next(bool forward) { forward ? ++m_segmentIdx : --m_segmentIdx; } private: uint32_t m_featureId = 0; @@ -105,20 +69,12 @@ public: : m_target(target), m_weight(weight) { } + Segment const & GetTarget() const { return m_target; } RouteWeight const & GetWeight() const { return m_weight; } - bool operator==(SegmentEdge const & edge) const - { - return m_target == edge.m_target && m_weight == edge.m_weight; - } - - bool operator<(SegmentEdge const & edge) const - { - if (m_target != edge.m_target) - return m_target < edge.m_target; - return m_weight < edge.m_weight; - } + bool operator==(SegmentEdge const & edge) const; + bool operator<(SegmentEdge const & edge) const; private: // Target is vertex going to for outgoing edges, vertex going from for ingoing edges. @@ -126,18 +82,6 @@ private: RouteWeight m_weight; }; -inline std::string DebugPrint(Segment const & segment) -{ - std::ostringstream out; - out << std::boolalpha << "Segment(" << segment.GetMwmId() << ", " << segment.GetFeatureId() << ", " - << segment.GetSegmentIdx() << ", " << segment.IsForward() << ")"; - return out.str(); -} - -inline std::string DebugPrint(SegmentEdge const & edge) -{ - std::ostringstream out; - out << "Edge(" << DebugPrint(edge.GetTarget()) << ", " << edge.GetWeight() << ")"; - return out.str(); -} +std::string DebugPrint(Segment const & segment); +std::string DebugPrint(SegmentEdge const & edge); } // namespace routing diff --git a/xcode/routing/routing.xcodeproj/project.pbxproj b/xcode/routing/routing.xcodeproj/project.pbxproj index 54770bff94..ea07ff399c 100644 --- a/xcode/routing/routing.xcodeproj/project.pbxproj +++ b/xcode/routing/routing.xcodeproj/project.pbxproj @@ -85,6 +85,7 @@ 440BE38622AFB31100C548FB /* world_graph_builder.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 440BE38422AFB31100C548FB /* world_graph_builder.hpp */; }; 440BE38822AFB31700C548FB /* uturn_restriction_tests.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 440BE38722AFB31600C548FB /* uturn_restriction_tests.cpp */; }; 44183280222D45BB00C70BD9 /* routing_options_tests.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4418327F222D45BB00C70BD9 /* routing_options_tests.cpp */; }; + 441CC8C623ACF42C008B9A49 /* segment.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 441CC8C523ACF42C008B9A49 /* segment.cpp */; }; 4433A8E923993BD200E1350B /* leaps_graph.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4433A8E823993BD200E1350B /* leaps_graph.cpp */; }; 4433A8EB23993BD700E1350B /* leaps_graph.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 4433A8EA23993BD700E1350B /* leaps_graph.hpp */; }; 4443DC3722789793000C8E32 /* leaps_postprocessor.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4443DC3522789793000C8E32 /* leaps_postprocessor.cpp */; }; @@ -394,6 +395,7 @@ 440BE38422AFB31100C548FB /* world_graph_builder.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = world_graph_builder.hpp; sourceTree = ""; }; 440BE38722AFB31600C548FB /* uturn_restriction_tests.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = uturn_restriction_tests.cpp; sourceTree = ""; }; 4418327F222D45BB00C70BD9 /* routing_options_tests.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = routing_options_tests.cpp; sourceTree = ""; }; + 441CC8C523ACF42C008B9A49 /* segment.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = segment.cpp; sourceTree = ""; }; 4433A8E823993BD200E1350B /* leaps_graph.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = leaps_graph.cpp; sourceTree = ""; }; 4433A8EA23993BD700E1350B /* leaps_graph.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = leaps_graph.hpp; sourceTree = ""; }; 4443DC3522789793000C8E32 /* leaps_postprocessor.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = leaps_postprocessor.cpp; sourceTree = ""; }; @@ -848,6 +850,7 @@ 675343FA1A3F640D00A0A8C3 /* routing */ = { isa = PBXGroup; children = ( + 441CC8C523ACF42C008B9A49 /* segment.cpp */, 56DAC2C72398F3C8000BC50D /* junction_visitor.hpp */, 4433A8EA23993BD700E1350B /* leaps_graph.hpp */, 4433A8E823993BD200E1350B /* leaps_graph.cpp */, @@ -1345,6 +1348,7 @@ 567F81942154D6FF0093C25B /* city_roads.cpp in Sources */, 6753441B1A3F644F00A0A8C3 /* route.cpp in Sources */, 44183280222D45BB00C70BD9 /* routing_options_tests.cpp in Sources */, + 441CC8C623ACF42C008B9A49 /* segment.cpp in Sources */, 44AE4A12214FBB8E006321F5 /* speed_camera.cpp in Sources */, 674F9BCA1B0A580E00704FFA /* async_router.cpp in Sources */, 0C5F5D221E798B0400307B98 /* cross_mwm_connector.cpp in Sources */,