return p;
}
+/**
+ * Updates near_point, next_way, and next_wpt. If quick is FALSE (as
+ * it is when this function is called from route_find_nearest_point), then
+ * the entire list (starting from near_point) is searched. Otherwise, we
+ * stop searching when we find a point that is farther away.
+ */
+gboolean
+path_update_nears(Path *route, Point *point, gboolean quick)
+{
+gboolean ret = FALSE;
+Point *curr, *near;
+WayPoint *wcurr, *wnext;
+guint64 near_dist_squared;
+
+g_return_val_if_fail(route, FALSE);
+
+/* If we have waypoints (_next_way != NULL), then determine the "next
+ * waypoint", which is defined as the waypoint after the nearest point,
+ * UNLESS we've passed that waypoint, in which case the waypoint after
+ * that waypoint becomes the "next" waypoint. */
+if (route->next_way) {
+ /* First, set near_dist_squared with the new distance from
+ * near_point. */
+ near = route->near_point;
+ near_dist_squared = DISTANCE_SQUARED(point, *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 = route->near_point; curr++ != route->tail;) {
+ if (curr->unity) {
+ guint dist_squared = DISTANCE_SQUARED(point, *curr);
+ if (dist_squared <= near_dist_squared) {
+ near = curr;
+ near_dist_squared = dist_squared;
+ } else if (quick)
+ break;
+ }
+ }
+
+ /* Update _near_point. */
+ route->near_point = near;
+ route->near_point_dist_squared = near_dist_squared;
+
+ for (wnext = wcurr = route->next_way; wcurr != route->wtail; wcurr++) {
+ if (wcurr->point < near || (wcurr->point == near && quick
+ && (route->next_wpt && (DISTANCE_SQUARED(point, *near) > route->next_way_dist_squared
+ && DISTANCE_SQUARED(point, *route->next_wpt) < route->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 _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
+ * there is no next waypoint, so we do not skip it in that case. */
+ wnext = wcurr + 1;
+ else
+ break;
+ }
+
+ if (wnext == route->wtail && (wnext->point < near || (wnext->point == near && quick
+ && (route->next_wpt && (DISTANCE_SQUARED (_gps->data, *near) > route->next_way_dist_squared
+ && DISTANCE_SQUARED(point, *route->next_wpt) < route->next_wpt_dist_squared)))))
+ {
+ route->next_way = NULL;
+ route->next_wpt = NULL;
+ route->next_way_dist_squared = -1;
+ route->next_wpt_dist_squared = -1;
+ ret = TRUE;
+ }
+ /* Only update next_way (and consequently _next_wpt) if _next_way is
+ * different, and record that fact for return. */
+ else {
+ if (!quick || route->next_way != wnext) {
+ route->next_way = wnext;
+ route->next_wpt = wnext->point;
+ if (route->next_wpt == route->tail)
+ route->next_wpt = NULL;
+ else {
+ while (!(++route->next_wpt)->unity) {
+ if (route->next_wpt == route->tail) {
+ route->next_wpt = NULL;
+ break;
+ }
+ }
+ }
+ ret = TRUE;
+ }
+ route->next_way_dist_squared = DISTANCE_SQUARED(_gps->data, *wnext->point);
+ if (route->next_wpt)
+ route->next_wpt_dist_squared = DISTANCE_SQUARED(_gps->data, *route->next_wpt);
+ }
+}
+return ret;
+}
+
+/******************************************************************************/
+
gdouble
path_get_distance_to(Path *path, Point *point, gdouble lat, gdouble lon)
{
return sum;
}
+/******************************************************************************/
+
gboolean
path_load(Path *path, const gchar *config_dir, const gchar *file)
{
return TRUE;
}
+/******************************************************************************/
+
gboolean
path_get_waypoint_latlon(WayPoint *way, gdouble *lat, gdouble *lon)
{
g_signal_emit(G_OBJECT(path), signals[NEW_WAYPOINT], 0, NULL);
}
+/******************************************************************************/
#if 0
static void
path_store_append_waypoint(GtkListStore *, WayPoint *w)
static poi_quick_data tqp;
+osm_location map_loc;
+
/* A GPS icon would be nice.. anyone ? */
#ifndef GTK_STOCK_INFO
ui = gtk_ui_manager_new ();
g_assert(ui);
-gtk_action_group_add_actions (actions, ui_entries, n_ui_entries, NULL);
-gtk_action_group_add_toggle_actions (actions, ui_toggle_entries, n_ui_toggle_entries, NULL);
-gtk_action_group_add_radio_actions (actions, ui_autocenter_entries,
- n_ui_autocenter_entries, _center_mode, G_CALLBACK(menu_cb_autocenter), NULL);
-
-gtk_ui_manager_insert_action_group (ui, actions, 0);
-g_object_unref (actions);
-
/* N810 has keyboard so set this up on hildon too */
-gtk_window_add_accel_group (GTK_WINDOW(_window), gtk_ui_manager_get_accel_group (ui));
+gtk_window_add_accel_group(GTK_WINDOW(_window), gtk_ui_manager_get_accel_group (ui));
-if (!gtk_ui_manager_add_ui_from_string (ui, mapper_ui, -1, &error)) {
+if (!gtk_ui_manager_add_ui_from_string(ui, mapper_ui, -1, &error)) {
g_message ("building menus failed: %s", error->message);
g_error_free(error);
g_assert(FALSE);
gtk_map_set_cache_size(_map, 256);
#endif
+gtk_action_group_add_actions(actions, ui_entries, n_ui_entries, NULL);
+gtk_action_group_add_toggle_actions(actions, ui_toggle_entries, n_ui_toggle_entries, NULL);
+gtk_action_group_add_radio_actions(actions, ui_autocenter_entries,
+ n_ui_autocenter_entries, gtk_map_get_center_mode(_map), G_CALLBACK(menu_cb_autocenter), NULL);
+
+gtk_ui_manager_insert_action_group(ui, actions, 0);
+g_object_unref(actions);
+
/* GPS Tab */
vbox = gtk_vbox_new(FALSE, 0);
label = gtk_label_new("Gps");
{
g_assert(gps);
if (filter_check(&filter, &gps->data, &map_loc)==TRUE) {
- if (track_add(_track, &_gps->data)) {
- KEEP_DISPLAY_ON();
- route_check_waypoint_announce(_route, &_gps->data);
+ if (path_add(_track, &_gps->data)) {
+ path_check_waypoint_announce(_route, &_gps->data);
+#if 0
route_autoroute_check(_route);
+#endif
+ KEEP_DISPLAY_ON();
}
- map_refresh_mark();
}
return FALSE;
}