]> err.no Git - mapper/blobdiff - src/route.c
Get rid of _pos, move data to gpsdata struct.
[mapper] / src / route.c
index beba25953c7130ed741cfc04bd1646531eeecf53..43dcfed456f165716955e75fad3b457a916cf154 100644 (file)
@@ -1,7 +1,5 @@
 #include <config.h>
 
-#define _GNU_SOURCE
-
 #include <unistd.h>
 #include <stdlib.h>
 #include <string.h>
 
 #include "help.h"
 
+#define DISTANCE_SQUARED(a, b) \
+   ((guint64)((((gint64)(b).unitx)-(a).unitx)*(((gint64)(b).unitx)-(a).unitx))\
+  + (guint64)((((gint64)(b).unity)-(a).unity)*(((gint64)(b).unity)-(a).unity)))
+
 void route_find_nearest_point(void);
 void cancel_autoroute(gboolean temporary);
 void route_show_distance_to_last(void);
@@ -136,9 +138,9 @@ if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(toggle))) {
                gchar buffer[80];
                gchar strlat[32];
                gchar strlon[32];
-               g_ascii_formatd(strlat, 32, "%.06f", _gps.lat);
-               g_ascii_formatd(strlon, 32, "%.06f", _gps.lon);
-               snprintf(buffer, sizeof(buffer), "%s, %s", strlat, strlon);
+               g_ascii_formatd(strlat, 32, "%.06f", _gps->lat);
+               g_ascii_formatd(strlon, 32, "%.06f", _gps->lon);
+               g_snprintf(buffer, sizeof(buffer), "%s, %s", strlat, strlon);
                gtk_entry_set_text(GTK_ENTRY(oti->txt_from), buffer);
        } else if (toggle == oti->rad_use_route) {
                gchar buffer[80];
@@ -154,7 +156,7 @@ if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(toggle))) {
                unit2latlon(p->unitx, p->unity, lat, lon);
                g_ascii_formatd(strlat, 32, "%.06f", lat);
                g_ascii_formatd(strlon, 32, "%.06f", lon);
-               snprintf(buffer, sizeof(buffer), "%s, %s", strlat, strlon);
+               g_snprintf(buffer, sizeof(buffer), "%s, %s", strlat, strlon);
                gtk_entry_set_text(GTK_ENTRY(oti->txt_from), buffer);
        }
        gtk_widget_set_sensitive(oti->txt_from, toggle == oti->rad_use_text);
@@ -216,20 +218,17 @@ auto_route_dl_idle()
 {
 gchar latstr[32], lonstr[32], *latlonstr;
 
-g_ascii_dtostr(latstr, 32, _gps.lat);
-g_ascii_dtostr(lonstr, 32, _gps.lon);
+g_ascii_dtostr(latstr, 32, _gps->lat);
+g_ascii_dtostr(lonstr, 32, _gps->lon);
 latlonstr = g_strdup_printf("%s,%s", latstr, lonstr);
 _autoroute_data.src_str =
     g_strdup_printf(_route_dl_url, latlonstr, _autoroute_data.dest);
 g_free(latlonstr);
 
 MACRO_CURL_EASY_INIT(_autoroute_data.curl_easy);
-curl_easy_setopt(_autoroute_data.curl_easy, CURLOPT_URL,
-                _autoroute_data.src_str);
-curl_easy_setopt(_autoroute_data.curl_easy, CURLOPT_WRITEFUNCTION,
-                route_dl_cb_read);
-curl_easy_setopt(_autoroute_data.curl_easy, CURLOPT_WRITEDATA,
-                &_autoroute_data.rdl_data);
+curl_easy_setopt(_autoroute_data.curl_easy, CURLOPT_URL, _autoroute_data.src_str);
+curl_easy_setopt(_autoroute_data.curl_easy, CURLOPT_WRITEFUNCTION, route_dl_cb_read);
+curl_easy_setopt(_autoroute_data.curl_easy, CURLOPT_WRITEDATA, &_autoroute_data.rdl_data);
 if (!_curl_multi) {
        /* Initialize CURL. */
        _curl_multi = curl_multi_init();
@@ -402,7 +401,7 @@ while (GTK_RESPONSE_ACCEPT == gtk_dialog_run(GTK_DIALOG(dialog))) {
 
        from_escaped = gnome_vfs_escape_string(from);
        to_escaped = gnome_vfs_escape_string(to);
-       snprintf(buffer, sizeof(buffer), source_url, from_escaped, to_escaped);
+       g_snprintf(buffer, sizeof(buffer), source_url, from_escaped, to_escaped);
        g_free(from_escaped);
        g_free(to_escaped);
 
@@ -538,14 +537,14 @@ if (_next_way) {
        /* First, set near_dist_squared with the new distance from
         * _near_point. */
        near = _near_point;
-       near_dist_squared = DISTANCE_SQUARED(_pos, *near);
+       near_dist_squared = DISTANCE_SQUARED(*_gps, *near);
 
        /* Now, search _route for a closer point.  If quick is TRUE, then we'll
         * only search forward, only as long as we keep finding closer points.
         */
        for (curr = _near_point; curr++ != _route.tail;) {
                if (curr->unity) {
-                       guint dist_squared = DISTANCE_SQUARED(_pos, *curr);
+                       guint dist_squared = DISTANCE_SQUARED(*_gps, *curr);
                        if (dist_squared <= near_dist_squared) {
                                near = curr;
                                near_dist_squared = dist_squared;
@@ -560,12 +559,12 @@ if (_next_way) {
 
        for (wnext = wcurr = _next_way; wcurr != _route.wtail; wcurr++) {
                if (wcurr->point < near || (wcurr->point == near && quick 
-                               && (_next_wpt && (DISTANCE_SQUARED(_pos, *near) > _next_way_dist_squared
-                               && DISTANCE_SQUARED(_pos, *_next_wpt) < _next_wpt_dist_squared))))
+                               && (_next_wpt && (DISTANCE_SQUARED(*_gps, *near) > _next_way_dist_squared
+                               && DISTANCE_SQUARED(*_gps, *_next_wpt) < _next_wpt_dist_squared))))
                    /* Okay, this else if expression warrants explanation.  If the
                     * nearest track point happens to be a waypoint, then we want to
                     * check if we have "passed" that waypoint.  To check this, we
-                    * test the distance from _pos to the waypoint and from _pos to
+                    * test the distance from _gps to the waypoint and from _gps to
                     * _next_wpt, and if the former is increasing and the latter is
                     * decreasing, then we have passed the waypoint, and thus we
                     * should skip it.  Note that if there is no _next_wpt, then
@@ -576,8 +575,8 @@ if (_next_way) {
        }
 
        if (wnext == _route.wtail && (wnext->point < near || (wnext->point == near && quick
-                                         && (_next_wpt && (DISTANCE_SQUARED (_pos, *near) > _next_way_dist_squared
-                                              && DISTANCE_SQUARED(_pos, *_next_wpt) < _next_wpt_dist_squared)))))
+                                         && (_next_wpt && (DISTANCE_SQUARED (*_gps, *near) > _next_way_dist_squared
+                                              && DISTANCE_SQUARED(*_gps, *_next_wpt) < _next_wpt_dist_squared)))))
        {
                _next_way = NULL;
                _next_wpt = NULL;
@@ -603,9 +602,9 @@ if (_next_way) {
                        }
                        ret = TRUE;
                }
-               _next_way_dist_squared = DISTANCE_SQUARED(_pos, *wnext->point);
+               _next_way_dist_squared = DISTANCE_SQUARED(*_gps, *wnext->point);
                if (_next_wpt)
-                       _next_wpt_dist_squared = DISTANCE_SQUARED(_pos, *_next_wpt);
+                       _next_wpt_dist_squared = DISTANCE_SQUARED(*_gps, *_next_wpt);
        }
 }
 return ret;
@@ -659,7 +658,7 @@ if (point == NULL && _next_way)
 if (point == NULL)
        return FALSE;
 
-unit2latlon(_pos.unitx, _pos.unity, lat1, lon1);
+unit2latlon(_gps->unitx, _gps->unity, lat1, lon1);
 if (point > _near_point) {
        Point *curr;
        /* Skip _near_point in case we have already passed it. */
@@ -737,7 +736,7 @@ if (_route.head != _route.tail) {
 /***/
 
 GtkListStore *
-route_generate_store(void)
+route_generate_store(Path *route)
 {
 WayPoint *wcurr;
 GtkTreeIter iter;
@@ -747,10 +746,10 @@ gchar buffer2[32];
 gdouble lat1, lon1, lat2, lon2;
 gfloat sum=0.0;
 
-if (_route.whead==_route.wtail)
+if (route->whead==route->wtail)
        return NULL;
 
-wcurr = _route.whead;
+wcurr=route->whead;
 
 if (!wcurr->point)
        return NULL;
@@ -759,7 +758,7 @@ unit2latlon(wcurr->point->unitx, wcurr->point->unity, lat1, lon1);
 
 store = gtk_list_store_new(ROUTE_NUM_COLUMNS,G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING);
 
-while (wcurr!=_route.wtail) {
+while (wcurr!=route->wtail) {
        if (!wcurr)
                break;