From 986252c4f95c37a0b5e6658d72c8c49858ac30cf Mon Sep 17 00:00:00 2001 From: Daniel Patterson Date: Sun, 10 Feb 2019 02:09:30 -0800 Subject: [PATCH] Quick fix for negative distances bug. --- package.json | 2 +- src/engine/plugins/table.cpp | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 8386c2d7e..ee10135a6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "osrm", - "version": "5.21.0-customsnapping.8", + "version": "5.21.0-customsnapping.9", "private": false, "description": "The Open Source Routing Machine is a high performance routing engine written in C++14 designed to run on OpenStreetMap data.", "dependencies": { diff --git a/src/engine/plugins/table.cpp b/src/engine/plugins/table.cpp index 14c5d07cf..40860f45e 100644 --- a/src/engine/plugins/table.cpp +++ b/src/engine/plugins/table.cpp @@ -112,7 +112,7 @@ Status TablePlugin::HandleRequest(const RoutingAlgorithmsInterface &algorithms, // here, but tiny numbers is what this adjustment lambda is all about, // so we do try to be reasonable. const auto average_speed = - duration == 0 ? 10 : distance / + duration == 0 ? 10 : std::abs(distance) / (duration / 10.); // duration is in deciseconds, we need m/sec // The following reference has a nice model (equations 9 through 12) @@ -141,7 +141,7 @@ Status TablePlugin::HandleRequest(const RoutingAlgorithmsInterface &algorithms, BOOST_ASSERT(distance_to_full_speed >= 0); - if (distance_to_full_speed > distance / 2) + if (distance_to_full_speed > std::abs(distance) / 2) { // Because equation 12 requires velocity at halfway, and // solving equation 11 for t requires a Lambert W function, @@ -149,13 +149,13 @@ Status TablePlugin::HandleRequest(const RoutingAlgorithmsInterface &algorithms, // over distance_to_full_speed using s = ut + 1/2at^2 const auto average_acceleration = 2 * distance_to_full_speed / (time_to_full_speed * time_to_full_speed); - const auto time_to_halfway = std::sqrt(distance / average_acceleration); + const auto time_to_halfway = std::sqrt(std::abs(distance) / average_acceleration); BOOST_ASSERT(time_to_halfway >= 0); return (2 * time_to_halfway) * 10; // result is in deciseconds } else { - const auto cruising_distance = distance - 2 * distance_to_full_speed; + const auto cruising_distance = std::abs(distance) - 2 * distance_to_full_speed; const auto cruising_time = cruising_distance / average_speed; BOOST_ASSERT(cruising_time >= 0); return (cruising_time + 2 * time_to_full_speed) * 10; // result is in deciseconds