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

Function CreateDrapeSubroute

libs/map/routing_manager.cpp:240–325  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

238}
239
240drape_ptr<df::Subroute> CreateDrapeSubroute(vector<RouteSegment> const & segments, m2::PointD const & startPt,
241 double baseDistance, double baseDepth, routing::RouterType routerType)
242{
243 auto subroute = make_unique_dp<df::Subroute>();
244 subroute->m_baseDistance = baseDistance;
245 subroute->m_baseDepthIndex = baseDepth;
246
247 auto constexpr kBias = 1.0;
248
249 if (routerType == RouterType::Transit)
250 {
251 subroute->m_headFakeDistance = -kBias;
252 subroute->m_tailFakeDistance = kBias;
253 subroute->m_polyline.Add(startPt);
254 return subroute;
255 }
256
257 vector<m2::PointD> points;
258 points.reserve(segments.size() + 1);
259 points.push_back(startPt);
260 for (auto const & s : segments)
261 points.push_back(s.GetJunction().GetPoint());
262
263 if (points.size() < 2)
264 {
265 LOG(LWARNING, ("Invalid subroute. Points number =", points.size()));
266 return nullptr;
267 }
268
269 if (routerType == RouterType::Ruler)
270 {
271 auto const subrouteLen = segments.back().GetDistFromBeginningMerc() - baseDistance;
272 subroute->m_headFakeDistance = -kBias;
273 subroute->m_tailFakeDistance = subrouteLen + kBias;
274 subroute->m_polyline = m2::PolylineD(std::move(points));
275 return subroute;
276 }
277
278 // We support visualization of fake edges only in the head and in the tail of subroute.
279 auto constexpr kInvalidId = std::numeric_limits<size_t>::max();
280 auto firstReal = kInvalidId;
281 auto lastReal = kInvalidId;
282 for (size_t i = 0; i < segments.size(); ++i)
283 {
284 if (!segments[i].GetSegment().IsRealSegment())
285 continue;
286
287 if (firstReal == kInvalidId)
288 firstReal = i;
289 lastReal = i;
290 }
291
292 if (firstReal == kInvalidId)
293 {
294 // All segments are fake.
295 subroute->m_headFakeDistance = 0.0;
296 subroute->m_tailFakeDistance = 0.0;
297 }

Callers 1

InsertRouteMethod · 0.85

Calls 10

backMethod · 0.80
GetSegmentMethod · 0.80
AlmostEqualAbsFunction · 0.50
AddMethod · 0.45
reserveMethod · 0.45
sizeMethod · 0.45
push_backMethod · 0.45
GetPointMethod · 0.45
IsRealSegmentMethod · 0.45

Tested by

no test coverage detected