Exemplo n.º 1
0
/*
 * Loads small Restaurant Distance structs for the restaurants
 * that meet the minimum rating into a supplied array,
 * and returns the numbers of restaurants loaded
 */
uint16_t loadDistances(uint16_t horiz, uint16_t vert, uint8_t minimumRating, RestDist *distances) {
  uint16_t skippedRestaurants = 0;
  uint16_t distancesIndex = 0;

  for(int i = 0; i < RESTAURANTS_COUNT; i++) {
    Restaurant rest;
    getRestaurant(i, &rest, &card);
    if(rest.rating >= minimumRating) {
      uint16_t rest_horiz = lon_to_x(rest.longitude_scaled);
      uint16_t rest_vert = lat_to_y(rest.latitude_scaled);

      uint16_t distance = manhattanDist(horiz, vert, rest_horiz, rest_vert);

      RestDist restDist = { i, distance };
      distances[distancesIndex] = restDist;
      distancesIndex++;
    } else {
      skippedRestaurants++;
    }
  }
  return RESTAURANTS_COUNT - skippedRestaurants;
}
Exemplo n.º 2
0
/**
 * \fn lon_to_pixels(double lon, double map_minlon, double map_maxlon)
 * \brief Fonction qui convertit une longitude GPS en une valeur en pixel (entre 0 et 1)
 *
 * \param lon longitude de type double a convertir.
 * \param map_minlon la longitude minimum de la map
 * \param map_maxlon la longitude maximal de la map
 * \return Retourne un double correspondant a la longitude GPS convertit en pixel
 */
double lon_to_pixels(double lon, double map_minlon, double map_maxlon){
	return (lon_to_x(lon) - lon_to_x(map_minlon)) / (lon_to_x(map_maxlon) - lon_to_x(map_minlon));
}
Exemplo n.º 3
0
gboolean download_cb(GtkWidget *widget, WizzardDownload * wizzard)
{
	printf("ok\n");

	Selection * selection = &(wizzard -> select_use_window -> selection);
	gboolean to_load[18];
	int i;
	for (i = 0; i < 18; i++){
		to_load[i] = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(wizzard -> select_use_window -> to_load_wid[i]));
	}

	gboolean one_selected = FALSE;
	for (i = 0; i < 18; i++){
		if (to_load[i]){
			one_selected = TRUE;
			break;
		}
	}	
	if (!one_selected){
		return;
	}

	gtk_widget_hide_all(GTK_WIDGET(wizzard -> select_use_window));

	int count = 0;
        for (i = 1; i <= 18; i++){
                if (to_load[i-1]){
                        double x1 = lon_to_x(selection->lon1, i);
                        double x2 = lon_to_x(selection->lon2, i);
                        double y1 = lat_to_y(selection->lat1, i);
                        double y2 = lat_to_y(selection->lat2, i);
                        int count_x = ((int) x2) - ((int)x1) + 1;
                        int count_y = ((int) y2) - ((int)y1) + 1;
                        count += count_x * count_y;
                }
        }
	wizzard -> total = count;

	// destroy?

	wizzard -> tile_download_window = GOSM_TILE_DOWNLOAD_WINDOW(tile_download_window_new(selection, to_load));
	gtk_window_set_title(GTK_WINDOW(wizzard ->  tile_download_window), "Loading Tiles...");
	gtk_window_set_position(GTK_WINDOW(wizzard ->  tile_download_window), GTK_WIN_POS_CENTER_ON_PARENT);
	gtk_window_set_transient_for(GTK_WINDOW(wizzard ->  tile_download_window), GTK_WINDOW(wizzard -> parent_window));
	gtk_window_set_modal(GTK_WINDOW(wizzard ->  tile_download_window), FALSE);
	gtk_widget_show_all(GTK_WIDGET(wizzard ->  tile_download_window));
	
	g_signal_connect(G_OBJECT(wizzard -> tile_download_window -> button_pause), "clicked", G_CALLBACK(pause_cb), wizzard);
	g_signal_connect(G_OBJECT(wizzard -> tile_download_window -> button_cancel), "clicked", G_CALLBACK(cancel_download_window_cb), wizzard);

	// download tiles, update window
	wizzard -> tile_loader = GOSM_TILE_LOADER(tile_loader_new());
	tile_loader_set_cache_directory(wizzard -> tile_loader, wizzard -> download_dir);
	tile_loader_set_url_format(wizzard -> tile_loader, wizzard -> format_url);

	wizzard -> handler_id_tile_loaded = g_signal_connect(G_OBJECT(wizzard -> tile_loader), "tile-loaded-succesfully", G_CALLBACK(loaded_cb), wizzard);

	int x1, x2, y1, y2, ix, iy, zoom;
	for (i = 0; i < 18; i++){
		zoom = i+1;
		if (to_load[i]){
			x1 = (int)lon_to_x(selection->lon1, zoom);
			x2 = (int)lon_to_x(selection->lon2, zoom);
			y1 = (int)lat_to_y(selection->lat1, zoom);
			y2 = (int)lat_to_y(selection->lat2, zoom);
			for (ix = x1; ix <= x2; ix++){
				for (iy = y1; iy <= y2; iy++){
					MapTile map_tile = {ix, iy, zoom};
					tile_loader_add_tile(wizzard -> tile_loader, map_tile);
				}
			}
		}
	}
	tile_loader_start(wizzard -> tile_loader);
}