Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions shared/src/gps/GpsLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -130,11 +132,21 @@ void GpsLayer::updatePosition(const Coord &position, double horizontalAccuracyM,
}
}

// skip update for small position changes
auto threshold = mapCoordinateSystem.unitToScreenMeterFactor * 10;

Copilot AI Jun 15, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The hard-coded multiplier 10 is a magic number. Consider defining a named constant (e.g., kMinUpdateDistanceScreenMeters) or documenting why 10 is chosen.

Suggested change
auto threshold = mapCoordinateSystem.unitToScreenMeterFactor * 10;
auto threshold = mapCoordinateSystem.unitToScreenMeterFactor * kMinUpdateDistanceScreenMeters;

Copilot uses AI. Check for mistakes.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On Android, this is usually a configuration value in the LocationProvider itself (so the client decides whats best). Shouldn't we make it configurable at least?

if (this->position &&

Copilot AI Jun 15, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using abs() on floating-point differences may invoke the integer overload. Use std::abs (from ) or std::fabs to ensure correct floating-point behavior.

Copilot uses AI. Check for mistakes.
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
Expand Down