| 238 | } |
| 239 | |
| 240 | drape_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 | } |
no test coverage detected