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 17:47:09 +0200
commit0fb390b84caf2e8047919645c4a4e487b3145a6c (patch)
tree36f03fa8cf9bbff559c2363e39a2036b3f871355 /main/src/cgeo/geocaching/ui/CompassView.java
parentb1b376cc15211705bb814bb0187c49e74656caa1 (diff)
downloadcgeo-0fb390b84caf2e8047919645c4a4e487b3145a6c.zip
cgeo-0fb390b84caf2e8047919645c4a4e487b3145a6c.tar.gz
cgeo-0fb390b84caf2e8047919645c4a4e487b3145a6c.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 {