From: Kaj-Michael Lang Date: Fri, 6 Jun 2008 15:48:55 +0000 (+0300) Subject: Move code around X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=cc08506eced42f1c59e52a9a98428af19fc13d5b;p=mapper Move code around --- diff --git a/src/path.c b/src/path.c index 06a5221..b9808ed 100644 --- a/src/path.c +++ b/src/path.c @@ -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 diff --git a/src/route.c b/src/route.c index d5d9ac2..ab15bbb 100644 --- a/src/route.c +++ b/src/route.c @@ -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