altosui: Move AltosGreatCircle.java to altoslib
authorKeith Packard <keithp@keithp.com>
Tue, 3 Jan 2012 05:12:45 +0000 (21:12 -0800)
committerKeith Packard <keithp@keithp.com>
Sun, 3 Jun 2012 02:31:10 +0000 (19:31 -0700)
Signed-off-by: Keith Packard <keithp@keithp.com>
altosui/AltosGreatCircle.java [deleted file]
altosui/Makefile.am
altosui/altoslib/Makefile.am
altosui/altoslib/src/org/altusmetrum/AltosLib/AltosGreatCircle.java [new file with mode: 0644]

diff --git a/altosui/AltosGreatCircle.java b/altosui/AltosGreatCircle.java
deleted file mode 100644 (file)
index e4af3c1..0000000
+++ /dev/null
@@ -1,101 +0,0 @@
-/*
- * Copyright © 2010 Keith Packard <keithp@keithp.com>
- *
- * 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.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
- */
-
-package altosui;
-
-import java.lang.Math;
-import org.altusmetrum.AltosLib.*;
-
-public class AltosGreatCircle {
-       double  distance;
-       double  bearing;
-
-       double sqr(double a) { return a * a; }
-
-       static final double rad = Math.PI / 180;
-       static final double earth_radius = 6371.2 * 1000;       /* in meters */
-
-    static int BEARING_LONG = 0;
-    static int BEARING_SHORT = 1;
-    static int BEARING_VOICE = 2;
-    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];
-    }
-
-       public AltosGreatCircle (double start_lat, double start_lon,
-                                double end_lat, double end_lon)
-       {
-               double lat1 = rad * start_lat;
-               double lon1 = rad * -start_lon;
-               double lat2 = rad * end_lat;
-               double lon2 = rad * -end_lon;
-
-               double d_lon = lon2 - lon1;
-
-               /* From http://en.wikipedia.org/wiki/Great-circle_distance */
-               double vdn = Math.sqrt(sqr(Math.cos(lat2) * Math.sin(d_lon)) +
-                                      sqr(Math.cos(lat1) * Math.sin(lat2) -
-                                          Math.sin(lat1) * Math.cos(lat2) * Math.cos(d_lon)));
-               double vdd = Math.sin(lat1) * Math.sin(lat2) + Math.cos(lat1) * Math.cos(lat2) * Math.cos(d_lon);
-               double d = Math.atan2(vdn,vdd);
-               double course;
-
-               if (Math.cos(lat1) < 1e-20) {
-                       if (lat1 > 0)
-                               course = Math.PI;
-                       else
-                               course = -Math.PI;
-               } else {
-                       if (d < 1e-10)
-                               course = 0;
-                       else
-                               course = Math.acos((Math.sin(lat2)-Math.sin(lat1)*Math.cos(d)) /
-                                                  (Math.sin(d)*Math.cos(lat1)));
-                       if (Math.sin(lon2-lon1) > 0)
-                               course = 2 * Math.PI-course;
-               }
-               distance = d * earth_radius;
-               bearing = course * 180/Math.PI;
-       }
-
-       public AltosGreatCircle(AltosGPS start, AltosGPS end) {
-               this(start.lat, start.lon, end.lat, end.lon);
-       }
-
-       public AltosGreatCircle() {
-               distance = 0;
-               bearing = 0;
-       }
-}
index 84482dc258d25f13075aafecc3f7d9eaa22d571d..f8a886badb74f23c5b752abbee39d36d06cbb578 100644 (file)
@@ -62,7 +62,6 @@ altosui_JAVA = \
        AltosFlightUI.java \
        AltosFontListener.java \
        AltosFreqList.java \
-       AltosGreatCircle.java \
        AltosHexfile.java \
        Altos.java \
        AltosIdleMonitorUI.java \
index 6f8c028a78adf709926d8fd44fd3181d7148309e..e0647bd4649eb1c3dce8790cc932ef166da18703 100644 (file)
@@ -22,6 +22,7 @@ AltosLib_JAVA = \
        $(SRC)/AltosFrequency.java \
        $(SRC)/AltosGPS.java \
        $(SRC)/AltosGPSSat.java \
+       $(SRC)/AltosGreatCircle.java \
        $(SRC)/AltosLine.java \
        $(SRC)/AltosLink.java \
        $(SRC)/AltosParse.java \
diff --git a/altosui/altoslib/src/org/altusmetrum/AltosLib/AltosGreatCircle.java b/altosui/altoslib/src/org/altusmetrum/AltosLib/AltosGreatCircle.java
new file mode 100644 (file)
index 0000000..76b7185
--- /dev/null
@@ -0,0 +1,101 @@
+/*
+ * Copyright © 2010 Keith Packard <keithp@keithp.com>
+ *
+ * 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.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ */
+
+package org.altusmetrum.AltosLib;
+
+import java.lang.Math;
+
+public class AltosGreatCircle {
+       public double   distance;
+       public double   bearing;
+
+       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 int BEARING_LONG = 0;
+       public static final int BEARING_SHORT = 1;
+       public static final int BEARING_VOICE = 2;
+
+       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];
+       }
+
+       public AltosGreatCircle (double start_lat, double start_lon,
+                                double end_lat, double end_lon)
+       {
+               double lat1 = rad * start_lat;
+               double lon1 = rad * -start_lon;
+               double lat2 = rad * end_lat;
+               double lon2 = rad * -end_lon;
+
+               double d_lon = lon2 - lon1;
+
+               /* From http://en.wikipedia.org/wiki/Great-circle_distance */
+               double vdn = Math.sqrt(sqr(Math.cos(lat2) * Math.sin(d_lon)) +
+                                      sqr(Math.cos(lat1) * Math.sin(lat2) -
+                                          Math.sin(lat1) * Math.cos(lat2) * Math.cos(d_lon)));
+               double vdd = Math.sin(lat1) * Math.sin(lat2) + Math.cos(lat1) * Math.cos(lat2) * Math.cos(d_lon);
+               double d = Math.atan2(vdn,vdd);
+               double course;
+
+               if (Math.cos(lat1) < 1e-20) {
+                       if (lat1 > 0)
+                               course = Math.PI;
+                       else
+                               course = -Math.PI;
+               } else {
+                       if (d < 1e-10)
+                               course = 0;
+                       else
+                               course = Math.acos((Math.sin(lat2)-Math.sin(lat1)*Math.cos(d)) /
+                                                  (Math.sin(d)*Math.cos(lat1)));
+                       if (Math.sin(lon2-lon1) > 0)
+                               course = 2 * Math.PI-course;
+               }
+               distance = d * earth_radius;
+               bearing = course * 180/Math.PI;
+       }
+
+       public AltosGreatCircle(AltosGPS start, AltosGPS end) {
+               this(start.lat, start.lon, end.lat, end.lon);
+       }
+
+       public AltosGreatCircle() {
+               distance = 0;
+               bearing = 0;
+       }
+}