]> git.street.me.uk Git - andy/viking.git/blobdiff - src/coords.c
Remove of temporary file after processing Geonames Wikipedia information.
[andy/viking.git] / src / coords.c
index c7ce8d616efbb3554974f9d856ecb47d271ba068..25eb900c033b617f7be642a993a6fdf9d6f1411d 100644 (file)
@@ -35,10 +35,19 @@ renaming functions and defining LatLon and UTM structs.
 ** OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 ** SUCH DAMAGE.
 */
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
 
+#ifdef HAVE_STDLIB_H
 #include <stdlib.h>
+#endif
+#ifdef HAVE_STRING_H
 #include <string.h>
+#endif
+#ifdef HAVE_MATH_H
 #include <math.h>
+#endif
 
 #include "viking.h"
 #include "globals.h"
@@ -89,11 +98,14 @@ double a_coords_utm_diff( const struct UTM *utm1, const struct UTM *utm2 )
 double a_coords_latlon_diff ( const struct LatLon *ll1, const struct LatLon *ll2 )
 {
   static struct LatLon tmp1, tmp2;
+  gdouble tmp3;
   tmp1.lat = ll1->lat * PIOVER180;
   tmp1.lon = ll1->lon * PIOVER180;
   tmp2.lat = ll2->lat * PIOVER180;
   tmp2.lon = ll2->lon * PIOVER180;
-  return EquatorialRadius * acos(sin(tmp1.lat)*sin(tmp2.lat)+cos(tmp1.lat)*cos(tmp2.lat)*cos(tmp1.lon-tmp2.lon));
+  tmp3 = EquatorialRadius * acos(sin(tmp1.lat)*sin(tmp2.lat)+cos(tmp1.lat)*cos(tmp2.lat)*cos(tmp1.lon-tmp2.lon));
+  // For very small differences we can sometimes get NaN returned
+  return isnan(tmp3)?0:tmp3;
 }
 
 void a_coords_latlon_to_utm( const struct LatLon *latlon, struct UTM *utm )