| 13 | double constexpr PositionAccumulator::kMaxValidSegmentLengthM; |
| 14 | |
| 15 | void PositionAccumulator::PushNextPoint(m2::PointD const & point) |
| 16 | { |
| 17 | double const lenM = m_points.empty() ? 0.0 : mercator::DistanceOnEarth(point, m_points.back()); |
| 18 | |
| 19 | // If the last segment is too long it tells nothing about an end user direction. |
| 20 | // And the history is not actual. |
| 21 | if (lenM > kMaxValidSegmentLengthM) |
| 22 | { |
| 23 | Clear(); |
| 24 | m_points.push_back(point); |
| 25 | return; |
| 26 | } |
| 27 | |
| 28 | // If the last segment is too short it means an end user stays we there's no information |
| 29 | // about it's direction. If m_points.empty() == true it means |point| is the first point. |
| 30 | if (!m_points.empty() && lenM < kMinValidSegmentLengthM) |
| 31 | return; |
| 32 | |
| 33 | // If |m_points| is empty |point| should be added any way. |
| 34 | // If the size of |m_points| is 1 and |lenM| is valid |point| should be added. |
| 35 | if (m_points.size() < 2) |
| 36 | { |
| 37 | CHECK_EQUAL(m_trackLengthM, 0.0, ()); |
| 38 | m_trackLengthM = lenM; |
| 39 | m_points.push_back(point); |
| 40 | return; |
| 41 | } |
| 42 | |
| 43 | // If after adding |point| to |m_points| and removing the farthest point the segment length |
| 44 | // is less than |kMinTrackLengthM| we just adding |point|. |
| 45 | double oldestSegmentLenM = mercator::DistanceOnEarth(m_points[1], m_points[0]); |
| 46 | if (m_trackLengthM + lenM - oldestSegmentLenM <= kMinTrackLengthM) |
| 47 | { |
| 48 | m_trackLengthM += lenM; |
| 49 | m_points.push_back(point); |
| 50 | return; |
| 51 | } |
| 52 | |
| 53 | // Removing the farthest point if length of the track |m_points[1]|, ..., |m_points.back()|, |point| |
| 54 | // is more than |kMinTrackLengthM|. |
| 55 | while (m_trackLengthM + lenM - oldestSegmentLenM > kMinTrackLengthM && m_points.size() > 2) |
| 56 | { |
| 57 | m_trackLengthM -= oldestSegmentLenM; |
| 58 | m_points.pop_front(); |
| 59 | oldestSegmentLenM = mercator::DistanceOnEarth(m_points[1], m_points[0]); |
| 60 | } |
| 61 | |
| 62 | m_trackLengthM += lenM; |
| 63 | m_points.push_back(point); |
| 64 | } |
| 65 | |
| 66 | void PositionAccumulator::Clear() |
| 67 | { |
no test coverage detected