Unverified Commit c5838fd5 authored by Don Gagne's avatar Don Gagne Committed by GitHub

Merge pull request #8020 from DonLakeFlyer/TrajectoryCrash

Fix crash caused by clear method not resetting internals correctly
parents 8ac56bc2 56256077
...@@ -19,22 +19,29 @@ TrajectoryPoints::TrajectoryPoints(Vehicle* vehicle, QObject* parent) ...@@ -19,22 +19,29 @@ TrajectoryPoints::TrajectoryPoints(Vehicle* vehicle, QObject* parent)
void TrajectoryPoints::_vehicleCoordinateChanged(QGeoCoordinate coordinate) void TrajectoryPoints::_vehicleCoordinateChanged(QGeoCoordinate coordinate)
{ {
// The goal of this algorithm is to limit the number of trajectory points whic represent the vehicle path.
// Fewer points means higher performance of map display.
if (_lastPoint.isValid()) { if (_lastPoint.isValid()) {
if (_lastPoint.distanceTo(coordinate) > _distanceTolerance) { if (_lastPoint.distanceTo(coordinate) > _distanceTolerance) {
// Vehicle has moved far enough from previous point for an update
double newAzimuth = _lastPoint.azimuthTo(coordinate); double newAzimuth = _lastPoint.azimuthTo(coordinate);
if (qIsNaN(_lastAzimuth) || qAbs(newAzimuth - _lastAzimuth) > _azimuthTolerance) { if (qIsNaN(_lastAzimuth) || qAbs(newAzimuth - _lastAzimuth) > _azimuthTolerance) {
// The new position IS NOT colinear with the last segment. Append the new position to the list.
_lastAzimuth = _lastPoint.azimuthTo(coordinate); _lastAzimuth = _lastPoint.azimuthTo(coordinate);
_lastPoint = coordinate; _lastPoint = coordinate;
_points.append(QVariant::fromValue(coordinate)); _points.append(QVariant::fromValue(coordinate));
emit pointAdded(coordinate); emit pointAdded(coordinate);
} else { } else {
// The new position IS colinear with the last segment. Don't add a new point, just update
// the last point to be the new position.
_lastPoint = coordinate; _lastPoint = coordinate;
_points[_points.count() - 1] = QVariant::fromValue(coordinate); _points[_points.count() - 1] = QVariant::fromValue(coordinate);
emit updateLastPoint(coordinate); emit updateLastPoint(coordinate);
} }
} }
} else { } else {
_lastAzimuth = _lastPoint.azimuthTo(coordinate); // Add the very first trajectory point to the list
_lastPoint = coordinate; _lastPoint = coordinate;
_points.append(QVariant::fromValue(coordinate)); _points.append(QVariant::fromValue(coordinate));
emit pointAdded(coordinate); emit pointAdded(coordinate);
...@@ -56,5 +63,7 @@ void TrajectoryPoints::stop(void) ...@@ -56,5 +63,7 @@ void TrajectoryPoints::stop(void)
void TrajectoryPoints::clear(void) void TrajectoryPoints::clear(void)
{ {
_points.clear(); _points.clear();
_lastPoint = QGeoCoordinate();
_lastAzimuth = qQNaN();
emit pointsCleared(); emit pointsCleared();
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment