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

Function GetPointForTurn

libs/routing/turns_generator.cpp:70–119  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

68}
69
70m2::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()

Callers 2

CalcTurnAngleFunction · 0.85
CheckUTurnOnRouteFunction · 0.85

Calls 9

GetLastIngoingPointIndexFunction · 0.85
ASSERTFunction · 0.85
GetNextRoutePointIndexFunction · 0.85
GetPointByIndexFunction · 0.85
CalcEstimatedTimeToPassFunction · 0.85
DistanceOnEarthFunction · 0.50
sizeMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected