| 68 | } |
| 69 | |
| 70 | m2::PointD GetPointForTurn(IRoutingResult const & result, size_t outgoingSegmentIndex, NumMwmIds const & numMwmIds, |
| 71 | size_t const maxPointsCount, double const maxDistMeters, bool const forward) |
| 72 | { |
| 73 | auto const & segments = result.GetSegments(); |
| 74 | ASSERT_LESS(outgoingSegmentIndex, segments.size(), ()); |
| 75 | ASSERT_GREATER(outgoingSegmentIndex, 0, ()); |
| 76 | |
| 77 | RoutePointIndex index = forward ? GetFirstOutgoingPointIndex(outgoingSegmentIndex) |
| 78 | : GetLastIngoingPointIndex(segments, outgoingSegmentIndex); |
| 79 | |
| 80 | ASSERT_LESS(index.m_pathIndex, segments[index.m_segmentIndex].m_path.size(), ()); |
| 81 | ASSERT_LESS(index.m_segmentIndex, segments.size(), ()); |
| 82 | ASSERT(!segments[index.m_segmentIndex].m_path.empty(), ()); |
| 83 | |
| 84 | RoutePointIndex nextIndex; |
| 85 | ASSERT(GetNextRoutePointIndex(result, index, numMwmIds, forward, nextIndex), ()); |
| 86 | |
| 87 | // There is no need for looking too far for low-speed roads. |
| 88 | // So additional time limit is applied. |
| 89 | double constexpr kMaxTimeSeconds = 3.0; |
| 90 | |
| 91 | m2::PointD point = GetPointByIndex(segments, index); |
| 92 | |
| 93 | size_t count = 0; |
| 94 | double curDistanceMeters = 0.0; |
| 95 | double curTimeSeconds = 0.0; |
| 96 | |
| 97 | while (GetNextRoutePointIndex(result, index, numMwmIds, forward, nextIndex)) |
| 98 | { |
| 99 | m2::PointD nextPoint = GetPointByIndex(segments, nextIndex); |
| 100 | |
| 101 | // At start and finish there are two edges with zero length. |
| 102 | // This function should not be called for the start (|outgoingSegmentIndex| == 0). |
| 103 | // So there is special processing for the finish below. |
| 104 | if (point == nextPoint && outgoingSegmentIndex + 1 == segments.size()) |
| 105 | return nextPoint; |
| 106 | |
| 107 | double distanceMeters = mercator::DistanceOnEarth(point, nextPoint); |
| 108 | curDistanceMeters += distanceMeters; |
| 109 | curTimeSeconds += CalcEstimatedTimeToPass(distanceMeters, segments[nextIndex.m_segmentIndex].m_highwayClass); |
| 110 | |
| 111 | if (curTimeSeconds > kMaxTimeSeconds || ++count >= maxPointsCount || curDistanceMeters > maxDistMeters) |
| 112 | return nextPoint; |
| 113 | |
| 114 | point = nextPoint; |
| 115 | index = nextIndex; |
| 116 | } |
| 117 | |
| 118 | return point; |
| 119 | } |
| 120 | |
| 121 | /*! |
| 122 | * \brief Calculates |nextIndex| which is an index of next route point at result.GetSegments() |
no test coverage detected