aboutsummaryrefslogtreecommitdiffstats
path: root/main/src/cgeo/geocaching/ui/CompassView.java
diff options
context:
space:
mode:
authorSamuel Tardieu <sam@rfc1149.net>2012-05-31 14:29:42 +0200
committerSamuel Tardieu <sam@rfc1149.net>2012-05-31 14:50:10 +0200
commit11dfc41193c31341831d0712692f3f2bf7dda860 (patch)
treefa122ca969465014bd7a9f5165cfa98581ec21cb /main/src/cgeo/geocaching/ui/CompassView.java
parent3e2d0a118596ab44857bec60d761fc2bfdeeb0be (diff)
downloadcgeo-11dfc41193c31341831d0712692f3f2bf7dda860.zip
cgeo-11dfc41193c31341831d0712692f3f2bf7dda860.tar.gz
cgeo-11dfc41193c31341831d0712692f3f2bf7dda860.tar.bz2
Ensure that we stay in the [0, 360[ range
We have to ensure that the direction stays within the right range when computing a smooth update. Related to issues #1680 and #1685.
Diffstat (limited to 'main/src/cgeo/geocaching/ui/CompassView.java')
-rw-r--r--main/src/cgeo/geocaching/ui/CompassView.java12
1 files changed, 6 insertions, 6 deletions
diff --git a/main/src/cgeo/geocaching/ui/CompassView.java b/main/src/cgeo/geocaching/ui/CompassView.java
index 56cba9d..703f96f 100644
--- a/main/src/cgeo/geocaching/ui/CompassView.java
+++ b/main/src/cgeo/geocaching/ui/CompassView.java
@@ -129,19 +129,19 @@ public class CompassView extends View {
* @return the new value
*/
static protected double smoothUpdate(double goal, double actual) {
- final double diff = (goal - actual + 360) % 360;
+ final double diff = DirectionProvider.difference(actual, goal);
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) {
+ // causes the arrow to vibrate. Round away from 0.
+ if (diff > 1.0) {
offset = Math.ceil(diff / 10.0); // for larger angles, rotate faster
- } else if (diff > 180.0 && diff < 359.0) {
- offset = Math.floor((diff - 360.0) / 10.0);
+ } else if (diff < 1.0) {
+ offset = Math.floor(diff / 10.0);
}
- return actual + offset;
+ return (actual + offset + 360) % 360;
}
private class RedrawHandler extends PeriodicHandler {