From 599c0264070d0546d0d6dfa301e139009337d810 Mon Sep 17 00:00:00 2001 From: Emil Tin Date: Thu, 3 May 2012 13:51:24 +0200 Subject: [PATCH] fix bike speed on ped streets. cleanup of speed code --- DataStructures/ExtractorCallBacks.h | 36 ++++++------ features/maxspeed.feature | 86 +++++++++++++++++++++++++++++ features/time.feature | 33 ++++++++++- test/speedprofiles/car.ini | 41 +++++++------- 4 files changed, 159 insertions(+), 37 deletions(-) create mode 100644 features/maxspeed.feature diff --git a/DataStructures/ExtractorCallBacks.h b/DataStructures/ExtractorCallBacks.h index 0f25f2bf8..c7028deda 100644 --- a/DataStructures/ExtractorCallBacks.h +++ b/DataStructures/ExtractorCallBacks.h @@ -190,23 +190,27 @@ public: //Is the highway tag listed as usable way? if(("track" == highway && ("yes" == access || "yes" == accessTag)) || ("track" != highway && (0 < settings[highway] || "yes" == accessTag || "designated" == accessTag) )) { if(!w.isDurationSet) { - if(0 < settings[highway]) { - if(0 < maxspeed) - if(settings.takeMinimumOfSpeeds) - w.speed = std::min(settings[highway], maxspeed); - else - w.speed = maxspeed; - else - w.speed = settings[highway]; - } else { - if(0 < maxspeed) - if(settings.takeMinimumOfSpeeds) - w.speed = std::min(settings.defaultSpeed, maxspeed); - else w.speed = maxspeed; - else - w.speed = settings.defaultSpeed; - highway = "default"; + int speed; + + if( accessTag=="yes" || accessTag=="designated" ) + speed = std::max( settings.defaultSpeed, settings[highway] ); + else if( settings[highway]>0 ) + speed = settings[highway]; + else { + speed = settings.defaultSpeed; } + + if( !settings[highway]>0 ) + highway = "default"; + + if( maxspeed>0 ) { + if( settings.takeMinimumOfSpeeds ) + w.speed = std::min( speed, maxspeed ); + else + w.speed = maxspeed; + } + else + w.speed = speed; } w.useful = true; diff --git a/features/maxspeed.feature b/features/maxspeed.feature new file mode 100644 index 000000000..fbf53f31b --- /dev/null +++ b/features/maxspeed.feature @@ -0,0 +1,86 @@ +@routing @maxspeed +Feature: Speed limits + Note: + 60km/h = 100m/6s + 30km/h = 100m/12s + 15km/h = 100m/24s + 10km/h = 100m/48s + 5km/h = 100m/72s + + Scenario: Obey speedlimits + Given the speedprofile "car" + And the speedprofile settings + | primary | 60 | + And a grid size of 100 meters + And the node map + | a | b | + | c | d | + + And the ways + | nodes | highway | maxspeed | + | ab | primary | | + | cd | primary | 30 | + + When I route I should get + | from | to | route | time | + | a | b | ab | 6s | + | c | d | cd | 12s | + + Scenario: Go faster than speedprofile when takeMinimumOfSpeeds=no + Given the speedprofile "car" + And the speedprofile settings + | residential | 15 | + | takeMinimumOfSpeeds | no | + And a grid size of 100 meters + And the node map + | a | b | + + And the ways + | nodes | highway | maxspeed | + | ab | residential | 30 | + + When I route I should get + | from | to | route | time | + | a | b | ab | 12s | + + Scenario: Bicycles can't go faster just because maxspeed is high + Given the speedprofile "bicycle" + And the speedprofile settings + | primary | 15 | + And a grid size of 100 meters + + And the node map + | a | b | + | c | d | + + And the ways + | nodes | highway | maxspeed | + | ab | primary | | + | cd | primary | 60 | + + When I route I should get + | from | to | route | time | + | a | b | ab | 24s | + | c | d | cd | 24s | + + Scenario: Bicycles should also obey maxspeed + Given the speedprofile "bicycle" + And the speedprofile settings + | primary | 15 | + And a grid size of 100 meters + + And the node map + | a | b | + | c | d | + + And the ways + | nodes | highway | maxspeed | + | ab | primary | | + | cd | primary | 10 | + + When I route I should get + | from | to | route | time | + | a | b | ab | 24s | + | c | d | cd | 48s | + + diff --git a/features/time.feature b/features/time.feature index e2da7fc57..79844d3aa 100644 --- a/features/time.feature +++ b/features/time.feature @@ -6,6 +6,23 @@ Feature: Estimation of travel time Background: Use specific speeds Given the speedprofile "bicycle" + And the speedprofile settings + | defaultSpeed | 15 | + | primary | 15 | + | footway | 5 | + + Scenario: Time of travelling 100 meters + Given a grid size of 100 meters + Given the node map + | a | b | + + And the ways + | nodes | highway | + | ab | primary | + + When I route I should get + | from | to | route | time | + | a | b | ab | 24s | Scenario: Basic travel time, 1m scale Given a grid size of 1 meters @@ -175,4 +192,18 @@ Feature: Estimation of travel time | 1 | 4 | ab | 72s | | 4 | 3 | ab | 24s | | 4 | 2 | ab | 48s | - | 4 | 1 | ab | 72s | \ No newline at end of file + | 4 | 1 | ab | 72s | + + @bike_speed + Scenario: Time of travel when bicycle=yes + Given the node map + | a | b | + | c | d | + + And the ways + | nodes | highway | bicycle | + | ab | footway | yes | + + When I route I should get + | from | to | route | time | + | a | b | ab | 24s | \ No newline at end of file diff --git a/test/speedprofiles/car.ini b/test/speedprofiles/car.ini index b2ce3c4c0..944f58534 100644 --- a/test/speedprofiles/car.ini +++ b/test/speedprofiles/car.ini @@ -1,23 +1,24 @@ [car] - accessTag = motorcar - defaultSpeed = 50 - obeyOneways = yes - useRestrictions = yes - barrier = bollard + accessTag = motorcar + defaultSpeed = 60 + obeyOneways = yes + useRestrictions = yes + barrier = bollard + takeMinimumOfSpeeds = yes - motorway = 100 - motorway_link = 90 - trunk = 90 - trunk_link = 70 - primary = 70 - primary_link = 60 - secondary = 60 - secondary_link = 50 - tertiary = 50 - tertiary_link = 40 - road = 40 - residential = 40 - unclassified = 30 - service = 20 - living_street = 10 + motorway = 110 + motorway_link = 90 + trunk = 90 + trunk_link = 70 + primary = 70 + primary_link = 60 + secondary = 60 + secondary_link = 50 + tertiary = 50 + tertiary_link = 40 + road = 40 + residential = 40 + unclassified = 30 + service = 20 + living_street = 10