From f7265892ed81368f14c717f9bd0ad615ff744e79 Mon Sep 17 00:00:00 2001 From: Moritz Kobitzsch Date: Fri, 2 Sep 2016 15:49:25 +0200 Subject: [PATCH] correctly detect loss of prefix/suffix --- CHANGELOG.md | 1 + features/guidance/suffix-changes.feature | 15 ++++- include/extractor/guidance/toolkit.hpp | 75 +++++++++++++----------- 3 files changed, 56 insertions(+), 35 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2856c3097..ff9cc7f32 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ - Fixed an issue that would result in segfaults for viaroutes with an invalid intermediate segment when u-turns were allowed at the via-location - Invalid only_* restrictions could result in loss of connectivity. As a fallback, we assume all turns allowed when the restriction is not valid - Fixed a bug that could result in an infinite loop when finding information about an upcoming intersection + - Fixed a bug that led to not discovering if a road simply looses a considered prefix # 5.3.0 Changes from 5.3.0-rc.3 diff --git a/features/guidance/suffix-changes.feature b/features/guidance/suffix-changes.feature index 9b53adbb3..06a5d2189 100644 --- a/features/guidance/suffix-changes.feature +++ b/features/guidance/suffix-changes.feature @@ -3,7 +3,7 @@ Feature: Suppress New Names on dedicated Suffices Background: Given the profile "car" - Given a grid size of 10 meters + Given a grid size of 2000 meters Scenario: Suffix To Suffix Given the node map @@ -44,6 +44,19 @@ Feature: Suppress New Names on dedicated Suffices | waypoints | route | turns | | a,c | West 42,East 42 | depart,arrive | + Scenario: Prefix Change ref + Given the node map + | a | | b | | c | + + And the ways + | nodes | name | + | ab | West 42 | + | bc | 42 | + + When I route I should get + | waypoints | route | turns | + | a,c | West 42,42 | depart,arrive | + Scenario: Prefix Change and Reference Given the node map | a | | b | | c | diff --git a/include/extractor/guidance/toolkit.hpp b/include/extractor/guidance/toolkit.hpp index b0cf1fdc5..7df23d434 100644 --- a/include/extractor/guidance/toolkit.hpp +++ b/include/extractor/guidance/toolkit.hpp @@ -205,43 +205,50 @@ inline bool requiresNameAnnounced(const std::string &from, const auto name_is_contained = boost::starts_with(from_name, to_name) || boost::starts_with(to_name, from_name); - const auto checkForPrefixOrSuffixChange = - [](const std::string &first, const std::string &second, const SuffixTable &suffix_table) { + const auto checkForPrefixOrSuffixChange = []( + const std::string &first, const std::string &second, const SuffixTable &suffix_table) { - const auto first_prefix_and_suffixes = getPrefixAndSuffix(first); - const auto second_prefix_and_suffixes = getPrefixAndSuffix(second); - // reverse strings, get suffices and reverse them to get prefixes - const auto checkTable = [&](const std::string str) { - return str.empty() || suffix_table.isSuffix(str); - }; - - const bool is_prefix_change = [&]() -> bool { - if (!checkTable(first_prefix_and_suffixes.first)) - return false; - if (!checkTable(first_prefix_and_suffixes.first)) - return false; - return !first.compare(first_prefix_and_suffixes.first.length(), - std::string::npos, - second, - second_prefix_and_suffixes.first.length(), - std::string::npos); - }(); - - const bool is_suffix_change = [&]() -> bool { - if (!checkTable(first_prefix_and_suffixes.second)) - return false; - if (!checkTable(first_prefix_and_suffixes.second)) - return false; - return !first.compare(0, - first.length() - first_prefix_and_suffixes.second.length(), - second, - 0, - second.length() - second_prefix_and_suffixes.second.length()); - }(); - - return is_prefix_change || is_suffix_change; + const auto first_prefix_and_suffixes = getPrefixAndSuffix(first); + const auto second_prefix_and_suffixes = getPrefixAndSuffix(second); + // reverse strings, get suffices and reverse them to get prefixes + const auto checkTable = [&](const std::string& str) { + return str.empty() || suffix_table.isSuffix(str); }; + const auto getOffset = [](const std::string &str) -> std::size_t { + if (str.empty()) + return 0; + else + return str.length() + 1; + }; + + const bool is_prefix_change = [&]() -> bool { + if (!checkTable(first_prefix_and_suffixes.first)) + return false; + if (!checkTable(second_prefix_and_suffixes.first)) + return false; + return !first.compare(getOffset(first_prefix_and_suffixes.first), + std::string::npos, + second, + getOffset(second_prefix_and_suffixes.first), + std::string::npos); + }(); + + const bool is_suffix_change = [&]() -> bool { + if (!checkTable(first_prefix_and_suffixes.second)) + return false; + if (!checkTable(second_prefix_and_suffixes.second)) + return false; + return !first.compare(0, + first.length() - getOffset(first_prefix_and_suffixes.second), + second, + 0, + second.length() - getOffset(second_prefix_and_suffixes.second)); + }(); + + return is_prefix_change || is_suffix_change; + }; + const auto is_suffix_change = checkForPrefixOrSuffixChange(from_name, to_name, suffix_table); const auto names_are_equal = from_name == to_name || name_is_contained || is_suffix_change; const auto name_is_removed = !from_name.empty() && to_name.empty();