altos/telefireone-v2.0: Remove build of ao_product.h from Makefile
[fw/altos] / altoslib / AltosGreatCircle.java
index 2c84bf4a27534c607f0c517215e41f354fc0000d..cd5b9636a4bea28957048bc87f2accf7dc6f712d 100644 (file)
@@ -3,7 +3,8 @@
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; version 2 of the License.
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
  *
  * This program is distributed in the hope that it will be useful, but
  * WITHOUT ANY WARRANTY; without even the implied warranty of
  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
  */
 
-package org.altusmetrum.altoslib_2;
+package org.altusmetrum.altoslib_13;
 
 import java.lang.Math;
+import java.io.*;
 
 public class AltosGreatCircle implements Cloneable {
        public double   distance;
@@ -27,33 +29,15 @@ public class AltosGreatCircle implements Cloneable {
 
        double sqr(double a) { return a * a; }
 
-       static final double rad = Math.PI / 180;
-       static final double earth_radius = 6371.2 * 1000;       /* in meters */
+       public static final double rad = Math.PI / 180;
+       public static final double earth_radius = 6371.2 * 1000;        /* in meters */
 
-       public static final int BEARING_LONG = 0;
-       public static final int BEARING_SHORT = 1;
-       public static final int BEARING_VOICE = 2;
+       public static final int BEARING_LONG = AltosConvert.BEARING_LONG;
+       public static final int BEARING_SHORT = AltosConvert.BEARING_SHORT;
+       public static final int BEARING_VOICE = AltosConvert.BEARING_VOICE;
 
        public String bearing_words(int length) {
-               String [][] bearing_string = {
-                       {
-                               "North", "North North East", "North East", "East North East",
-                               "East", "East South East", "South East", "South South East",
-                               "South", "South South West", "South West", "West South West",
-                               "West", "West North West", "North West", "North North West"
-                       }, {
-                               "N", "NNE", "NE", "ENE",
-                               "E", "ESE", "SE", "SSE",
-                               "S", "SSW", "SW", "WSW",
-                               "W", "WNW", "NW", "NNW"
-                       }, {
-                               "north", "nor nor east", "north east", "east nor east",
-                               "east", "east sow east", "south east", "sow sow east",
-                               "south", "sow sow west", "south west", "west sow west",
-                               "west", "west nor west", "north west", "nor nor west "
-                       }
-               };
-               return bearing_string[length][(int)((bearing / 90 * 8 + 1) / 2)%16];
+               return AltosConvert.bearing_to_words(length, bearing);
        }
 
        public AltosGreatCircle (double start_lat, double start_lon, double start_alt,
@@ -88,7 +72,10 @@ public class AltosGreatCircle implements Cloneable {
                                course = 2 * Math.PI-course;
                }
                distance = d * earth_radius;
-               bearing = course * 180/Math.PI;
+               if (Double.isNaN(course) || Double.isInfinite(course))
+                       bearing = 0;
+               else
+                       bearing = course * 180/Math.PI;
 
                double height_diff = end_alt - start_alt;
                range = Math.sqrt(distance * distance + height_diff * height_diff);