]> err.no Git - mapper/commitdiff
Move code around
authorKaj-Michael Lang <milang@tal.org>
Fri, 6 Jun 2008 15:48:55 +0000 (18:48 +0300)
committerKaj-Michael Lang <milang@tal.org>
Fri, 6 Jun 2008 15:48:55 +0000 (18:48 +0300)
src/path.c
src/route.c

index 06a5221c1e5ea64b3f18b34c5e23bcfffae5b234..b9808edf988048229646f74ce51d2e2d0eb1a701 100644 (file)
@@ -69,6 +69,7 @@ enum {
        NEAR_WAYPOINT,                  /* We are near the next route waypoint */
        REACHED_WAYPOINT,               /* We have reached the next route waypoint */
        REACHED_DESTINATION,    /* We have reached the last route waypoint */
+       CLEARED,                                /* Path was cleared */
        LAST_SIGNAL
 };
 static guint32 signals[LAST_SIGNAL] = {0};
@@ -152,7 +153,6 @@ void
 path_free(Path *path)
 {
 g_return_if_fail(path);
-g_debug("path_free");
 g_object_unref(path);
 }
 
@@ -452,6 +452,39 @@ path->next_wpt_dist_squared=-1;
 
 }
 
+WayPoint *
+path_find_nearest_waypoint(Path *path, guint unitx, guint unity)
+{
+WayPoint *wcurr;
+WayPoint *wnear;
+guint64 nearest_squared;
+Point pos = { unitx, unity, 0, NAN };
+
+g_return_val_if_fail(path, NULL);
+
+wcurr=wnear=path->whead;
+if (wcurr && wcurr->point && wcurr!=path->wtail) {
+       nearest_squared=DISTANCE_SQUARED(pos, *(wcurr->point));
+
+       while (wcurr++!=path->wtail) {
+               guint64 test_squared=DISTANCE_SQUARED(pos, *(wcurr->point));
+               if (test_squared < nearest_squared) {
+                       wnear=wcurr;
+                       nearest_squared=test_squared;
+               }
+       }
+}
+
+if (wnear && wnear->point) {
+       /* Only use the waypoint if it is within a 6*_draw_width square drawn
+        * around the position. This is consistent with select_poi(). */
+       if (abs(unitx - wnear->point->unitx) < pixel2unit(3 * path->sensitivity) && abs(unity - wnear->point->unity) < pixel2unit(3 * path->sensitivity))
+               return wnear;
+}
+
+return NULL;
+}
+
 /******************************************************************************/
 
 gdouble
@@ -601,11 +634,17 @@ if (text) {
        path->wtail->desc=text;
 } else {
        path->wpcnt++;
-       path->wtail->desc=g_strdup_printf("WP%u", path->wpcnt);
+       path->wtail->desc=g_strdup_printf("WPT:#%u", path->wpcnt);
 }
 g_signal_emit(G_OBJECT(path), signals[NEW_WAYPOINT], 0, NULL);
 }
 
+void
+path_insert_mark_autonumber(Path *path)
+{
+path_insert_mark_text(path, NULL);
+}
+
 /******************************************************************************/
 #if 0
 static void
index d5d9ac228ba500f42ed75269711cdf77078924be..ab15bbbb4f1fdfdf4be3df0cd2bc1e05b60a6ba3 100644 (file)
@@ -32,8 +32,8 @@
 #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)))
+       ((guint64)((((gint64)(b).unitx)-(a).unitx)*(((gint64)(b).unitx)-(a).unitx))\
+       + (guint64)((((gint64)(b).unity)-(a).unity)*(((gint64)(b).unity)-(a).unity)))
 
 static gboolean show_directions=TRUE;
 
@@ -468,8 +468,6 @@ while (GTK_RESPONSE_ACCEPT == gtk_dialog_run(GTK_DIALOG(dialog))) {
                        gtk_list_store_insert_with_values(_loc_model, &iter, INT_MAX, 0, to, -1);
                }
 
-               map_force_redraw();
-
                MACRO_BANNER_SHOW_INFO(_window, _("Route Downloaded"));
                g_free(rdl_data.bytes);
                route_set_destination_from_last(route, &_dest);
@@ -489,41 +487,6 @@ gtk_widget_hide(dialog);   /* Destroying causes a crash (!?!?!??!) */
 return r;
 }
 
-WayPoint *
-route_find_nearest_waypoint(Path *route, guint unitx, guint unity)
-{
-WayPoint *wcurr;
-WayPoint *wnear;
-guint64 nearest_squared;
-Point pos = { unitx, unity, 0, NAN };
-
-g_return_val_if_fail(route, NULL);
-
-wcurr = wnear = route->whead;
-if (wcurr && wcurr->point && wcurr != route->wtail) {
-       nearest_squared = DISTANCE_SQUARED(pos, *(wcurr->point));
-
-       while (wcurr++ != route->wtail) {
-               guint64 test_squared = DISTANCE_SQUARED(pos, *(wcurr->point));
-               if (test_squared < nearest_squared) {
-                       wnear = wcurr;
-                       nearest_squared = test_squared;
-               }
-       }
-}
-
-if (wnear && wnear->point) {
-       /* Only use the waypoint if it is within a 6*_draw_width square drawn
-        * around the position. This is consistent with select_poi(). */
-       if (abs(unitx - wnear->point->unitx) < pixel2unit(3 * _draw_width) && abs(unity - wnear->point->unity) < pixel2unit(3 * _draw_width))
-               return wnear;
-}
-
-MACRO_BANNER_SHOW_INFO(_window, _("There are no waypoints."));
-
-return NULL;
-}
-
 /**
  * Show the distance from the current GPS location to the given point,
  * following the route. If point is NULL, then the distance is shown to the