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

Method ClipLines

libs/transit/transit_graph_data.cpp:401–457  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

399}
400
401void 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

Callers

nothing calls this directly

Calls 15

RegionsContainFunction · 0.85
GetStop1IdMethod · 0.80
GetStop2IdMethod · 0.80
GetNetworkIdMethod · 0.80
GetPointMethod · 0.45
insertMethod · 0.45
GetIdMethod · 0.45
countMethod · 0.45
cbeginMethod · 0.45
cendMethod · 0.45
sizeMethod · 0.45
beginMethod · 0.45

Tested by

no test coverage detected