diff --git a/pedestrian_routing_tests/pedestrian_routing_tests.cpp b/pedestrian_routing_tests/pedestrian_routing_tests.cpp index c21b792ac0..8abaaad192 100644 --- a/pedestrian_routing_tests/pedestrian_routing_tests.cpp +++ b/pedestrian_routing_tests/pedestrian_routing_tests.cpp @@ -4,10 +4,12 @@ #include "indexer/classificator_loader.hpp" #include "routing/features_road_graph.hpp" -#include "routing/road_graph_router.hpp" -#include "routing/route.hpp" #include "routing/pedestrian_directions.hpp" #include "routing/pedestrian_model.hpp" +#include "routing/pedestrian_model.hpp" +#include "routing/road_graph.hpp" +#include "routing/road_graph_router.hpp" +#include "routing/route.hpp" #include "routing/router_delegate.hpp" #include "storage/country_info_getter.hpp" @@ -124,7 +126,8 @@ m2::PointD GetPointOnEdge(routing::Edge & e, double posAlong) return e.GetStartJunction().GetPoint() + d * posAlong; } -void GetNearestPedestrianEdges(Index & index, m2::PointD const & pt, vector> & edges) +void GetNearestPedestrianEdges(Index & index, m2::PointD const & pt, + vector> & edges) { unique_ptr vehicleModelFactory(new SimplifiedPedestrianModelFactory()); routing::FeaturesRoadGraph roadGraph(index, routing::IRoadGraph::Mode::IgnoreOnewayTag, @@ -189,11 +192,11 @@ void TestTwoPointsOnFeature(m2::PointD const & startPos, m2::PointD const & fina TEST(id.IsAlive(), ()); } - vector> startEdges; + vector> startEdges; GetNearestPedestrianEdges(index, startPos, startEdges); TEST(!startEdges.empty(), ()); - vector> finalEdges; + vector> finalEdges; GetNearestPedestrianEdges(index, finalPos, finalEdges); TEST(!finalEdges.empty(), ()); diff --git a/routing/features_road_graph.cpp b/routing/features_road_graph.cpp index 8d0d1dcd22..a59ed392e7 100644 --- a/routing/features_road_graph.cpp +++ b/routing/features_road_graph.cpp @@ -166,7 +166,7 @@ void FeaturesRoadGraph::ForEachFeatureClosestToCross(m2::PointD const & cross, } void FeaturesRoadGraph::FindClosestEdges(m2::PointD const & point, uint32_t count, - vector> & vicinities) const + vector> & vicinities) const { NearestEdgeFinder finder(point); @@ -254,6 +254,38 @@ double FeaturesRoadGraph::GetSpeedKMPHFromFt(FeatureType const & ft) const return m_vehicleModel.GetSpeed(ft); } +void FeaturesRoadGraph::ExtractRoadInfo(FeatureID const & featureId, FeatureType const & ft, + double speedKMPH, RoadInfo & ri) const +{ + ri.m_bidirectional = !IsOneWay(ft); + ri.m_speedKMPH = speedKMPH; + + ft.ParseGeometry(FeatureType::BEST_GEOMETRY); + ft.ParseAltitude(); + // @TODO It's a temprarery solution until a vector of feature altitudes is saved in mwm. + bool const isAltidudeValid = + ft.GetAltitudes().begin != feature::kInvalidAltitude && ft.GetAltitudes().end != feature::kInvalidAltitude; + feature::TAltitude pointAlt = ft.GetAltitudes().begin; + size_t const pointsCount = ft.GetPointsCount(); + feature::TAltitude const diffAlt = isAltidudeValid ? (ft.GetAltitudes().end - ft.GetAltitudes().begin) / pointsCount : 0; + + ri.m_junctions.clear(); + ri.m_junctions.resize(pointsCount); + for (size_t i = 0; i < pointsCount; ++i) + { + if (!isAltidudeValid) + { + ri.m_junctions[i] = Junction(ft.GetPoint(i), feature::kInvalidAltitude); + continue; + } + + ri.m_junctions[i] = Junction(ft.GetPoint(i), pointAlt); + pointAlt += diffAlt; + } + + LockFeatureMwm(featureId); +} + IRoadGraph::RoadInfo const & FeaturesRoadGraph::GetCachedRoadInfo(FeatureID const & featureId) const { bool found = false; @@ -271,24 +303,12 @@ IRoadGraph::RoadInfo const & FeaturesRoadGraph::GetCachedRoadInfo(FeatureID cons ASSERT_EQUAL(ft.GetFeatureType(), feature::GEOM_LINE, ()); - ft.ParseGeometry(FeatureType::BEST_GEOMETRY); - - ri.m_bidirectional = !IsOneWay(ft); - ri.m_speedKMPH = GetSpeedKMPHFromFt(ft); - ft.SwapPoints(ri.m_points); - - ft.ParseAltitude(); - // @TODO It's better to use swap here when altitudes is kept in a vector. - ri.m_altitudes = ft.GetAltitudes(); - LOG(LINFO, ("ri.m_altitudes.begin =", ri.m_altitudes.begin, "ri.m_altitudes.end =", ri.m_altitudes.end)); - - LockFeatureMwm(featureId); - + ExtractRoadInfo(featureId, ft, GetSpeedKMPHFromFt(ft), ri); return ri; } IRoadGraph::RoadInfo const & FeaturesRoadGraph::GetCachedRoadInfo(FeatureID const & featureId, - FeatureType & ft, + FeatureType const & ft, double speedKMPH) const { bool found = false; @@ -299,15 +319,7 @@ IRoadGraph::RoadInfo const & FeaturesRoadGraph::GetCachedRoadInfo(FeatureID cons // ft must be set ASSERT_EQUAL(featureId, ft.GetID(), ()); - - ft.ParseGeometry(FeatureType::BEST_GEOMETRY); - - ri.m_bidirectional = !IsOneWay(ft); - ri.m_speedKMPH = speedKMPH; - ft.SwapPoints(ri.m_points); - - LockFeatureMwm(featureId); - + ExtractRoadInfo(featureId, ft, speedKMPH, ri); return ri; } diff --git a/routing/features_road_graph.hpp b/routing/features_road_graph.hpp index df3d7ec47a..e870d18859 100644 --- a/routing/features_road_graph.hpp +++ b/routing/features_road_graph.hpp @@ -69,7 +69,7 @@ public: void ForEachFeatureClosestToCross(m2::PointD const & cross, ICrossEdgesLoader & edgesLoader) const override; void FindClosestEdges(m2::PointD const & point, uint32_t count, - vector> & vicinities) const override; + vector> & vicinities) const override; void GetFeatureTypes(FeatureID const & featureId, feature::TypesHolder & types) const override; void GetJunctionTypes(Junction const & junction, feature::TypesHolder & types) const override; IRoadGraph::Mode GetMode() const override; @@ -88,8 +88,10 @@ private: // Searches a feature RoadInfo in the cache, and if does not find then takes passed feature and speed. // This version is used to prevent redundant feature loading when feature speed is known. RoadInfo const & GetCachedRoadInfo(FeatureID const & featureId, - FeatureType & ft, + FeatureType const & ft, double speedKMPH) const; + void ExtractRoadInfo(FeatureID const & featureId, FeatureType const & ft, + double speedKMPH, RoadInfo & ri) const; void LockFeatureMwm(FeatureID const & featureId) const; diff --git a/routing/nearest_edge_finder.cpp b/routing/nearest_edge_finder.cpp index 1780d0fa8d..1e7b1b0e02 100644 --- a/routing/nearest_edge_finder.cpp +++ b/routing/nearest_edge_finder.cpp @@ -13,10 +13,7 @@ namespace routing NearestEdgeFinder::Candidate::Candidate() : m_dist(numeric_limits::max()), - m_segId(0), - m_segStart(m2::PointD::Zero()), - m_segEnd(m2::PointD::Zero()), - m_point(m2::PointD::Zero()) + m_segId(0) { } @@ -29,13 +26,13 @@ void NearestEdgeFinder::AddInformationSource(FeatureID const & featureId, IRoadG { Candidate res; - size_t const count = roadInfo.m_points.size(); + size_t const count = roadInfo.m_junctions.size(); ASSERT_GREATER(count, 1, ()); for (size_t i = 1; i < count; ++i) { /// @todo Probably, we need to get exact projection distance in meters. m2::ProjectionToSection segProj; - segProj.SetBounds(roadInfo.m_points[i - 1], roadInfo.m_points[i]); + segProj.SetBounds(roadInfo.m_junctions[i - 1].GetPoint(), roadInfo.m_junctions[i].GetPoint()); m2::PointD const pt = segProj(m_point); double const d = m_point.SquareLength(pt); @@ -44,9 +41,16 @@ void NearestEdgeFinder::AddInformationSource(FeatureID const & featureId, IRoadG res.m_dist = d; res.m_fid = featureId; res.m_segId = static_cast(i - 1); - res.m_segStart = roadInfo.m_points[i - 1]; - res.m_segEnd = roadInfo.m_points[i]; - res.m_point = pt; + res.m_segStart = roadInfo.m_junctions[i - 1]; + res.m_segEnd = roadInfo.m_junctions[i]; + // @TODO res.m_projPoint.GetAltitude() is an altitude of |pt|. |pt| is a projection of m_point + // to segment [res.m_segStart.GetPoint(), res.m_segEnd.GetPoint()]. + // It's necessary to calculate exact value of res.m_projPoint.GetAltitude() by this information. + bool const isAltidudeValid = res.m_segStart.GetAltitude() != feature::kInvalidAltitude + && res.m_segEnd.GetAltitude() != feature::kInvalidAltitude; + feature::TAltitude const projPointAlt = isAltidudeValid ? static_cast((res.m_segStart.GetAltitude() + res.m_segEnd.GetAltitude()) / 2) + : feature::kInvalidAltitude; + res.m_projPoint = Junction(pt, projPointAlt); } } @@ -54,7 +58,7 @@ void NearestEdgeFinder::AddInformationSource(FeatureID const & featureId, IRoadG m_candidates.push_back(res); } -void NearestEdgeFinder::MakeResult(vector> & res, size_t const maxCountFeatures) +void NearestEdgeFinder::MakeResult(vector> & res, size_t const maxCountFeatures) { sort(m_candidates.begin(), m_candidates.end(), [](Candidate const & r1, Candidate const & r2) { @@ -67,7 +71,8 @@ void NearestEdgeFinder::MakeResult(vector> & res, size_t size_t i = 0; for (Candidate const & candidate : m_candidates) { - res.emplace_back(Edge(candidate.m_fid, true /* forward */, candidate.m_segId, candidate.m_segStart, candidate.m_segEnd), candidate.m_point); + res.emplace_back(Edge(candidate.m_fid, true /* forward */, candidate.m_segId, + candidate.m_segStart, candidate.m_segEnd), candidate.m_projPoint); ++i; if (i == maxCountFeatures) break; diff --git a/routing/nearest_edge_finder.hpp b/routing/nearest_edge_finder.hpp index 6a9ad2a773..ca83564abd 100644 --- a/routing/nearest_edge_finder.hpp +++ b/routing/nearest_edge_finder.hpp @@ -5,6 +5,7 @@ #include "geometry/point2d.hpp" +#include "indexer/feature_altitude.hpp" #include "indexer/feature_decl.hpp" #include "indexer/index.hpp" #include "indexer/mwm_set.hpp" @@ -24,9 +25,9 @@ class NearestEdgeFinder { double m_dist; uint32_t m_segId; - m2::PointD m_segStart; - m2::PointD m_segEnd; - m2::PointD m_point; + Junction m_segStart; + Junction m_segEnd; + Junction m_projPoint; FeatureID m_fid; Candidate(); @@ -42,7 +43,7 @@ public: void AddInformationSource(FeatureID const & featureId, IRoadGraph::RoadInfo const & roadInfo); - void MakeResult(vector> & res, size_t const maxCountFeatures); + void MakeResult(vector> & res, size_t const maxCountFeatures); }; } // namespace routing diff --git a/routing/road_graph.cpp b/routing/road_graph.cpp index 271e258e63..a2e1ea414a 100644 --- a/routing/road_graph.cpp +++ b/routing/road_graph.cpp @@ -67,17 +67,17 @@ void ReverseEdges(size_t beginIdx, IRoadGraph::TEdgeVector & edges) // Junction -------------------------------------------------------------------- Junction::Junction() - : m_point(m2::PointD::Zero()) + : m_point(m2::PointD::Zero()), m_altitude(feature::kInvalidAltitude) {} -Junction::Junction(m2::PointD const & point) - : m_point(point) +Junction::Junction(m2::PointD const & point, feature::TAltitude altitude) + : m_point(point), m_altitude(altitude) {} string DebugPrint(Junction const & r) { ostringstream ss; - ss << "Junction{point:" << DebugPrint(r.m_point) << "}"; + ss << "Junction{point:" << DebugPrint(r.m_point) << ", altitude:}" << r.GetAltitude(); return ss.str(); } @@ -146,32 +146,32 @@ IRoadGraph::RoadInfo::RoadInfo() {} IRoadGraph::RoadInfo::RoadInfo(RoadInfo && ri) - : m_points(move(ri.m_points)), + : m_junctions(move(ri.m_junctions)), m_speedKMPH(ri.m_speedKMPH), m_bidirectional(ri.m_bidirectional) {} -IRoadGraph::RoadInfo::RoadInfo(bool bidirectional, double speedKMPH, initializer_list const & points) - : m_points(points), m_speedKMPH(speedKMPH), m_bidirectional(bidirectional) +IRoadGraph::RoadInfo::RoadInfo(bool bidirectional, double speedKMPH, initializer_list const & points) + : m_junctions(points), m_speedKMPH(speedKMPH), m_bidirectional(bidirectional) {} // IRoadGraph::CrossOutgoingLoader --------------------------------------------- void IRoadGraph::CrossOutgoingLoader::LoadEdges(FeatureID const & featureId, RoadInfo const & roadInfo) { - ForEachEdge(roadInfo, [&featureId, &roadInfo, this](size_t segId, m2::PointD const & endPoint, bool forward) + ForEachEdge(roadInfo, [&featureId, &roadInfo, this](size_t segId, Junction const & endJunction, bool forward) { if (forward || roadInfo.m_bidirectional || m_mode == IRoadGraph::Mode::IgnoreOnewayTag) - m_edges.emplace_back(featureId, forward, segId, m_cross, endPoint); + m_edges.emplace_back(featureId, forward, segId, m_cross, endJunction); }); } // IRoadGraph::CrossIngoingLoader ---------------------------------------------- void IRoadGraph::CrossIngoingLoader::LoadEdges(FeatureID const & featureId, RoadInfo const & roadInfo) { - ForEachEdge(roadInfo, [&featureId, &roadInfo, this](size_t segId, m2::PointD const & endPoint, bool forward) + ForEachEdge(roadInfo, [&featureId, &roadInfo, this](size_t segId, Junction const & endJunction, bool forward) { if (!forward || roadInfo.m_bidirectional || m_mode == IRoadGraph::Mode::IgnoreOnewayTag) - m_edges.emplace_back(featureId, !forward, segId, endPoint, m_cross); + m_edges.emplace_back(featureId, !forward, segId, endJunction, m_cross); }); } @@ -190,16 +190,14 @@ void IRoadGraph::GetIngoingEdges(Junction const & junction, TEdgeVector & edges) void IRoadGraph::GetRegularOutgoingEdges(Junction const & junction, TEdgeVector & edges) const { - m2::PointD const cross = junction.GetPoint(); - CrossOutgoingLoader loader(cross, GetMode(), edges); - ForEachFeatureClosestToCross(cross, loader); + CrossOutgoingLoader loader(junction, GetMode(), edges); + ForEachFeatureClosestToCross(junction.GetPoint(), loader); } void IRoadGraph::GetRegularIngoingEdges(Junction const & junction, TEdgeVector & edges) const { - m2::PointD const cross = junction.GetPoint(); - CrossIngoingLoader loader(cross, GetMode(), edges); - ForEachFeatureClosestToCross(cross, loader); + CrossIngoingLoader loader(junction, GetMode(), edges); + ForEachFeatureClosestToCross(junction.GetPoint(), loader); } void IRoadGraph::GetFakeOutgoingEdges(Junction const & junction, TEdgeVector & edges) const @@ -224,7 +222,7 @@ void IRoadGraph::ResetFakes() m_outgoingEdges.clear(); } -void IRoadGraph::AddFakeEdges(Junction const & junction, vector> const & vicinity) +void IRoadGraph::AddFakeEdges(Junction const & junction, vector> const & vicinity) { for (auto const & v : vicinity) { @@ -387,4 +385,15 @@ void IRoadGraph::GetEdgeTypes(Edge const & edge, feature::TypesHolder & types) c GetFeatureTypes(edge.GetFeatureId(), types); } +IRoadGraph::RoadInfo MakeRoadInfoForTesting(bool bidirectional, double speedKMPH, + initializer_list const & points) +{ + buffer_vector junctions; + for (auto const & p : points) + junctions.emplace_back(MakeJunctionForTesting(p)); + + IRoadGraph::RoadInfo ri(bidirectional, speedKMPH, {}); + ri.m_junctions.swap(junctions); + return ri; +} } // namespace routing diff --git a/routing/road_graph.hpp b/routing/road_graph.hpp index 528f471131..00b86e670f 100644 --- a/routing/road_graph.hpp +++ b/routing/road_graph.hpp @@ -20,7 +20,7 @@ class Junction { public: Junction(); - Junction(m2::PointD const & point); + Junction(m2::PointD const & point, feature::TAltitude altitude); Junction(Junction const &) = default; Junction & operator=(Junction const &) = default; @@ -28,14 +28,21 @@ public: inline bool operator<(Junction const & r) const { return m_point < r.m_point; } inline m2::PointD const & GetPoint() const { return m_point; } + inline feature::TAltitude GetAltitude() const { return m_altitude; } private: friend string DebugPrint(Junction const & r); // Point of the junction m2::PointD m_point; + feature::TAltitude m_altitude; }; +inline Junction MakeJunctionForTesting(m2::PointD const & point) +{ + return Junction(point, feature::kInvalidAltitude); +} + inline bool AlmostEqualAbs(Junction const & lhs, Junction const & rhs) { return my::AlmostEqualAbs(lhs.GetPoint(), rhs.GetPoint(), kPointsEqualEpsilon); @@ -102,12 +109,11 @@ public: { RoadInfo(); RoadInfo(RoadInfo && ri); - RoadInfo(bool bidirectional, double speedKMPH, initializer_list const & points); + RoadInfo(bool bidirectional, double speedKMPH, initializer_list const & points); RoadInfo(RoadInfo const &) = default; RoadInfo & operator=(RoadInfo const &) = default; - buffer_vector m_points; - feature::Altitudes m_altitudes; + buffer_vector m_junctions; double m_speedKMPH; bool m_bidirectional; }; @@ -116,7 +122,7 @@ public: class ICrossEdgesLoader { public: - ICrossEdgesLoader(m2::PointD const & cross, IRoadGraph::Mode mode, TEdgeVector & edges) + ICrossEdgesLoader(Junction const & cross, IRoadGraph::Mode mode, TEdgeVector & edges) : m_cross(cross), m_mode(mode), m_edges(edges) { } @@ -135,29 +141,29 @@ public: template void ForEachEdge(RoadInfo const & roadInfo, TFn && fn) { - for (size_t i = 0; i < roadInfo.m_points.size(); ++i) + for (size_t i = 0; i < roadInfo.m_junctions.size(); ++i) { - if (!my::AlmostEqualAbs(m_cross, roadInfo.m_points[i], kPointsEqualEpsilon)) + if (!my::AlmostEqualAbs(m_cross.GetPoint(), roadInfo.m_junctions[i].GetPoint(), kPointsEqualEpsilon)) continue; - if (i < roadInfo.m_points.size() - 1) + if (i < roadInfo.m_junctions.size() - 1) { // Head of the edge. // m_cross // o------------>o - fn(i, roadInfo.m_points[i + 1], true /* forward */); + fn(i, roadInfo.m_junctions[i + 1], true /* forward */); } if (i > 0) { // Tail of the edge. // m_cross // o------------>o - fn(i - 1, roadInfo.m_points[i - 1], false /* backward */); + fn(i - 1, roadInfo.m_junctions[i - 1], false /* backward */); } } } - m2::PointD const m_cross; + Junction const m_cross; IRoadGraph::Mode const m_mode; TEdgeVector & m_edges; }; @@ -165,7 +171,7 @@ public: class CrossOutgoingLoader : public ICrossEdgesLoader { public: - CrossOutgoingLoader(m2::PointD const & cross, IRoadGraph::Mode mode, TEdgeVector & edges) + CrossOutgoingLoader(Junction const & cross, IRoadGraph::Mode mode, TEdgeVector & edges) : ICrossEdgesLoader(cross, mode, edges) {} private: @@ -176,7 +182,7 @@ public: class CrossIngoingLoader : public ICrossEdgesLoader { public: - CrossIngoingLoader(m2::PointD const & cross, IRoadGraph::Mode mode, TEdgeVector & edges) + CrossIngoingLoader(Junction const & cross, IRoadGraph::Mode mode, TEdgeVector & edges) : ICrossEdgesLoader(cross, mode, edges) {} private: @@ -197,7 +203,7 @@ public: /// Adds fake edges from fake position rp to real vicinity /// positions. - void AddFakeEdges(Junction const & junction, vector> const & vicinities); + void AddFakeEdges(Junction const & junction, vector> const & vicinities); /// Returns RoadInfo for a road corresponding to featureId. virtual RoadInfo GetRoadInfo(FeatureID const & featureId) const = 0; @@ -219,7 +225,7 @@ public: /// @return Array of pairs of Edge and projection point on the Edge. If there is no the closest edges /// then returns empty array. virtual void FindClosestEdges(m2::PointD const & point, uint32_t count, - vector> & vicinities) const = 0; + vector> & vicinities) const = 0; /// @return Types for the specified feature virtual void GetFeatureTypes(FeatureID const & featureId, feature::TypesHolder & types) const = 0; @@ -251,4 +257,7 @@ private: // Map of outgoing edges for junction map m_outgoingEdges; }; + +IRoadGraph::RoadInfo MakeRoadInfoForTesting(bool bidirectional, double speedKMPH, + initializer_list const & points); } // namespace routing diff --git a/routing/road_graph_router.cpp b/routing/road_graph_router.cpp index 2539087a22..8970f54d07 100644 --- a/routing/road_graph_router.cpp +++ b/routing/road_graph_router.cpp @@ -39,7 +39,7 @@ size_t constexpr kTestConnectivityVisitJunctionsLimit = 25; uint64_t constexpr kMinPedestrianMwmVersion = 150713; // Check if the found edges lays on mwm with pedestrian routing support. -bool CheckMwmVersion(vector> const & vicinities, vector & mwmNames) +bool CheckMwmVersion(vector> const & vicinities, vector & mwmNames) { mwmNames.clear(); for (auto const & vicinity : vicinities) @@ -92,7 +92,7 @@ bool CheckGraphConnectivity(IRoadGraph const & graph, Junction const & junction, // Find closest candidates in the world graph void FindClosestEdges(IRoadGraph const & graph, m2::PointD const & point, - vector> & vicinity) + vector> & vicinity) { // WARNING: Take only one vicinity // It is an oversimplification that is not as easily @@ -101,7 +101,7 @@ void FindClosestEdges(IRoadGraph const & graph, m2::PointD const & point, // an obstacle. Using only the closest feature minimizes (but not // eliminates) this risk. - vector> candidates; + vector> candidates; graph.FindClosestEdges(point, kMaxRoadCandidates, candidates); vicinity.clear(); @@ -156,7 +156,7 @@ IRouter::ResultCode RoadGraphRouter::CalculateRoute(m2::PointD const & startPoin if (!CheckMapExistence(startPoint, route) || !CheckMapExistence(finalPoint, route)) return IRouter::RouteFileNotExist; - vector> finalVicinity; + vector> finalVicinity; FindClosestEdges(*m_roadGraph, finalPoint, finalVicinity); if (finalVicinity.empty()) @@ -170,7 +170,7 @@ IRouter::ResultCode RoadGraphRouter::CalculateRoute(m2::PointD const & startPoin route.AddAbsentCountry(name); } - vector> startVicinity; + vector> startVicinity; FindClosestEdges(*m_roadGraph, startPoint, startVicinity); if (startVicinity.empty()) @@ -186,8 +186,10 @@ IRouter::ResultCode RoadGraphRouter::CalculateRoute(m2::PointD const & startPoin if (!route.GetAbsentCountries().empty()) return IRouter::FileTooOld; - Junction const startPos(startPoint); - Junction const finalPos(finalPoint); + // Let us assume that the closest to startPoint/finalPoint feature point has the same altitude + // with startPoint/finalPoint. + Junction const startPos(startPoint, startVicinity.front().second.GetAltitude()); + Junction const finalPos(finalPoint, finalVicinity.front().second.GetAltitude()); m_roadGraph->ResetFakes(); m_roadGraph->AddFakeEdges(startPos, startVicinity); diff --git a/routing/routing_integration_tests/bicycle_turn_test.cpp b/routing/routing_integration_tests/bicycle_turn_test.cpp index 88fa24532d..350a29b0e4 100644 --- a/routing/routing_integration_tests/bicycle_turn_test.cpp +++ b/routing/routing_integration_tests/bicycle_turn_test.cpp @@ -59,6 +59,9 @@ UNIT_TEST(RussiaMoscowSevTushinoParkBicycleOnePointTurnTest) TRouteResult const routeResult = integration::CalculateRoute(integration::GetBicycleComponents(), point, {0.0, 0.0}, point); + Route const & route = *routeResult.first; + UNUSED_VALUE(route); + IRouter::ResultCode const result = routeResult.second; TEST_EQUAL(result, IRouter::IRouter::RouteNotFound, ()); } diff --git a/routing/routing_tests/astar_router_test.cpp b/routing/routing_tests/astar_router_test.cpp index cb15d76e58..f6372bf326 100644 --- a/routing/routing_tests/astar_router_test.cpp +++ b/routing/routing_tests/astar_router_test.cpp @@ -7,6 +7,7 @@ #include "routing/route.hpp" #include "routing/router_delegate.hpp" +#include "indexer/feature_altitude.hpp" #include "indexer/classificator_loader.hpp" #include "base/logging.hpp" @@ -39,36 +40,44 @@ void TestAStarRouterMock(Junction const & startPos, Junction const & finalPos, void AddRoad(RoadGraphMockSource & graph, double speedKMPH, initializer_list const & points) { - graph.AddRoad(IRoadGraph::RoadInfo(true /* bidir */, speedKMPH, points)); + graph.AddRoad(routing::MakeRoadInfoForTesting(true /* bidir */, speedKMPH, points)); } void AddRoad(RoadGraphMockSource & graph, initializer_list const & points) { double const speedKMPH = graph.GetMaxSpeedKMPH(); - graph.AddRoad(IRoadGraph::RoadInfo(true /* bidir */, speedKMPH, points)); + graph.AddRoad(routing::MakeRoadInfoForTesting(true /* bidir */, speedKMPH, points)); } } // namespace UNIT_TEST(AStarRouter_Graph2_Simple1) { - Junction const startPos = m2::PointD(0, 0); - Junction const finalPos = m2::PointD(80, 55); + Junction const startPos = MakeJunctionForTesting(m2::PointD(0, 0)); + Junction const finalPos = MakeJunctionForTesting(m2::PointD(80, 55)); - vector const expected = {m2::PointD(0, 0), m2::PointD(5, 10), m2::PointD(5, 40), - m2::PointD(18, 55), m2::PointD(39, 55), m2::PointD(80, 55)}; + vector const expected = {MakeJunctionForTesting(m2::PointD(0, 0)), + MakeJunctionForTesting(m2::PointD(5, 10)), + MakeJunctionForTesting(m2::PointD(5, 40)), + MakeJunctionForTesting(m2::PointD(18, 55)), + MakeJunctionForTesting(m2::PointD(39, 55)), + MakeJunctionForTesting(m2::PointD(80, 55))}; TestAStarRouterMock(startPos, finalPos, expected); } UNIT_TEST(AStarRouter_Graph2_Simple2) { - Junction const startPos = m2::PointD(80, 55); - Junction const finalPos = m2::PointD(80, 0); + Junction const startPos = MakeJunctionForTesting(m2::PointD(80, 55)); + Junction const finalPos = MakeJunctionForTesting(m2::PointD(80, 0)); - vector const expected = {m2::PointD(80, 55), m2::PointD(39, 55), m2::PointD(37, 30), - m2::PointD(70, 30), m2::PointD(70, 10), m2::PointD(70, 0), - m2::PointD(80, 0)}; + vector const expected = {MakeJunctionForTesting(m2::PointD(80, 55)), + MakeJunctionForTesting(m2::PointD(39, 55)), + MakeJunctionForTesting(m2::PointD(37, 30)), + MakeJunctionForTesting(m2::PointD(70, 30)), + MakeJunctionForTesting(m2::PointD(70, 10)), + MakeJunctionForTesting(m2::PointD(70, 0)), + MakeJunctionForTesting(m2::PointD(80, 0))}; TestAStarRouterMock(startPos, finalPos, expected); } @@ -85,10 +94,13 @@ UNIT_TEST(AStarRouter_SimpleGraph_RouteIsFound) AddRoad(graph, {m2::PointD(0, 60), m2::PointD(0, 30)}); // feature 4 AddRoad(graph, {m2::PointD(0, 30), m2::PointD(0, 0)}); // feature 5 - Junction const startPos = m2::PointD(0, 0); - Junction const finalPos = m2::PointD(40, 100); + Junction const startPos = MakeJunctionForTesting(m2::PointD(0, 0)); + Junction const finalPos = MakeJunctionForTesting(m2::PointD(40, 100)); - vector const expected = {m2::PointD(0, 0), m2::PointD(0, 30), m2::PointD(0, 60), m2::PointD(40, 100)}; + vector const expected = {MakeJunctionForTesting(m2::PointD(0, 0)), + MakeJunctionForTesting(m2::PointD(0, 30)), + MakeJunctionForTesting(m2::PointD(0, 60)), + MakeJunctionForTesting(m2::PointD(40, 100))}; RouterDelegate delegate; RoutingResult result; @@ -110,20 +122,28 @@ UNIT_TEST(AStarRouter_SimpleGraph_RoutesInConnectedComponents) // Roads in the first connected component. vector const roadInfo_1 = { - IRoadGraph::RoadInfo(true /* bidir */, speedKMPH, {m2::PointD(10, 10), m2::PointD(90, 10)}), // feature 0 - IRoadGraph::RoadInfo(true /* bidir */, speedKMPH, {m2::PointD(90, 10), m2::PointD(90, 90)}), // feature 1 - IRoadGraph::RoadInfo(true /* bidir */, speedKMPH, {m2::PointD(90, 90), m2::PointD(10, 90)}), // feature 2 - IRoadGraph::RoadInfo(true /* bidir */, speedKMPH, {m2::PointD(10, 90), m2::PointD(10, 10)}), // feature 3 + IRoadGraph::RoadInfo(true /* bidir */, speedKMPH, { + MakeJunctionForTesting(m2::PointD(10, 10)), MakeJunctionForTesting(m2::PointD(90, 10))}), // feature 0 + IRoadGraph::RoadInfo(true /* bidir */, speedKMPH, { + MakeJunctionForTesting(m2::PointD(90, 10)), MakeJunctionForTesting(m2::PointD(90, 90))}), // feature 1 + IRoadGraph::RoadInfo(true /* bidir */, speedKMPH, { + MakeJunctionForTesting(m2::PointD(90, 90)), MakeJunctionForTesting(m2::PointD(10, 90))}), // feature 2 + IRoadGraph::RoadInfo(true /* bidir */, speedKMPH, { + MakeJunctionForTesting(m2::PointD(10, 90)), MakeJunctionForTesting(m2::PointD(10, 10))}), // feature 3 }; vector const featureId_1 = { 0, 1, 2, 3 }; // featureIDs in the first connected component // Roads in the second connected component. vector const roadInfo_2 = { - IRoadGraph::RoadInfo(true /* bidir */, speedKMPH, {m2::PointD(30, 30), m2::PointD(70, 30)}), // feature 4 - IRoadGraph::RoadInfo(true /* bidir */, speedKMPH, {m2::PointD(70, 30), m2::PointD(70, 70)}), // feature 5 - IRoadGraph::RoadInfo(true /* bidir */, speedKMPH, {m2::PointD(70, 70), m2::PointD(30, 70)}), // feature 6 - IRoadGraph::RoadInfo(true /* bidir */, speedKMPH, {m2::PointD(30, 70), m2::PointD(30, 30)}), // feature 7 + IRoadGraph::RoadInfo(true /* bidir */, speedKMPH, { + MakeJunctionForTesting(m2::PointD(30, 30)), MakeJunctionForTesting(m2::PointD(70, 30))}), // feature 4 + IRoadGraph::RoadInfo(true /* bidir */, speedKMPH, { + MakeJunctionForTesting(m2::PointD(70, 30)), MakeJunctionForTesting(m2::PointD(70, 70))}), // feature 5 + IRoadGraph::RoadInfo(true /* bidir */, speedKMPH, { + MakeJunctionForTesting(m2::PointD(70, 70)), MakeJunctionForTesting(m2::PointD(30, 70))}), // feature 6 + IRoadGraph::RoadInfo(true /* bidir */, speedKMPH, { + MakeJunctionForTesting(m2::PointD(30, 70)), MakeJunctionForTesting(m2::PointD(30, 30))}), // feature 7 }; vector const featureId_2 = { 4, 5, 6, 7 }; // featureIDs in the second connected component @@ -141,11 +161,11 @@ UNIT_TEST(AStarRouter_SimpleGraph_RoutesInConnectedComponents) // Check if there is no any route between points in different connected components. for (size_t i = 0; i < roadInfo_1.size(); ++i) { - Junction const startPos(roadInfo_1[i].m_points[0]); + Junction const startPos = roadInfo_1[i].m_junctions[0]; for (size_t j = 0; j < roadInfo_2.size(); ++j) { RouterDelegate delegate; - Junction const finalPos(roadInfo_2[j].m_points[0]); + Junction const finalPos = roadInfo_2[j].m_junctions[0]; RoutingResult result; TEST_EQUAL(TRoutingAlgorithm::Result::NoPath, algorithm.CalculateRoute(graph, startPos, finalPos, delegate, result), ()); @@ -157,11 +177,11 @@ UNIT_TEST(AStarRouter_SimpleGraph_RoutesInConnectedComponents) // Check if there is route between points in the first connected component. for (size_t i = 0; i < roadInfo_1.size(); ++i) { - Junction const startPos(roadInfo_1[i].m_points[0]); + Junction const startPos = roadInfo_1[i].m_junctions[0]; for (size_t j = i + 1; j < roadInfo_1.size(); ++j) { RouterDelegate delegate; - Junction const finalPos(roadInfo_1[j].m_points[0]); + Junction const finalPos = roadInfo_1[j].m_junctions[0]; RoutingResult result; TEST_EQUAL(TRoutingAlgorithm::Result::OK, algorithm.CalculateRoute(graph, startPos, finalPos, delegate, result), ()); @@ -173,11 +193,11 @@ UNIT_TEST(AStarRouter_SimpleGraph_RoutesInConnectedComponents) // Check if there is route between points in the second connected component. for (size_t i = 0; i < roadInfo_2.size(); ++i) { - Junction const startPos(roadInfo_2[i].m_points[0]); + Junction const startPos = roadInfo_2[i].m_junctions[0]; for (size_t j = i + 1; j < roadInfo_2.size(); ++j) { RouterDelegate delegate; - Junction const finalPos(roadInfo_2[j].m_points[0]); + Junction const finalPos = roadInfo_2[j].m_junctions[0]; RoutingResult result; TEST_EQUAL(TRoutingAlgorithm::Result::OK, algorithm.CalculateRoute(graph, startPos, finalPos, delegate, result), ()); @@ -209,10 +229,16 @@ UNIT_TEST(AStarRouter_SimpleGraph_PickTheFasterRoad1) RoutingResult result; TRoutingAlgorithm algorithm; TEST_EQUAL(TRoutingAlgorithm::Result::OK, - algorithm.CalculateRoute(graph, m2::PointD(2, 2), m2::PointD(10, 2), delegate, result), + algorithm.CalculateRoute(graph, MakeJunctionForTesting(m2::PointD(2, 2)), + MakeJunctionForTesting(m2::PointD(10, 2)), delegate, result), ()); - TEST_EQUAL(result.path, vector({m2::PointD(2,2), m2::PointD(2,3), m2::PointD(4,3), m2::PointD(6,3), - m2::PointD(8,3), m2::PointD(10,3), m2::PointD(10,2)}), ()); + TEST_EQUAL(result.path, vector({MakeJunctionForTesting(m2::PointD(2,2)), + MakeJunctionForTesting(m2::PointD(2,3)), + MakeJunctionForTesting(m2::PointD(4,3)), + MakeJunctionForTesting(m2::PointD(6,3)), + MakeJunctionForTesting(m2::PointD(8,3)), + MakeJunctionForTesting(m2::PointD(10,3)), + MakeJunctionForTesting(m2::PointD(10,2))}), ()); TEST(my::AlmostEqualAbs(result.distance, 800451., 1.), ("Distance error:", result.distance)); } @@ -237,9 +263,12 @@ UNIT_TEST(AStarRouter_SimpleGraph_PickTheFasterRoad2) RoutingResult result; TRoutingAlgorithm algorithm; TEST_EQUAL(TRoutingAlgorithm::Result::OK, - algorithm.CalculateRoute(graph, m2::PointD(2, 2), m2::PointD(10, 2), delegate, result), + algorithm.CalculateRoute(graph, MakeJunctionForTesting(m2::PointD(2, 2)), + MakeJunctionForTesting(m2::PointD(10, 2)), delegate, result), ()); - TEST_EQUAL(result.path, vector({m2::PointD(2,2), m2::PointD(6,2), m2::PointD(10,2)}), ()); + TEST_EQUAL(result.path, vector({MakeJunctionForTesting(m2::PointD(2,2)), + MakeJunctionForTesting(m2::PointD(6,2)), + MakeJunctionForTesting(m2::PointD(10,2))}), ()); TEST(my::AlmostEqualAbs(result.distance, 781458., 1.), ("Distance error:", result.distance)); } @@ -264,8 +293,12 @@ UNIT_TEST(AStarRouter_SimpleGraph_PickTheFasterRoad3) RoutingResult result; TRoutingAlgorithm algorithm; TEST_EQUAL(TRoutingAlgorithm::Result::OK, - algorithm.CalculateRoute(graph, m2::PointD(2, 2), m2::PointD(10, 2), delegate, result), + algorithm.CalculateRoute(graph, MakeJunctionForTesting(m2::PointD(2, 2)), + MakeJunctionForTesting(m2::PointD(10, 2)), delegate, result), ()); - TEST_EQUAL(result.path, vector({m2::PointD(2,2), m2::PointD(2,1), m2::PointD(10,1), m2::PointD(10,2)}), ()); + TEST_EQUAL(result.path, vector({MakeJunctionForTesting(m2::PointD(2,2)), + MakeJunctionForTesting(m2::PointD(2,1)), + MakeJunctionForTesting(m2::PointD(10,1)), + MakeJunctionForTesting(m2::PointD(10,2))}), ()); TEST(my::AlmostEqualAbs(result.distance, 814412., 1.), ("Distance error:", result.distance)); } diff --git a/routing/routing_tests/nearest_edge_finder_tests.cpp b/routing/routing_tests/nearest_edge_finder_tests.cpp index 0a90d400bb..978f3531c2 100644 --- a/routing/routing_tests/nearest_edge_finder_tests.cpp +++ b/routing/routing_tests/nearest_edge_finder_tests.cpp @@ -8,7 +8,7 @@ using namespace routing; using namespace routing_test; void TestNearestOnMock1(m2::PointD const & point, size_t const candidatesCount, - vector> const & expected) + vector> const & expected) { unique_ptr graph(new RoadGraphMockSource()); InitRoadGraphMockSourceWithTest1(*graph); @@ -20,7 +20,7 @@ void TestNearestOnMock1(m2::PointD const & point, size_t const candidatesCount, finder.AddInformationSource(featureId, graph->GetRoadInfo(featureId)); } - vector> result; + vector> result; TEST(finder.HasCandidates(), ()); finder.MakeResult(result, candidatesCount); @@ -29,28 +29,36 @@ void TestNearestOnMock1(m2::PointD const & point, size_t const candidatesCount, UNIT_TEST(StarterPosAtBorder_Mock1Graph) { - vector> const expected = + vector> const expected = { - make_pair(Edge(MakeTestFeatureID(0), true /* forward */, 0, m2::PointD(0, 0), m2::PointD(5, 0)), m2::PointD(0, 0)) + make_pair(Edge(MakeTestFeatureID(0), true /* forward */, 0, + MakeJunctionForTesting(m2::PointD(0, 0)), MakeJunctionForTesting(m2::PointD(5, 0))), + MakeJunctionForTesting(m2::PointD(0, 0))) }; TestNearestOnMock1(m2::PointD(0, 0), 1, expected); } UNIT_TEST(MiddleEdgeTest_Mock1Graph) { - vector> const expected = + vector> const expected = { - make_pair(Edge(MakeTestFeatureID(0), true /* forward */, 0, m2::PointD(0, 0), m2::PointD(5, 0)), m2::PointD(3, 0)) + make_pair(Edge(MakeTestFeatureID(0), true /* forward */, 0, + MakeJunctionForTesting(m2::PointD(0, 0)), MakeJunctionForTesting(m2::PointD(5, 0))), + MakeJunctionForTesting(m2::PointD(3, 0))) }; TestNearestOnMock1(m2::PointD(3, 3), 1, expected); } UNIT_TEST(MiddleSegmentTest_Mock1Graph) { - vector> const expected = + vector> const expected = { - make_pair(Edge(MakeTestFeatureID(0), true /* forward */, 2, m2::PointD(10, 0), m2::PointD(15, 0)), m2::PointD(12.5, 0)), - make_pair(Edge(MakeTestFeatureID(1), true /* forward */, 2, m2::PointD(10, 0), m2::PointD(10, 5)), m2::PointD(10, 2.5)) + make_pair(Edge(MakeTestFeatureID(0), true /* forward */, 2, + MakeJunctionForTesting(m2::PointD(10, 0)), MakeJunctionForTesting(m2::PointD(15, 0))), + MakeJunctionForTesting(m2::PointD(12.5, 0))), + make_pair(Edge(MakeTestFeatureID(1), true /* forward */, 2, + MakeJunctionForTesting(m2::PointD(10, 0)), MakeJunctionForTesting(m2::PointD(10, 5))), + MakeJunctionForTesting(m2::PointD(10, 2.5))) }; TestNearestOnMock1(m2::PointD(12.5, 2.5), 2, expected); } diff --git a/routing/routing_tests/road_graph_builder.cpp b/routing/routing_tests/road_graph_builder.cpp index 158dec6321..74ee0986d2 100644 --- a/routing/routing_tests/road_graph_builder.cpp +++ b/routing/routing_tests/road_graph_builder.cpp @@ -1,5 +1,7 @@ #include "road_graph_builder.hpp" +#include "routing/road_graph.hpp" + #include "indexer/mwm_set.hpp" #include "base/macros.hpp" @@ -62,7 +64,7 @@ namespace routing_test void RoadGraphMockSource::AddRoad(RoadInfo && ri) { - CHECK_GREATER_OR_EQUAL(ri.m_points.size(), 2, ("Empty road")); + CHECK_GREATER_OR_EQUAL(ri.m_junctions.size(), 2, ("Empty road")); m_roads.push_back(move(ri)); } @@ -91,7 +93,7 @@ void RoadGraphMockSource::ForEachFeatureClosestToCross(m2::PointD const & /* cro } void RoadGraphMockSource::FindClosestEdges(m2::PointD const & point, uint32_t count, - vector> & vicinities) const + vector> & vicinities) const { UNUSED_VALUE(point); UNUSED_VALUE(count); @@ -128,34 +130,34 @@ void InitRoadGraphMockSourceWithTest1(RoadGraphMockSource & src) IRoadGraph::RoadInfo ri0; ri0.m_bidirectional = true; ri0.m_speedKMPH = speedKMPH; - ri0.m_points.push_back(m2::PointD(0, 0)); - ri0.m_points.push_back(m2::PointD(5, 0)); - ri0.m_points.push_back(m2::PointD(10, 0)); - ri0.m_points.push_back(m2::PointD(15, 0)); - ri0.m_points.push_back(m2::PointD(20, 0)); + ri0.m_junctions.push_back(MakeJunctionForTesting(m2::PointD(0, 0))); + ri0.m_junctions.push_back(MakeJunctionForTesting(m2::PointD(5, 0))); + ri0.m_junctions.push_back(MakeJunctionForTesting(m2::PointD(10, 0))); + ri0.m_junctions.push_back(MakeJunctionForTesting(m2::PointD(15, 0))); + ri0.m_junctions.push_back(MakeJunctionForTesting(m2::PointD(20, 0))); IRoadGraph::RoadInfo ri1; ri1.m_bidirectional = true; ri1.m_speedKMPH = speedKMPH; - ri1.m_points.push_back(m2::PointD(10, -10)); - ri1.m_points.push_back(m2::PointD(10, -5)); - ri1.m_points.push_back(m2::PointD(10, 0)); - ri1.m_points.push_back(m2::PointD(10, 5)); - ri1.m_points.push_back(m2::PointD(10, 10)); + ri1.m_junctions.push_back(MakeJunctionForTesting(m2::PointD(10, -10))); + ri1.m_junctions.push_back(MakeJunctionForTesting(m2::PointD(10, -5))); + ri1.m_junctions.push_back(MakeJunctionForTesting(m2::PointD(10, 0))); + ri1.m_junctions.push_back(MakeJunctionForTesting(m2::PointD(10, 5))); + ri1.m_junctions.push_back(MakeJunctionForTesting(m2::PointD(10, 10))); IRoadGraph::RoadInfo ri2; ri2.m_bidirectional = true; ri2.m_speedKMPH = speedKMPH; - ri2.m_points.push_back(m2::PointD(15, -5)); - ri2.m_points.push_back(m2::PointD(15, 0)); + ri2.m_junctions.push_back(MakeJunctionForTesting(m2::PointD(15, -5))); + ri2.m_junctions.push_back(MakeJunctionForTesting(m2::PointD(15, 0))); IRoadGraph::RoadInfo ri3; ri3.m_bidirectional = true; ri3.m_speedKMPH = speedKMPH; - ri3.m_points.push_back(m2::PointD(20, 0)); - ri3.m_points.push_back(m2::PointD(25, 5)); - ri3.m_points.push_back(m2::PointD(15, 5)); - ri3.m_points.push_back(m2::PointD(20, 0)); + ri3.m_junctions.push_back(MakeJunctionForTesting(m2::PointD(20, 0))); + ri3.m_junctions.push_back(MakeJunctionForTesting(m2::PointD(25, 5))); + ri3.m_junctions.push_back(MakeJunctionForTesting(m2::PointD(15, 5))); + ri3.m_junctions.push_back(MakeJunctionForTesting(m2::PointD(20, 0))); src.AddRoad(move(ri0)); src.AddRoad(move(ri1)); @@ -170,72 +172,72 @@ void InitRoadGraphMockSourceWithTest2(RoadGraphMockSource & graph) IRoadGraph::RoadInfo ri0; ri0.m_bidirectional = true; ri0.m_speedKMPH = speedKMPH; - ri0.m_points.push_back(m2::PointD(0, 0)); - ri0.m_points.push_back(m2::PointD(10, 0)); - ri0.m_points.push_back(m2::PointD(25, 0)); - ri0.m_points.push_back(m2::PointD(35, 0)); - ri0.m_points.push_back(m2::PointD(70, 0)); - ri0.m_points.push_back(m2::PointD(80, 0)); + ri0.m_junctions.push_back(MakeJunctionForTesting(m2::PointD(0, 0))); + ri0.m_junctions.push_back(MakeJunctionForTesting(m2::PointD(10, 0))); + ri0.m_junctions.push_back(MakeJunctionForTesting(m2::PointD(25, 0))); + ri0.m_junctions.push_back(MakeJunctionForTesting(m2::PointD(35, 0))); + ri0.m_junctions.push_back(MakeJunctionForTesting(m2::PointD(70, 0))); + ri0.m_junctions.push_back(MakeJunctionForTesting(m2::PointD(80, 0))); IRoadGraph::RoadInfo ri1; ri1.m_bidirectional = true; ri1.m_speedKMPH = speedKMPH; - ri1.m_points.push_back(m2::PointD(0, 0)); - ri1.m_points.push_back(m2::PointD(5, 10)); - ri1.m_points.push_back(m2::PointD(5, 40)); + ri1.m_junctions.push_back(MakeJunctionForTesting(m2::PointD(0, 0))); + ri1.m_junctions.push_back(MakeJunctionForTesting(m2::PointD(5, 10))); + ri1.m_junctions.push_back(MakeJunctionForTesting(m2::PointD(5, 40))); IRoadGraph::RoadInfo ri2; ri2.m_bidirectional = true; ri2.m_speedKMPH = speedKMPH; - ri2.m_points.push_back(m2::PointD(12, 25)); - ri2.m_points.push_back(m2::PointD(10, 10)); - ri2.m_points.push_back(m2::PointD(10, 0)); + ri2.m_junctions.push_back(MakeJunctionForTesting(m2::PointD(12, 25))); + ri2.m_junctions.push_back(MakeJunctionForTesting(m2::PointD(10, 10))); + ri2.m_junctions.push_back(MakeJunctionForTesting(m2::PointD(10, 0))); IRoadGraph::RoadInfo ri3; ri3.m_bidirectional = true; ri3.m_speedKMPH = speedKMPH; - ri3.m_points.push_back(m2::PointD(5, 10)); - ri3.m_points.push_back(m2::PointD(10, 10)); - ri3.m_points.push_back(m2::PointD(70, 10)); - ri3.m_points.push_back(m2::PointD(80, 10)); + ri3.m_junctions.push_back(MakeJunctionForTesting(m2::PointD(5, 10))); + ri3.m_junctions.push_back(MakeJunctionForTesting(m2::PointD(10, 10))); + ri3.m_junctions.push_back(MakeJunctionForTesting(m2::PointD(70, 10))); + ri3.m_junctions.push_back(MakeJunctionForTesting(m2::PointD(80, 10))); IRoadGraph::RoadInfo ri4; ri4.m_bidirectional = true; ri4.m_speedKMPH = speedKMPH; - ri4.m_points.push_back(m2::PointD(25, 0)); - ri4.m_points.push_back(m2::PointD(27, 25)); + ri4.m_junctions.push_back(MakeJunctionForTesting(m2::PointD(25, 0))); + ri4.m_junctions.push_back(MakeJunctionForTesting(m2::PointD(27, 25))); IRoadGraph::RoadInfo ri5; ri5.m_bidirectional = true; ri5.m_speedKMPH = speedKMPH; - ri5.m_points.push_back(m2::PointD(35, 0)); - ri5.m_points.push_back(m2::PointD(37, 30)); - ri5.m_points.push_back(m2::PointD(70, 30)); - ri5.m_points.push_back(m2::PointD(80, 30)); + ri5.m_junctions.push_back(MakeJunctionForTesting(m2::PointD(35, 0))); + ri5.m_junctions.push_back(MakeJunctionForTesting(m2::PointD(37, 30))); + ri5.m_junctions.push_back(MakeJunctionForTesting(m2::PointD(70, 30))); + ri5.m_junctions.push_back(MakeJunctionForTesting(m2::PointD(80, 30))); IRoadGraph::RoadInfo ri6; ri6.m_bidirectional = true; ri6.m_speedKMPH = speedKMPH; - ri6.m_points.push_back(m2::PointD(70, 0)); - ri6.m_points.push_back(m2::PointD(70, 10)); - ri6.m_points.push_back(m2::PointD(70, 30)); + ri6.m_junctions.push_back(MakeJunctionForTesting(m2::PointD(70, 0))); + ri6.m_junctions.push_back(MakeJunctionForTesting(m2::PointD(70, 10))); + ri6.m_junctions.push_back(MakeJunctionForTesting(m2::PointD(70, 30))); IRoadGraph::RoadInfo ri7; ri7.m_bidirectional = true; ri7.m_speedKMPH = speedKMPH; - ri7.m_points.push_back(m2::PointD(39, 55)); - ri7.m_points.push_back(m2::PointD(80, 55)); + ri7.m_junctions.push_back(MakeJunctionForTesting(m2::PointD(39, 55))); + ri7.m_junctions.push_back(MakeJunctionForTesting(m2::PointD(80, 55))); IRoadGraph::RoadInfo ri8; ri8.m_bidirectional = true; ri8.m_speedKMPH = speedKMPH; - ri8.m_points.push_back(m2::PointD(5, 40)); - ri8.m_points.push_back(m2::PointD(18, 55)); - ri8.m_points.push_back(m2::PointD(39, 55)); - ri8.m_points.push_back(m2::PointD(37, 30)); - ri8.m_points.push_back(m2::PointD(27, 25)); - ri8.m_points.push_back(m2::PointD(12, 25)); - ri8.m_points.push_back(m2::PointD(5, 40)); + ri8.m_junctions.push_back(MakeJunctionForTesting(m2::PointD(5, 40))); + ri8.m_junctions.push_back(MakeJunctionForTesting(m2::PointD(18, 55))); + ri8.m_junctions.push_back(MakeJunctionForTesting(m2::PointD(39, 55))); + ri8.m_junctions.push_back(MakeJunctionForTesting(m2::PointD(37, 30))); + ri8.m_junctions.push_back(MakeJunctionForTesting(m2::PointD(27, 25))); + ri8.m_junctions.push_back(MakeJunctionForTesting(m2::PointD(12, 25))); + ri8.m_junctions.push_back(MakeJunctionForTesting(m2::PointD(5, 40))); graph.AddRoad(move(ri0)); graph.AddRoad(move(ri1)); diff --git a/routing/routing_tests/road_graph_builder.hpp b/routing/routing_tests/road_graph_builder.hpp index bb7c2a6240..dd478cbdf8 100644 --- a/routing/routing_tests/road_graph_builder.hpp +++ b/routing/routing_tests/road_graph_builder.hpp @@ -19,7 +19,7 @@ public: void ForEachFeatureClosestToCross(m2::PointD const & cross, ICrossEdgesLoader & edgeLoader) const override; void FindClosestEdges(m2::PointD const & point, uint32_t count, - vector> & vicinities) const override; + vector> & vicinities) const override; void GetFeatureTypes(FeatureID const & featureId, feature::TypesHolder & types) const override; void GetJunctionTypes(routing::Junction const & junction, feature::TypesHolder & types) const override; routing::IRoadGraph::Mode GetMode() const override; diff --git a/routing/routing_tests/road_graph_nearest_edges_test.cpp b/routing/routing_tests/road_graph_nearest_edges_test.cpp index e1f3424acf..757c7623ea 100644 --- a/routing/routing_tests/road_graph_nearest_edges_test.cpp +++ b/routing/routing_tests/road_graph_nearest_edges_test.cpp @@ -30,20 +30,20 @@ UNIT_TEST(RoadGraph_NearestEdges) RoadGraphMockSource graph; { IRoadGraph::RoadInfo ri0; - ri0.m_points.emplace_back(-2, 0); - ri0.m_points.emplace_back(-1, 0); - ri0.m_points.emplace_back(0, 0); - ri0.m_points.emplace_back(1, 0); - ri0.m_points.emplace_back(2, 0); + ri0.m_junctions.push_back(MakeJunctionForTesting(m2::PointD(-2, 0))); + ri0.m_junctions.push_back(MakeJunctionForTesting(m2::PointD(-1, 0))); + ri0.m_junctions.push_back(MakeJunctionForTesting(m2::PointD(0, 0))); + ri0.m_junctions.push_back(MakeJunctionForTesting(m2::PointD(1, 0))); + ri0.m_junctions.push_back(MakeJunctionForTesting(m2::PointD(2, 0))); ri0.m_speedKMPH = 5; ri0.m_bidirectional = true; IRoadGraph::RoadInfo ri1; - ri1.m_points.emplace_back(0, -2); - ri1.m_points.emplace_back(0, -1); - ri1.m_points.emplace_back(0, 0); - ri1.m_points.emplace_back(0, 1); - ri1.m_points.emplace_back(0, 2); + ri1.m_junctions.push_back(MakeJunctionForTesting(m2::PointD(0, -2))); + ri1.m_junctions.push_back(MakeJunctionForTesting(m2::PointD(0, -1))); + ri1.m_junctions.push_back(MakeJunctionForTesting(m2::PointD(0, 0))); + ri1.m_junctions.push_back(MakeJunctionForTesting(m2::PointD(0, 1))); + ri1.m_junctions.push_back(MakeJunctionForTesting(m2::PointD(0, 2))); ri1.m_speedKMPH = 5; ri1.m_bidirectional = true; @@ -52,25 +52,33 @@ UNIT_TEST(RoadGraph_NearestEdges) } // We are standing at x junction. - Junction const crossPos(m2::PointD(0, 0)); + Junction const crossPos = MakeJunctionForTesting(m2::PointD(0, 0)); // Expected outgoing edges. IRoadGraph::TEdgeVector expectedOutgoing = { - Edge(MakeTestFeatureID(0) /* first road */, false /* forward */, 1 /* segId */, m2::PointD(0, 0), m2::PointD(-1, 0)), - Edge(MakeTestFeatureID(0) /* first road */, true /* forward */, 2 /* segId */, m2::PointD(0, 0), m2::PointD(1, 0)), - Edge(MakeTestFeatureID(1) /* second road */, false /* forward */, 1 /* segId */, m2::PointD(0, 0), m2::PointD(0, -1)), - Edge(MakeTestFeatureID(1) /* second road */, true /* forward */, 2 /* segId */, m2::PointD(0, 0), m2::PointD(0, 1)), + Edge(MakeTestFeatureID(0) /* first road */, false /* forward */, 1 /* segId */, + MakeJunctionForTesting(m2::PointD(0, 0)), MakeJunctionForTesting(m2::PointD(-1, 0))), + Edge(MakeTestFeatureID(0) /* first road */, true /* forward */, 2 /* segId */, + MakeJunctionForTesting(m2::PointD(0, 0)), MakeJunctionForTesting(m2::PointD(1, 0))), + Edge(MakeTestFeatureID(1) /* second road */, false /* forward */, 1 /* segId */, + MakeJunctionForTesting(m2::PointD(0, 0)), MakeJunctionForTesting(m2::PointD(0, -1))), + Edge(MakeTestFeatureID(1) /* second road */, true /* forward */, 2 /* segId */, + MakeJunctionForTesting(m2::PointD(0, 0)), MakeJunctionForTesting(m2::PointD(0, 1))), }; sort(expectedOutgoing.begin(), expectedOutgoing.end()); // Expected ingoing edges. IRoadGraph::TEdgeVector expectedIngoing = { - Edge(MakeTestFeatureID(0) /* first road */, true /* forward */, 1 /* segId */, m2::PointD(-1, 0), m2::PointD(0, 0)), - Edge(MakeTestFeatureID(0) /* first road */, false /* forward */, 2 /* segId */, m2::PointD(1, 0), m2::PointD(0, 0)), - Edge(MakeTestFeatureID(1) /* second road */, true /* forward */, 1 /* segId */, m2::PointD(0, -1), m2::PointD(0, 0)), - Edge(MakeTestFeatureID(1) /* second road */, false /* forward */, 2 /* segId */, m2::PointD(0, 1), m2::PointD(0, 0)), + Edge(MakeTestFeatureID(0) /* first road */, true /* forward */, 1 /* segId */, + MakeJunctionForTesting(m2::PointD(-1, 0)), MakeJunctionForTesting(m2::PointD(0, 0))), + Edge(MakeTestFeatureID(0) /* first road */, false /* forward */, 2 /* segId */, + MakeJunctionForTesting(m2::PointD(1, 0)), MakeJunctionForTesting(m2::PointD(0, 0))), + Edge(MakeTestFeatureID(1) /* second road */, true /* forward */, 1 /* segId */, + MakeJunctionForTesting(m2::PointD(0, -1)), MakeJunctionForTesting(m2::PointD(0, 0))), + Edge(MakeTestFeatureID(1) /* second road */, false /* forward */, 2 /* segId */, + MakeJunctionForTesting(m2::PointD(0, 1)), MakeJunctionForTesting(m2::PointD(0, 0))), }; sort(expectedIngoing.begin(), expectedIngoing.end());