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

Method FindCamerasOnRouteAndCache

libs/routing/speed_camera_manager.cpp:179–220  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

177}
178
179void SpeedCameraManager::FindCamerasOnRouteAndCache(double passedDistanceMeters)
180{
181 CHECK(!m_route.expired(), ());
182
183 auto const & segments = m_route.lock()->GetRouteSegments();
184 size_t firstNotChecked = m_firstNotCheckedSpeedCameraIndex;
185 if (firstNotChecked == segments.size())
186 return;
187
188 CHECK_LESS(firstNotChecked, segments.size(), ());
189
190 double distToPrevSegment = segments[firstNotChecked].GetDistFromBeginningMeters();
191 double distFromCurPosToLatestCheckedSegmentM = distToPrevSegment - passedDistanceMeters;
192
193 while (firstNotChecked < segments.size() && distFromCurPosToLatestCheckedSegmentM < kLookAheadDistanceMeters)
194 {
195 CHECK_GREATER(firstNotChecked, 0, ());
196
197 auto const & lastSegment = segments[firstNotChecked];
198 auto const & prevSegment = segments[firstNotChecked - 1];
199
200 auto const & endPoint = lastSegment.GetJunction().GetPoint();
201 auto const & startPoint = prevSegment.GetJunction().GetPoint();
202 auto const direction = endPoint - startPoint;
203
204 auto const & speedCamsVector = lastSegment.GetSpeedCams();
205 double segmentLength = m_route.lock()->GetSegLenMeters(firstNotChecked);
206
207 for (auto const & speedCam : speedCamsVector)
208 {
209 segmentLength *= speedCam.m_coef;
210 m_cachedSpeedCameras.emplace(distToPrevSegment + segmentLength, speedCam.m_maxSpeedKmPH,
211 startPoint + direction * speedCam.m_coef);
212 }
213
214 distToPrevSegment = lastSegment.GetDistFromBeginningMeters();
215 distFromCurPosToLatestCheckedSegmentM = distToPrevSegment - passedDistanceMeters;
216 ++firstNotChecked;
217 }
218
219 m_firstNotCheckedSpeedCameraIndex = firstNotChecked;
220}
221
222void SpeedCameraManager::PassClosestCameraToUI()
223{

Callers

nothing calls this directly

Calls 6

lockMethod · 0.80
GetSegLenMetersMethod · 0.80
sizeMethod · 0.45
GetPointMethod · 0.45
emplaceMethod · 0.45

Tested by

no test coverage detected