From 4a0b82d42f22926b29a4656bea747411e380caef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20Ma=CC=88rki?= Date: Sun, 15 Jun 2025 10:40:01 +0200 Subject: [PATCH] reduce invalidation frequency --- shared/src/gps/GpsLayer.cpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/shared/src/gps/GpsLayer.cpp b/shared/src/gps/GpsLayer.cpp index 6a288fe..c29ebfd 100644 --- a/shared/src/gps/GpsLayer.cpp +++ b/shared/src/gps/GpsLayer.cpp @@ -114,8 +114,10 @@ void GpsLayer::updatePosition(const Coord &position, double horizontalAccuracyM, } positionValid = true; + const auto mapCoordinateSystem = mapInterface->getMapConfig().mapCoordinateSystem; + Coord newPosition = mapInterface->getCoordinateConverterHelper()->convert( - mapInterface->getMapConfig().mapCoordinateSystem.identifier, position); + mapCoordinateSystem.identifier, position); // ignore position altitude newPosition.z = 0.0; @@ -130,11 +132,21 @@ void GpsLayer::updatePosition(const Coord &position, double horizontalAccuracyM, } } + // skip update for small position changes + auto threshold = mapCoordinateSystem.unitToScreenMeterFactor * 10; + if (this->position && + abs(newPosition.x - this->position->x) < threshold && + abs(newPosition.y - this->position->y) < threshold && + abs(newPosition.z - this->position->z) < threshold) { + return; + } + + this->position = newPosition; if (this->horizontalAccuracyMapUnits != horizontalAccuracyM) { accuracyChanged.clear(); } - this->horizontalAccuracyMapUnits = horizontalAccuracyM * mapInterface->getMapConfig().mapCoordinateSystem.unitToScreenMeterFactor; + this->horizontalAccuracyMapUnits = horizontalAccuracyM * mapCoordinateSystem.unitToScreenMeterFactor; // only invalidate if the position is visible