Ticket #660: trac660_r5911.patch

File trac660_r5911.patch, 5.6 KB (added by mvglasow (2), 5 years ago)

Third version of patch, applies on top of r5911 (replaces second version)

  • navit/navit/navigation.c

    diff --git a/navit/navit/navigation.c b/navit/navit/navigation.c
    index 3f82af1..713bc4b 100644
    a b is_way_allowed(struct navigation *nav, struct navigation_way *way, int mode) 
    11561156}
    11571157
    11581158/**
     1159 * @brief Checks whether a way has motorway-like characteristics
     1160 *
     1161 * Motorway-like means one of the following:
     1162 * <ul>
     1163 * <li>
     1164 * item type is {@code highway_land} or {@code highway_city} (OSM: {@code highway=motorway})
     1165 * </li>
     1166 * <li>
     1167 * item type is {@code street_n_lanes} (OSM: {@code highway=trunk}) and way is one-way
     1168 * </li>
     1169 * </ul>
     1170 *
     1171 * @param way The way to examine
     1172 * @return True for motorway-like, false otherwise
     1173 */
     1174static int
     1175is_motorway_like(struct navigation_way *way)
     1176{
     1177        if ((way->item.type == type_highway_land) || (way->item.type == type_highway_city)  || ((way->item.type == type_street_n_lanes) && (way->flags & AF_ONEWAYMASK)))
     1178                return 1;
     1179        return 0;
     1180}
     1181
     1182/**
    11591183 * @brief Checks if navit has to create a maneuver to drive from old to new
    11601184 *
    11611185 * This function checks if it has to create a "maneuver" - i.e. guide the user - to drive
    maneuver_required2(struct navigation *nav, struct navigation_itm *old, struct na 
    11851209                /* If the other way is only a ramp and it is one-way in the wrong direction, no announcement necessary */
    11861210                r="no: Only ramp";
    11871211        }
     1212        if (! r) {
     1213                /* Announce exit from roundabout, but not entry or staying in it */
     1214                if ((old->way.flags & AF_ROUNDABOUT) && ! (new->way.flags & AF_ROUNDABOUT)) {
     1215                        r="yes: leaving roundabout";
     1216                        ret=1;
     1217                } else  if (!new->way.next->next && !(old->way.flags & AF_ROUNDABOUT) && (new->way.flags & AF_ROUNDABOUT) && (new->way.next->flags & AF_ROUNDABOUT)) {
     1218                        /* this rather complicated construct makes sure we suppress announcements
     1219                         * only when we're entering a roundabout AND there are no other options */
     1220                        r="no: entering roundabout";
     1221                } else if ((old->way.flags & AF_ROUNDABOUT) && (new->way.flags & AF_ROUNDABOUT)) {
     1222                        r="no: staying in roundabout";
     1223                }
     1224        }
    11881225        if (!r) {
    11891226                if (new->way.item.type == type_ramp) {
    11901227                        /* If new is a ramp, ANNOUNCE */
    11911228                        r="yes: entering ramp";
    11921229                        ret=1;
    1193                 } else if ((old->way.item.type == type_highway_land) || (old->way.item.type == type_highway_city)  || ((old->way.item.type == type_street_n_lanes) && (old->way.flags & AF_ONEWAYMASK))) {
     1230                } else if (is_motorway_like(&(old->way))) {
    11941231                        /* If we are at a motorway interchange, ANNOUNCE
    11951232                         * We are assuming a motorway interchange when old way and at least
    11961233                         * two possible ways are motorway-like and allowed.
    1197                          * Motorway-like means one of the following:
    1198                          * - item type is highway_land or highway_city
    1199                          * - item type is street_n_lanes (trunk in OSM) and way is one-way
    12001234                         * If any of the possible ways is neither motorway-like nor a ramp,
    12011235                         * we are probably on a trunk road with level crossings and not
    12021236                         * at a motorway interchange.
    maneuver_required2(struct navigation *nav, struct navigation_itm *old, struct na 
    12061240                        int num_other = 0;
    12071241                        struct navigation_way *cur_itm = &(new->way);
    12081242                        while (cur_itm) {
    1209                                 if (((cur_itm->item.type == type_highway_land) || (cur_itm->item.type == type_highway_city) || ((cur_itm->item.type == type_street_n_lanes) && (cur_itm->flags & AF_ONEWAYMASK))) && is_way_allowed(nav,cur_itm,1)) {
     1243                                if ((is_motorway_like(cur_itm)) && is_way_allowed(nav,cur_itm,1)) {
    12101244                                        num_new_motorways++;
    12111245                                } else if (cur_itm->item.type != type_ramp) {
    12121246                                        num_other++;
    maneuver_required2(struct navigation *nav, struct navigation_itm *old, struct na 
    12191253                        }
    12201254                }
    12211255        }
    1222         if (! r) {
    1223                 /* Announce exit from roundabout, but not entry or staying in it */
    1224                 if ((old->way.flags & AF_ROUNDABOUT) && ! (new->way.flags & AF_ROUNDABOUT)) {
    1225                         r="yes: leaving roundabout";
    1226                         ret=1;
    1227                 } else  if (!(old->way.flags & AF_ROUNDABOUT) && (new->way.flags & AF_ROUNDABOUT)) {
    1228                         r="no: entering roundabout";
    1229                 } else if ((old->way.flags & AF_ROUNDABOUT) && (new->way.flags & AF_ROUNDABOUT))
    1230                         r="no: staying in roundabout";
    1231         }
    12321256        cat=maneuver_category(old->way.item.type);
    12331257        if (!r && abs(d) > 75) {
    12341258                /* always make an announcement if you have to make a sharp turn */
    maneuver_required2(struct navigation *nav, struct navigation_itm *old, struct na 
    12791303                                        dc=dw;
    12801304                        }
    12811305                        wcat=maneuver_category(w->item.type);
    1282                         /* If any other street has the same name but isn't a highway (a highway might split up temporarily), then
    1283                            we can't use the same name criterium  */
    1284                         if (is_same_street && is_same_street2(old->way.name1, old->way.name2, w->name1, w->name2) && (cat != 7 || wcat != 7) && is_way_allowed(nav,w,2))
    1285                                 is_same_street=0;
    1286                         /* Even if the ramp has the same name, announce it */
    1287                         if (new->way.item.type == type_ramp && old->way.item.type != type_ramp)
     1306                        /* If any other street has the same name, we can't use the same name criterion.
     1307                         * Exceptions apply if we're coming from a motorway-like road and:
     1308                         * - the other road is motorway-like (a motorway might split up temporarily) or
     1309                         * - the other road is a ramp (they are sometimes tagged with the name of the motorway)
     1310                         * The second one is really a workaround for bad tagging practice in OSM. Since entering
     1311                         * a ramp always creates a maneuver, we don't expect the workaround to have any unwanted
     1312                         * side effects.
     1313                         */
     1314                        if (is_same_street && is_same_street2(old->way.name1, old->way.name2, w->name1, w->name2) && (!is_motorway_like(&(old->way)) || (!is_motorway_like(w) && w->item.type != type_ramp)) && is_way_allowed(nav,w,2))
    12881315                                is_same_street=0;
    12891316                        /* Mark if the street has a higher or the same category */
    12901317                        if (wcat > maxcat)