Ticket #660: trac660.patch

File trac660.patch, 3.8 KB (added by mvglasow (2), 5 years ago)
  • navit/navit/navigation.c

    From 4662baec1c22781da74f7338e008e24c8f297f1b Mon Sep 17 00:00:00 2001
    From: mvglasow <michael -at- vonglasow.com>
    Date: Sat, 27 Sep 2014 00:35:18 +0200
    Subject: [PATCH] route: Catch some ambiguous cases that didn't create a
     maneuver
    
    Signed-off-by: mvglasow <michael -at- vonglasow.com>
    ---
     navit/navit/navigation.c |   60 +++++++++++++++++++++++++++++++++++++++++++++-
     1 file changed, 59 insertions(+), 1 deletion(-)
    
    diff --git a/navit/navit/navigation.c b/navit/navit/navigation.c
    index 1129c9e..3f82af1 100644
    a b maneuver_required2(struct navigation *nav, struct navigation_itm *old, struct na 
    11851185                /* If the other way is only a ramp and it is one-way in the wrong direction, no announcement necessary */
    11861186                r="no: Only ramp";
    11871187        }
     1188        if (!r) {
     1189                if (new->way.item.type == type_ramp) {
     1190                        /* If new is a ramp, ANNOUNCE */
     1191                        r="yes: entering ramp";
     1192                        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))) {
     1194                        /* If we are at a motorway interchange, ANNOUNCE
     1195                         * We are assuming a motorway interchange when old way and at least
     1196                         * 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
     1200                         * If any of the possible ways is neither motorway-like nor a ramp,
     1201                         * we are probably on a trunk road with level crossings and not
     1202                         * at a motorway interchange.
     1203                         */
     1204                        // FIXME: motorway junctions could have service roads
     1205                        int num_new_motorways = 0;
     1206                        int num_other = 0;
     1207                        struct navigation_way *cur_itm = &(new->way);
     1208                        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)) {
     1210                                        num_new_motorways++;
     1211                                } else if (cur_itm->item.type != type_ramp) {
     1212                                        num_other++;
     1213                                }
     1214                                cur_itm = cur_itm->next;
     1215                        }
     1216                        if ((num_other == 0) && (num_new_motorways > 1)) {
     1217                                r="yes: motorway interchange";
     1218                                ret=1;
     1219                        }
     1220                }
     1221        }
    11881222        if (! r) {
     1223                /* Announce exit from roundabout, but not entry or staying in it */
    11891224                if ((old->way.flags & AF_ROUNDABOUT) && ! (new->way.flags & AF_ROUNDABOUT)) {
    11901225                        r="yes: leaving roundabout";
    11911226                        ret=1;
    maneuver_required2(struct navigation *nav, struct navigation_itm *old, struct na 
    11941229                } else if ((old->way.flags & AF_ROUNDABOUT) && (new->way.flags & AF_ROUNDABOUT))
    11951230                        r="no: staying in roundabout";
    11961231        }
     1232        cat=maneuver_category(old->way.item.type);
    11971233        if (!r && abs(d) > 75) {
    11981234                /* always make an announcement if you have to make a sharp turn */
    11991235                r="yes: delta over 75";
    12001236                ret=1;
     1237        } else if (!r && abs(d) > 22) {
     1238                /* When coming from street_2_* or higher category road, check if
     1239                 * - we have multiple options of the same category and
     1240                 * - we have to make a considerable turn (more than 22 degrees)
     1241                 * If both is the case, ANNOUNCE.
     1242                 * Note: 22.5 degrees is the threshold because anything higher is
     1243                 * closer to 45 than to 0 degrees.
     1244                 */
     1245                if (cat >= maneuver_category(type_street_2_city)) {
     1246                        int num_similar = 0;
     1247                        struct navigation_way *cur_itm = &(new->way);
     1248                        while (cur_itm) {
     1249                                if (maneuver_category(cur_itm->item.type) == cat) {
     1250                                        // TODO: decide if a maneuver_category difference of 1 is still similar
     1251                                        num_similar++;
     1252                                }
     1253                                cur_itm = cur_itm->next;
     1254                        }
     1255                        if (num_similar > 1) {
     1256                                ret=1;
     1257                                r="yes: more than one similar road and delta over 22";
     1258                        }
     1259                }
    12011260        }
    1202         cat=maneuver_category(old->way.item.type);
    12031261        ncat=maneuver_category(new->way.item.type);
    12041262        if (!r) {
    12051263                int dc=d;