X-Git-Url: https://git.gag.com/?p=fw%2Faltos;a=blobdiff_plain;f=altoslib%2FAltosGreatCircle.java;h=cd5b9636a4bea28957048bc87f2accf7dc6f712d;hp=8fd380a100ada00c645698460426dbd56223adc4;hb=eaf2ee0f498b519d64e1664a2b8c66c52ac1497c;hpb=1b5ea911049a8afae6af475a4a2bf62a6e3aa57b diff --git a/altoslib/AltosGreatCircle.java b/altoslib/AltosGreatCircle.java index 8fd380a1..cd5b9636 100644 --- a/altoslib/AltosGreatCircle.java +++ b/altoslib/AltosGreatCircle.java @@ -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 @@ -15,12 +16,12 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -package org.altusmetrum.altoslib_11; +package org.altusmetrum.altoslib_13; import java.lang.Math; import java.io.*; -public class AltosGreatCircle implements Cloneable, AltosHashable, AltosJsonable { +public class AltosGreatCircle implements Cloneable { public double distance; public double bearing; public double range; @@ -71,7 +72,10 @@ public class AltosGreatCircle implements Cloneable, AltosHashable, AltosJsonable 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); @@ -103,58 +107,4 @@ public class AltosGreatCircle implements Cloneable, AltosHashable, AltosJsonable 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 AltosJson json() { - AltosJson j = new AltosJson(); - - j.put("distance", distance); - j.put("bearing", bearing); - j.put("range", range); - j.put("elevation", elevation); - - return j; - } - - 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); - } - - public AltosGreatCircle(AltosJson j) { - this(); - - distance = j.get_double("distance", distance); - bearing = j.get_double("bearing", bearing); - range = j.get_double("range", range); - elevation = j.get_double("elevation", elevation); - } - - public static AltosGreatCircle fromJson(AltosJson j, AltosGreatCircle def) { - if (j == null) - return def; - - return new AltosGreatCircle(j); - } }