diff options
| author | Samuel Tardieu <sam@rfc1149.net> | 2012-06-14 21:51:41 +0200 |
|---|---|---|
| committer | rsudev <rasch@munin-soft.de> | 2012-06-17 17:23:31 +0200 |
| commit | a97f0b14dcef867cd1aad7b0d6273734264865d3 (patch) | |
| tree | f39a4345017d88c0f59de722052dea52a749dc82 /main/src/cgeo/geocaching/utils/AngleUtils.java | |
| parent | 903ac4252151004f27e975384f71defbfb11f1e1 (diff) | |
| download | cgeo-a97f0b14dcef867cd1aad7b0d6273734264865d3.zip cgeo-a97f0b14dcef867cd1aad7b0d6273734264865d3.tar.gz cgeo-a97f0b14dcef867cd1aad7b0d6273734264865d3.tar.bz2 | |
Put angle-related utilities into their own package
Also, use float instead of double for every angle computation.
Conflicts:
main/src/cgeo/geocaching/ui/CacheListAdapter.java
Diffstat (limited to 'main/src/cgeo/geocaching/utils/AngleUtils.java')
| -rw-r--r-- | main/src/cgeo/geocaching/utils/AngleUtils.java | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/main/src/cgeo/geocaching/utils/AngleUtils.java b/main/src/cgeo/geocaching/utils/AngleUtils.java new file mode 100644 index 0000000..e2b4a66 --- /dev/null +++ b/main/src/cgeo/geocaching/utils/AngleUtils.java @@ -0,0 +1,28 @@ +package cgeo.geocaching.utils; + +public class AngleUtils { + + private AngleUtils() { + // Do not instantiate + } + + /** + * Return the angle to turn of to go from an angle to the other + * + * @param from the origin angle in degrees + * @param to the target angle in degreees + * @return a value in degrees, in the [-180, 180[ range + */ + public static float difference(final float from, final float to) { + return normalize(to - from + 180) - 180; + } + + /** + * Normalize an angle so that it belongs to the [0, 360[ range. + * @param angle the angle in degrees + * @return the same angle in the [0, 360[ range + */ + public static float normalize(final float angle) { + return (angle >= 0 ? angle : (360 - ((-angle) % 360))) % 360; + } +} |
