altoslib: Store saved state in version-independent format
[fw/altos] / altoslib / AltosGreatCircle.java
index 22a8e0e53149de59db01ae11633df35730eac57b..9ec808a5ca74e0c3b9e93d6a4a489d224d550448 100644 (file)
  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
  */
 
-package org.altusmetrum.altoslib_5;
+package org.altusmetrum.altoslib_11;
 
 import java.lang.Math;
 import java.io.*;
 
-public class AltosGreatCircle implements Cloneable, Serializable {
+public class AltosGreatCircle implements Cloneable, AltosHashable {
        public double   distance;
        public double   bearing;
        public double   range;
@@ -28,8 +28,8 @@ public class AltosGreatCircle implements Cloneable, Serializable {
 
        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 = AltosConvert.BEARING_LONG;
        public static final int BEARING_SHORT = AltosConvert.BEARING_SHORT;
@@ -103,4 +103,31 @@ public class AltosGreatCircle implements Cloneable, Serializable {
                range = 0;
                elevation = 0;
        }
+
+       public AltosHashSet hashSet() {
+               AltosHashSet h = new AltosHashSet();
+
+               h.putDouble("distance", distance);
+               h.putDouble("bearing", bearing);
+               h.putDouble("range", range);
+               h.putDouble("elevation", elevation);
+
+               return h;
+       }
+
+       public AltosGreatCircle(AltosHashSet h) {
+               this();
+
+               distance = h.getDouble("distance", distance);
+               bearing = h.getDouble("bearing", bearing);
+               range = h.getDouble("range", range);
+               elevation = h.getDouble("elevation", elevation);
+       }
+
+       public static AltosGreatCircle fromHashSet(AltosHashSet h, AltosGreatCircle def) {
+               if (h == null)
+                       return def;
+
+               return new AltosGreatCircle(h);
+       }
 }