From ad93745d42f9aaf5bc4925075987ef64c13b2f71 Mon Sep 17 00:00:00 2001 From: Bananeweizen Date: Wed, 30 May 2012 21:00:52 +0200 Subject: fix #1680: compass gets stuck after some rotations --- main/src/cgeo/geocaching/ui/CompassView.java | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) (limited to 'main/src/cgeo/geocaching/ui/CompassView.java') diff --git a/main/src/cgeo/geocaching/ui/CompassView.java b/main/src/cgeo/geocaching/ui/CompassView.java index 770bbaf..5401bfd 100644 --- a/main/src/cgeo/geocaching/ui/CompassView.java +++ b/main/src/cgeo/geocaching/ui/CompassView.java @@ -128,15 +128,13 @@ public class CompassView extends View { * @return the new value */ static protected double smoothUpdate(double goal, double actual) { - double diff = goal - actual; - double offset = 0.0; - + double diff = (goal - actual) % 360; if (diff < 0.0) { diff += 360.0; - } else if (diff >= 360.0) { - diff -= 360.0; } + double offset = 0.0; + // If the difference is smaller than 1 degree, do nothing as it // causes the arrow to vibrate. if (diff > 1.0 && diff <= 180.0) { @@ -181,11 +179,9 @@ public class CompassView extends View { } double azimuthTemp = azimuthDrawn; - double azimuthRelative = azimuthTemp - headingDrawn; + double azimuthRelative = (azimuthTemp - headingDrawn) % 360; if (azimuthRelative < 0) { azimuthRelative += 360; - } else if (azimuthRelative >= 360) { - azimuthRelative -= 360; } // compass margins -- cgit v1.1