| 868 | } |
| 869 | |
| 870 | std::optional<Direction> WorldFeed::ProjectStopsToShape( |
| 871 | ShapesIter & itShape, StopsOnLines const & stopsOnLines, |
| 872 | ankerl::unordered_dense::map<TransitId, std::vector<size_t>> & stopsToIndexes) |
| 873 | { |
| 874 | IdList const & stopIds = stopsOnLines.m_stopSeq; |
| 875 | TransitId const shapeId = itShape->first; |
| 876 | |
| 877 | auto const tryProject = [&](Direction direction) |
| 878 | { |
| 879 | auto shape = itShape->second.m_points; |
| 880 | std::optional<m2::PointD> prevPoint = std::nullopt; |
| 881 | for (size_t i = 0; i < stopIds.size(); ++i) |
| 882 | { |
| 883 | auto const & stopId = stopIds[i]; |
| 884 | auto const itStop = m_stops.m_data.find(stopId); |
| 885 | CHECK(itStop != m_stops.m_data.end(), (stopId)); |
| 886 | auto const & stop = itStop->second; |
| 887 | |
| 888 | size_t const prevIdx = |
| 889 | i == 0 ? (direction == Direction::Forward ? 0 : shape.size() - 1) : stopsToIndexes[stopIds[i - 1]].back(); |
| 890 | auto const [curIdx, pointInserted] = |
| 891 | PrepareNearestPointOnTrack(stop.m_point, prevPoint, prevIdx, direction, shape); |
| 892 | |
| 893 | if (curIdx > shape.size()) |
| 894 | { |
| 895 | CHECK(!itShape->second.m_lineIds.empty(), (shapeId)); |
| 896 | TransitId const lineId = *stopsOnLines.m_lines.begin(); |
| 897 | |
| 898 | LOG(LWARNING, ("Error projecting stops to the shape. GTFS trip id", m_lines.m_data[lineId].m_gtfsTripId, |
| 899 | "shapeId", shapeId, "stopId", stopId, "i", i, "previous index on shape", prevIdx, "trips count", |
| 900 | stopsOnLines.m_lines.size())); |
| 901 | return false; |
| 902 | } |
| 903 | |
| 904 | prevPoint = std::optional<m2::PointD>(stop.m_point); |
| 905 | |
| 906 | if (pointInserted) |
| 907 | { |
| 908 | for (auto & indexesList : stopsToIndexes) |
| 909 | { |
| 910 | for (auto & stopIndex : indexesList.second) |
| 911 | if (stopIndex >= curIdx) |
| 912 | ++stopIndex; |
| 913 | } |
| 914 | |
| 915 | for (auto const & lineId : m_shapes.m_data[shapeId].m_lineIds) |
| 916 | { |
| 917 | auto & line = m_lines.m_data[lineId]; |
| 918 | |
| 919 | if (line.m_shapeLink.m_startIndex >= curIdx) |
| 920 | ++line.m_shapeLink.m_startIndex; |
| 921 | |
| 922 | if (line.m_shapeLink.m_endIndex >= curIdx) |
| 923 | ++line.m_shapeLink.m_endIndex; |
| 924 | } |
| 925 | } |
| 926 | |
| 927 | stopsToIndexes[stopId].push_back(curIdx); |