MCPcopy Create free account
hub / github.com/comaps/comaps / CalculateRoute

Method CalculateRoute

libs/routing/ruler_router.cpp:58–116  ·  view source on GitHub ↗

Ruler router doesn't read roads graph and uses only checkpoints to build a route. 1-----------2 / \ / \ / F S For example we need to build route from start (S) to finish (F) with intermediate points (1) and (2). Target route should have parameters: m_geometry = [S, S, 1, 1, 2, 2, F, F] m_routeSegments = [S, 1, 1, 2, 2,

Source from the content-addressed store, hash-verified

56
57 */
58RouterResultCode RulerRouter::CalculateRoute(Checkpoints const & checkpoints, m2::PointD const & startDirection,
59 bool adjustToPrevRoute, RouterDelegate const & delegate, Route & route)
60{
61 vector<m2::PointD> const & points = checkpoints.GetPoints();
62 size_t const count = points.size();
63 ASSERT(count > 0, ());
64
65 vector<RouteSegment> routeSegments;
66 routeSegments.reserve(count * 2 - 1);
67 vector<double> times;
68 times.reserve(count * 2 - 1);
69
70 Segment const segment(kFakeNumMwmId, 0, 0, false);
71
72 auto const ToPointWA = [](m2::PointD const & p) { return geometry::PointWithAltitude(p, 0 /* altitude */); };
73
74 for (uint32_t i = 0; i < count; ++i)
75 {
76 turns::TurnItem turn(i, turns::PedestrianDirection::None);
77 geometry::PointWithAltitude const junction = ToPointWA(points[i]);
78 RouteSegment::RoadNameInfo const roadNameInfo;
79
80 auto routeSegment = RouteSegment(segment, turn, junction, roadNameInfo);
81 routeSegments.emplace_back(segment, turn, junction, roadNameInfo);
82 times.push_back(0);
83
84 if (i == count - 1)
85 turn = turns::TurnItem(i + 1, turns::PedestrianDirection::ReachedYourDestination);
86 else if (i == 0)
87 continue;
88
89 routeSegments.emplace_back(segment, turn, junction, roadNameInfo);
90 times.push_back(0);
91 }
92
93 FillSegmentInfo(times, routeSegments);
94 route.SetRouteSegments(std::move(routeSegments));
95
96 vector<Route::SubrouteAttrs> subroutes;
97 for (size_t i = 1; i < count; ++i)
98 {
99 subroutes.emplace_back(ToPointWA(points[i - 1]), ToPointWA(points[i]), i * 2 - 2, i * 2);
100 subroutes.emplace_back(ToPointWA(points[i - 1]), ToPointWA(points[i]), i * 2 - 1, i * 2);
101 }
102
103 route.SetCurrentSubrouteIdx(checkpoints.GetPassedIdx());
104 route.SetSubroteAttrs(std::move(subroutes));
105
106 vector<m2::PointD> routeGeometry;
107 for (auto p : points)
108 {
109 routeGeometry.push_back(p);
110 routeGeometry.push_back(p);
111 }
112
113 route.SetGeometry(routeGeometry.begin(), routeGeometry.end());
114
115 return RouterResultCode::NoError;

Callers

nothing calls this directly

Calls 15

ASSERTFunction · 0.85
FillSegmentInfoFunction · 0.85
SetRouteSegmentsMethod · 0.80
SetCurrentSubrouteIdxMethod · 0.80
GetPassedIdxMethod · 0.80
SetSubroteAttrsMethod · 0.80
RouteSegmentClass · 0.70
TurnItemClass · 0.70
PointWithAltitudeClass · 0.50
sizeMethod · 0.45
reserveMethod · 0.45
emplace_backMethod · 0.45

Tested by

no test coverage detected