Example #1
0
// checks if a positions is on the same street as a segment
static int check_same_street(const PluginLine *line, const RoadMapPosition *point_position) {

    const char *street_name;
    const char *city_name;
    char			current_street_name[512];
    char			current_city_name[512];
    int point_res;
    int square_current = roadmap_square_active ();

    get_street_from_line (line->square, line->line_id, &street_name, &city_name);
    strncpy_safe (current_street_name, street_name, sizeof (current_street_name));
    strncpy_safe (current_city_name, city_name, sizeof (current_city_name));

    point_res = get_street(point_position, &street_name, &city_name);

    roadmap_square_set_current (square_current);

    if (point_res == -1)
        return FALSE;

    if (strcmp (current_street_name, street_name) == 0 &&
            strcmp (current_city_name, city_name) == 0)
        return TRUE;
    else
        return FALSE;

}
Example #2
0
static int editor_override_find (int line, editor_db_override **data, int *create) {

   int id;
   int count;
   int square = roadmap_square_active ();
   editor_db_override *rec;
   
   count = editor_db_get_item_count (ActiveOverridesDB);

	for (id = 0; id < count; id++) {
		
		rec = (editor_db_override *)editor_db_get_item (ActiveOverridesDB, id, 0, NULL);
		if (rec->square == square && rec->line == line) {
			if (create) *create = 0;
			break;
		}
	}
	
	if (id == count) {
		if (!create) return -1;
		
		id = editor_db_add_item (ActiveOverridesDB, NULL, 0); 
		if (id >= 0) {
			rec = (editor_db_override *)editor_db_get_item (ActiveOverridesDB, id, 0, NULL);
			rec->square = square;
			rec->line = line;
			rec->flags = 0;
			rec->direction = roadmap_line_route_get_direction (line, ROUTE_CAR_ALLOWED);
			*create = 1;
		}
	}
	
	if (data) *data = rec;
	return id;
}
Example #3
0
int navigate_graph_get_line (int node, int line_no) {

   int square = roadmap_square_active (); //roadmap_point_square (node);
   struct SquareGraphItem *cache = get_square_graph (square);
   int i;
   int skip;

   node &= 0xffff;

   i = cache->nodes_index[node];
   assert (i > 0);
   i--;

   skip = line_no;
   while (skip) {
      i = cache->lines_index[i];
	   assert (i > 0);
	   i--;
      skip--;
   }

   return cache->lines[i];
}
Example #4
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;
}
Example #5
0
/*
 * searches for relevant alerts in the given param provider - D.F.
 */
static BOOL is_alert_in_range_provider(roadmap_alert_provider* provider,
      const RoadMapGpsPosition *gps_position, const PluginLine* line,
      int * pAlert_index, int * pDistance, const char* cur_street_name){
   int i;
   int steering;
   RoadMapPosition pos;
   int azymuth;
   int delta;
   int square_current;
   int count = 0;
   const char *street_name;
   roadmap_alerter_location_info location_info;
   roadmap_alerter_location_info * pAlert_location_info = NULL;
   RoadMapPosition gps_pos;
   gps_pos.latitude = gps_position->latitude;
   gps_pos.longitude = gps_position->longitude;
   square_current = roadmap_square_active ();
   count =  (* (provider->count)) ();

   // no alerts for this provider
   if (count == 0) {
      return FALSE;
   }

   for (i=0; i<count; i++) {

      roadmap_square_set_current (square_current);
      // if the alert is not alertable, continue. (dummy speed cams, etc.)
      if (!(* (provider->is_alertable))(i)) {
         continue;
      }

      (* (provider->get_position)) (i, &pos, &steering);

      // check that the alert is within alert distance
      * pDistance = roadmap_math_distance(&pos, &gps_pos);

      if (*pDistance > (*(provider->get_distance))(i))
         continue;

      // Let the provider handle the Alert.
      if ((* (provider->handle_event))((* (provider->get_id))(i)))
         continue;

      // get this alerts cached location info
      pAlert_location_info = (*(provider->get_location_info))(i);

      // retrieve the current location info for this alert ( square id, line id... )
      if(!get_alert_location_info(&pos,&location_info,pAlert_location_info))
         continue; // could not find relevant location.

      // check if the alert is on the navigation route
      if (!alert_is_on_route (&location_info, steering)) {

         roadmap_square_set_current (square_current);
         if ((* (provider->check_same_street))(i)){

            // check that the alert is in the direction of driving
            delta = azymuth_delta(gps_position->steering, steering);
            if (delta > AZYMUTH_DELTA || delta < (0-AZYMUTH_DELTA)) {
               continue;
            }

            // check that we didnt pass the alert
            azymuth = roadmap_math_azymuth (&gps_pos, &pos);
            delta = azymuth_delta(azymuth, steering);
            if (delta > 90|| delta < (-90))
               continue;

            // get the street name of the alert
            get_street_from_line(location_info.square_id,location_info.line_id, &street_name);

            // if same street found an alert infront of us
            if(strcmp(street_name,cur_street_name))
               continue; // not the same street.

         }
      }

      // if we got until here, then we found a valid alert
      * pAlert_index = i;
      roadmap_square_set_current (square_current);
      return TRUE;

   }

   roadmap_square_set_current (square_current);
   return FALSE;
}