| 399 | } |
| 400 | |
| 401 | void GraphData::ClipLines(vector<m2::RegionD> const & borders) |
| 402 | { |
| 403 | // Set with stop ids with stops which are inside |borders|. |
| 404 | set<StopId> stopIdInside; |
| 405 | for (auto const & stop : m_stops) |
| 406 | if (m2::RegionsContain(borders, stop.GetPoint())) |
| 407 | stopIdInside.insert(stop.GetId()); |
| 408 | |
| 409 | set<StopId> hasNeighborInside; |
| 410 | for (auto const & edge : m_edges) |
| 411 | { |
| 412 | auto const stop1Inside = stopIdInside.count(edge.GetStop1Id()) != 0; |
| 413 | auto const stop2Inside = stopIdInside.count(edge.GetStop2Id()) != 0; |
| 414 | if (stop1Inside && !stop2Inside) |
| 415 | hasNeighborInside.insert(edge.GetStop2Id()); |
| 416 | if (stop2Inside && !stop1Inside) |
| 417 | hasNeighborInside.insert(edge.GetStop1Id()); |
| 418 | } |
| 419 | |
| 420 | stopIdInside.insert(hasNeighborInside.cbegin(), hasNeighborInside.cend()); |
| 421 | |
| 422 | // Filling |lines| with stops inside |borders|. |
| 423 | vector<Line> lines; |
| 424 | for (auto const & line : m_lines) |
| 425 | { |
| 426 | // Note. |stopIdsToFill| will be filled with continuous sequences of stop ids. |
| 427 | // In most cases only one sequence of stop ids should be placed to |stopIdsToFill|. |
| 428 | // But if a line is split by |borders| several times then several |
| 429 | // continuous groups of stop ids will be placed to |stopIdsToFill|. |
| 430 | // The loop below goes through all the stop ids belong the line |line| and |
| 431 | // keeps in |stopIdsToFill| continuous groups of stop ids which are inside |borders|. |
| 432 | Ranges stopIdsToFill; |
| 433 | Ranges const & ranges = line.GetStopIds(); |
| 434 | CHECK_EQUAL(ranges.size(), 1, ()); |
| 435 | vector<StopId> const & stopIds = ranges[0]; |
| 436 | auto it = stopIds.begin(); |
| 437 | while (it != stopIds.end()) |
| 438 | { |
| 439 | while (it != stopIds.end() && stopIdInside.count(*it) == 0) |
| 440 | ++it; |
| 441 | auto jt = it; |
| 442 | while (jt != stopIds.end() && stopIdInside.count(*jt) != 0) |
| 443 | ++jt; |
| 444 | if (it != jt) |
| 445 | stopIdsToFill.emplace_back(it, jt); |
| 446 | it = jt; |
| 447 | } |
| 448 | |
| 449 | if (!stopIdsToFill.empty()) |
| 450 | { |
| 451 | lines.emplace_back(line.GetId(), line.GetNumber(), line.GetTitle(), line.GetType(), line.GetColor(), |
| 452 | line.GetNetworkId(), stopIdsToFill, line.GetInterval()); |
| 453 | } |
| 454 | } |
| 455 | |
| 456 | m_lines.swap(lines); |
| 457 | } |
| 458 |
nothing calls this directly
no test coverage detected