]> git.street.me.uk Git - andy/viking.git/blobdiff - src/coords.c
Remove dependencies to gob2
[andy/viking.git] / src / coords.c
index df2391bc31813ccb14d1f13e4d8d19024e23cdfd..c7ce8d616efbb3554974f9d856ecb47d271ba068 100644 (file)
@@ -6,6 +6,8 @@ I (Evan Battaglia <viking@greentorch.org>) have only made some small changes suc
 renaming functions and defining LatLon and UTM structs.
 2004-02-10 -- I also added a function of my own -- a_coords_utm_diff() -- that I felt belonged in coords.c
 2004-02-21 -- I also added a_coords_utm_equal().
+2005-11-23 -- Added a_coords_dtostr() for lack of a better place.
+
 */
 /* coords.h - include file for coords routines
 **
@@ -39,10 +41,23 @@ renaming functions and defining LatLon and UTM structs.
 #include <math.h>
 
 #include "viking.h"
+#include "globals.h"
+#include "degrees_converters.h"
 
-#ifdef WINDOWS
-#define M_PI 3.14159265358979
-#endif
+/**
+ * Convert a double to a string WITHOUT LOCALE.
+ *
+ * Following GPX specifications, decimal values are xsd:decimal
+ * So, they must use the period separator, not the localized one.
+ *
+ * The returned value must be freed by g_free.
+ */
+char *a_coords_dtostr ( double d )
+{
+  gchar *buffer = g_malloc(G_ASCII_DTOSTR_BUF_SIZE*sizeof(gchar));
+  g_ascii_dtostr (buffer, G_ASCII_DTOSTR_BUF_SIZE, (gdouble) d);
+  return buffer;
+}
 
 #define PIOVER180 0.01745329252
 
@@ -222,3 +237,29 @@ void a_coords_utm_to_latlon( const struct UTM *utm, struct LatLon *latlon )
     latlon->lon = longitude;
 
     }
+
+void a_coords_latlon_to_string ( const struct LatLon *latlon,
+                                gchar **lat,
+                                gchar **lon )
+{
+  g_return_if_fail ( latlon != NULL );
+
+  vik_degree_format_t format = a_vik_get_degree_format ();
+
+  switch (format) {
+  case VIK_DEGREE_FORMAT_DDD:
+    *lat = convert_lat_dec_to_ddd ( latlon->lat );
+    *lon = convert_lon_dec_to_ddd ( latlon->lon );
+    break;
+  case VIK_DEGREE_FORMAT_DMM:
+    *lat = convert_lat_dec_to_dmm ( latlon->lat );
+    *lon = convert_lon_dec_to_dmm ( latlon->lon );
+    break;
+  case VIK_DEGREE_FORMAT_DMS:
+    *lat = convert_lat_dec_to_dms ( latlon->lat );
+    *lon = convert_lon_dec_to_dms ( latlon->lon );
+    break;
+  default:
+    g_critical("Houston, we've had a problem. format=%d", format);
+  }
+}