Improved calculations for speed limit violations on the road

This PR resolves the issue mentioned in the comment:
https://github.com/organicmaps/organicmaps/issues/8934#issuecomment-2295239837

The error was in the condition:
last.getSpeed() > info.speedLimitMps

Here, a float was compared with a double, leading to incorrect calculations when determining the text color. For example:

(22.375252f > 22.37525199999) = false (expected true)
(22.375252f > 22.375252) = false (this is correct)
(22.375252f > 22.37521) = true (this is correct)
My fix involves converting the numbers to int before comparing them, which eliminates these comparison anomalies.

Signed-off-by: Mikhail Mitrofanov <mk.mitrofanov@outlook.com>
This commit is contained in:
Mikhail Mitrofanov 2024-08-28 15:20:29 +02:00 committed by Alexander Borsuk
parent 918ed8bc33
commit 55a4b68aef

View file

@ -222,7 +222,7 @@ public class NavMenu
else
mSpeedValue.setText(speedAndUnits.first);
if (info.speedLimitMps > 0.0 && last.getSpeed() > info.speedLimitMps)
if (info.speedLimitMps > 0.0 && (int) last.getSpeed() > (int) info.speedLimitMps)
{
if (info.isSpeedCamLimitExceeded())
mSpeedValue.setTextColor(ContextCompat.getColor(mActivity, R.color.white_primary));