aboutsummaryrefslogtreecommitdiffstats
path: root/main/src/cgeo/geocaching
diff options
context:
space:
mode:
authorSamuel Tardieu <sam@rfc1149.net>2012-05-31 14:45:12 +0200
committerSamuel Tardieu <sam@rfc1149.net>2012-05-31 17:47:01 +0200
commitb1b376cc15211705bb814bb0187c49e74656caa1 (patch)
tree6e8f5e8b8ac68d715ad4da6522476579be08b4b6 /main/src/cgeo/geocaching
parent77448c73c305513df4f7651b3e56dbc59602ddc8 (diff)
downloadcgeo-b1b376cc15211705bb814bb0187c49e74656caa1.zip
cgeo-b1b376cc15211705bb814bb0187c49e74656caa1.tar.gz
cgeo-b1b376cc15211705bb814bb0187c49e74656caa1.tar.bz2
Add a function to compute a normalized angle difference
Diffstat (limited to 'main/src/cgeo/geocaching')
-rw-r--r--main/src/cgeo/geocaching/DirectionProvider.java11
-rw-r--r--main/src/cgeo/geocaching/ui/CompassView.java4
2 files changed, 14 insertions, 1 deletions
diff --git a/main/src/cgeo/geocaching/DirectionProvider.java b/main/src/cgeo/geocaching/DirectionProvider.java
index 7bb940f..2f54b41 100644
--- a/main/src/cgeo/geocaching/DirectionProvider.java
+++ b/main/src/cgeo/geocaching/DirectionProvider.java
@@ -60,4 +60,15 @@ public class DirectionProvider extends MemorySubject<Float> implements SensorEve
return Compatibility.getDirectionNow(direction, activity) % 360;
}
+ /**
+ * Return the angle to turn of to go from an angle to the other
+ *
+ * @param from the origin angle in degrees, in the [0, 360[ range
+ * @param to the target angle in degreees, in the [0, 360[ range
+ * @return a value in degrees, in the [-180, 180[ range
+ */
+ public static double difference(final double from, final double to) {
+ return (to - from + 360 + 180) % 360 - 180;
+ }
+
}
diff --git a/main/src/cgeo/geocaching/ui/CompassView.java b/main/src/cgeo/geocaching/ui/CompassView.java
index 6f5b8b9..56cba9d 100644
--- a/main/src/cgeo/geocaching/ui/CompassView.java
+++ b/main/src/cgeo/geocaching/ui/CompassView.java
@@ -1,5 +1,6 @@
package cgeo.geocaching.ui;
+import cgeo.geocaching.DirectionProvider;
import cgeo.geocaching.R;
import cgeo.geocaching.utils.PeriodicHandler;
@@ -153,7 +154,8 @@ public class CompassView extends View {
public void act() {
final double newAzimuthShown = smoothUpdate(northMeasured, azimuthShown);
final double newCacheHeadingShown = smoothUpdate(cacheHeadingMeasured, cacheHeadingShown);
- if (Math.abs(newAzimuthShown - azimuthShown) >= 2 || Math.abs(newCacheHeadingShown - cacheHeadingShown) >= 2) {
+ if (Math.abs(DirectionProvider.difference(azimuthShown, newAzimuthShown)) >= 2 ||
+ Math.abs(DirectionProvider.difference(cacheHeadingShown, newCacheHeadingShown)) >= 2) {
synchronized(CompassView.this) {
azimuthShown = newAzimuthShown;
cacheHeadingShown = newCacheHeadingShown;