Exemplo n.º 1
0
int alert_is_on_route (roadmap_alerter_location_info *pInfo, int steering, roadmap_alert_provider* provider, int i ) {

   int rc = 0;
   int from;
   int to;
   RoadMapPosition from_position;
   RoadMapPosition to_position;
   int road_azymuth;
   int delta;

   BOOL is_alert_on_route = ((provider->is_on_route) && ((* (provider->is_on_route))((* (provider->get_id))(i))));

   if (is_alert_on_route)
      return TRUE;

   roadmap_square_set_current (pInfo->square_id);
   roadmap_line_points (pInfo->line_id, &from, &to);
   roadmap_point_position (from, &from_position);
   roadmap_point_position (to, &to_position);
   road_azymuth = roadmap_math_azymuth (&from_position, &to_position);
   delta = azymuth_delta (steering, road_azymuth);
   if (delta >= -90 && delta < 90)
      rc = navigate_is_line_on_route (pInfo->square_id, pInfo->line_id, from, to);
   else
      rc = navigate_is_line_on_route (pInfo->square_id, pInfo->line_id, to, from);
   return rc;
}
Exemplo n.º 2
0
static BOOL RealtimeAltRoutes_GetOrigin(RoadMapGpsPosition *pos, PluginLine *line, int *fromPoint){
   int direction;

   if ((roadmap_navigate_get_current (pos, line, &direction) != -1) &&
       (roadmap_plugin_get_id(line) == ROADMAP_PLUGIN_ID)){
      int from;
      int to;
      roadmap_square_set_current (line->square);
      roadmap_line_points (line->line_id, &from, &to);
      if (direction == ROUTE_DIRECTION_WITH_LINE){
         *fromPoint = to;
      } else{
         *fromPoint = from;
      }
      return TRUE;
   }
   return FALSE;
}
Exemplo n.º 3
0
static int alert_is_on_route (const RoadMapPosition *point_position, int steering) {

    int count = 0;
    int layers[128];
    int layers_count;
    RoadMapNeighbour neighbours;
    int rc = 0;
    int from;
    int to;
    RoadMapPosition from_position;
    RoadMapPosition to_position;
    int road_azymuth;
    int delta;
    int square_current = roadmap_square_active ();

    layers_count =  roadmap_layer_all_roads (layers, 128);
    if (layers_count > 0) {
        count = roadmap_street_get_closest
                (point_position, 0, layers, layers_count, &neighbours, 1);
        if (count > 0) {
            roadmap_square_set_current (neighbours.line.square);
            roadmap_line_points (neighbours.line.line_id, &from, &to);
            roadmap_point_position (from, &from_position);
            roadmap_point_position (to, &to_position);
            road_azymuth = roadmap_math_azymuth (&from_position, &to_position);
            delta = azymuth_delta (steering, road_azymuth);
            if (delta >= -90 && delta < 90)
                rc = navigate_is_line_on_route (neighbours.line.square, neighbours.line.line_id, from, to);
            else
                rc = navigate_is_line_on_route (neighbours.line.square, neighbours.line.line_id, to, from);
        }
    }

    roadmap_square_set_current (square_current);
    return rc;
}
Exemplo n.º 4
0
//TODO arrange as LRU list
static struct SquareGraphItem *get_square_graph (int square_id) {

   int i;
   int slot;
   int line;
   int lines1_count;
   int lines2_count;
   struct SquareGraphItem *cache;
   int cur_line = 0;
   int found = 0;

   for (slot = 0; slot < SquareCacheSize; slot++) {
     	if (SquareGraphCache[slot]->square_id == square_id) {
     		found = 1;
     		break;
     	}
   }

	if (!found) {
		if (SquareCacheSize == MAX_GRAPH_CACHE) {
			slot--;
			free_cache_slot (slot);
			cache = SquareGraphCache[slot];
		} else {
			cache = (struct SquareGraphItem *)malloc(sizeof(struct SquareGraphItem));
			SquareCacheSize++;
		}
	} else {
		cache = SquareGraphCache[slot];
	}

	for (i = slot; i > 0; i--) {
		SquareGraphCache[i] = SquareGraphCache[i - 1];
	}
	SquareGraphCache[0] = cache;

	if (found) return cache;
	
   cache->square_id = square_id;
   lines1_count = 0;
   lines2_count = 0;

   /* Count total lines */
   for (i = ROADMAP_ROAD_FIRST; i <= ROADMAP_ROAD_LAST; ++i) {

      int first_line;
      int last_line;

      if (roadmap_line_in_square
            (square_id, i, &first_line, &last_line) > 0) {

         lines1_count += (last_line - first_line + 1);
      }
   }

   cache->lines_count = lines1_count * 2 + lines2_count;

   /* assume that the number of nodes equals the number of lines */
   cache->nodes_count = roadmap_square_points_count (square_id);

   cache->mem_size = cache->lines_count * sizeof(int) +
                     cache->lines_count * sizeof(unsigned short) +
                     cache->nodes_count * sizeof(unsigned short);

   while (cache_total_mem &&
          ((cache_total_mem + cache->mem_size) > MAX_MEM_CACHE) &&
          SquareCacheSize > 1) {

		SquareCacheSize--;
      free_cache_slot(SquareCacheSize);
      free (SquareGraphCache[SquareCacheSize]);
      SquareGraphCache[SquareCacheSize] = NULL;
   }

   cache->lines = malloc(cache->lines_count * sizeof(int));
   cache->lines_index = calloc(cache->lines_count, sizeof(unsigned short));
   cache->nodes_index = calloc(cache->nodes_count, sizeof(unsigned short));

   cache_total_mem += cache->mem_size;

   for (i = ROADMAP_ROAD_LAST; i >= ROADMAP_ROAD_FIRST; --i) {

      int first_line;
      int last_line;

      if (roadmap_line_in_square
            (square_id, i, &first_line, &last_line) > 0) {

         for (line = last_line; line >= first_line; line--) {

            int from_point_id;
            int to_point_id;

            roadmap_line_points (line, &from_point_id, &to_point_id);
            from_point_id &= 0xffff;

            add_graph_node(cache, line, from_point_id, cur_line, 0);
            cur_line++;

            //if (roadmap_point_square(to_point_id) == square_id) {

               to_point_id &= 0xffff;

               add_graph_node(cache, line, to_point_id, cur_line, REVERSED);

               cur_line++;
            //}
         }
      }
   }

   assert(cur_line <= cache->lines_count);

   return cache;
}