]> git.street.me.uk Git - andy/viking.git/blobdiff - src/degrees_converters.c
Enable using an optional file cache for Mapnik Renderings.
[andy/viking.git] / src / degrees_converters.c
index 734638263b897d089b6637f80120fa597438e76f..9e55a399aa4c55e646b37ec39d80ed4b0b64a8b7 100644 (file)
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  *
  */
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
 
+#ifdef HAVE_MATH_H
 #include <math.h>
-#include <glib.h>
+#endif
 #include <string.h>
+#include "degrees_converters.h"
 
 #define DEGREE_SYMBOL "\302\260"
 
@@ -129,11 +134,11 @@ static gchar *convert_dec_to_dms(gdouble dec, gchar pos_c, gchar neg_c)
   tmp = (tmp - val_d) * 60;
   val_m = (gint)tmp;
 
-  /* Minutes */
+  /* Seconds */
   val_s = (tmp - val_m) * 60;
 
   /* Format */
-  result = g_strdup_printf ( "%c%d" DEGREE_SYMBOL "%d'%f\"",
+  result = g_strdup_printf ( "%c%d" DEGREE_SYMBOL "%d'%.4f\"",
                              sign_c, val_d, val_m, val_s );
   return result;
 }
@@ -173,8 +178,13 @@ gdouble convert_dms_to_dec(const gchar *dms)
                        gdouble value;
                        ptr = strpbrk (endptr, "0123456789,.");
                        if (ptr != NULL) {
-                               value = g_strtod(ptr, &endptr);
-                       nbFloat++;
+                               const gchar *tmpptr = endptr;
+                               value = g_strtod((const gchar *)ptr, (gchar **)&endptr);
+                               // Detect when endptr hasn't changed (which may occur if no conversion took place)
+                               //  particularly if the last character is a ',' or there are multiple '.'s like '5.5.'
+                               if ( endptr == tmpptr )
+                                       break;
+                               nbFloat++;
                switch(nbFloat) {
                        case 1:
                                d = value;
@@ -185,6 +195,7 @@ gdouble convert_dms_to_dec(const gchar *dms)
                        case 3:
                                s = value;
                                break;
+                       default: break;
                }
                        }
                } while (ptr != NULL && endptr != NULL);