From 63e713aa4a9f42f11c1fd4e86c8878cb5d5b2170 Mon Sep 17 00:00:00 2001 From: Kajari Ghosh Date: Mon, 10 Dec 2018 22:48:57 -0500 Subject: [PATCH] Revert "Include distance from input to snapped for all waypoints, not just on the `nearest` service." This reverts commit 4dde9c7bbe76170338aba5acb84ba0585a3fc9d9. --- docs/http.md | 2 +- include/engine/api/base_api.hpp | 5 ----- include/engine/api/json_factory.hpp | 11 ++++------- include/engine/api/nearest_api.hpp | 1 + src/engine/api/json_factory.cpp | 13 ++++--------- src/util/coordinate_calculation.cpp | 2 +- unit_tests/library/route.cpp | 22 +++++----------------- 7 files changed, 16 insertions(+), 40 deletions(-) diff --git a/docs/http.md b/docs/http.md index ad2469324..f1b2a1f05 100644 --- a/docs/http.md +++ b/docs/http.md @@ -119,6 +119,7 @@ In addition to the [general options](#general-options) the following options are - `code` if the request was successful `Ok` otherwise see the service dependent and general status codes. - `waypoints` array of `Waypoint` objects sorted by distance to the input coordinate. Each object has at least the following additional properties: + - `distance`: Distance in meters to the supplied input coordinate. - `nodes`: Array of OpenStreetMap node ids. #### Example Requests @@ -906,7 +907,6 @@ Object used to describe waypoint on a route. - `name` Name of the street the coordinate snapped to - `location` Array that contains the `[longitude, latitude]` pair of the snapped coordinate -- `distance` The distance, in metres, from the input coordinate to the snapped coordinate - `hint` Unique internal identifier of the segment (ephemeral, not constant over data updates) This can be used on subsequent request to significantly speed up the query and to connect multiple services. E.g. you can use the `hint` value obtained by the `nearest` query as `hint` values for `route` inputs. diff --git a/include/engine/api/base_api.hpp b/include/engine/api/base_api.hpp index e0c924348..0e0dad33b 100644 --- a/include/engine/api/base_api.hpp +++ b/include/engine/api/base_api.hpp @@ -6,7 +6,6 @@ #include "engine/api/json_factory.hpp" #include "engine/hint.hpp" -#include "util/coordinate_calculation.hpp" #include #include @@ -54,8 +53,6 @@ class BaseAPI // TODO: check forward/reverse return json::makeWaypoint( phantom.location, - util::coordinate_calculation::fccApproximateDistance(phantom.location, - phantom.input_location), facade.GetNameForID(facade.GetNameIndex(phantom.forward_segment_id.id)).to_string(), Hint{phantom, facade.GetCheckSum()}); } @@ -64,8 +61,6 @@ class BaseAPI // TODO: check forward/reverse return json::makeWaypoint( phantom.location, - util::coordinate_calculation::fccApproximateDistance(phantom.location, - phantom.input_location), facade.GetNameForID(facade.GetNameIndex(phantom.forward_segment_id.id)) .to_string()); } diff --git a/include/engine/api/json_factory.hpp b/include/engine/api/json_factory.hpp index db30ecc9e..627a59ead 100644 --- a/include/engine/api/json_factory.hpp +++ b/include/engine/api/json_factory.hpp @@ -33,7 +33,7 @@ namespace json namespace detail { -util::json::Array coordinateToLonLat(const util::Coordinate &coordinate); +util::json::Array coordinateToLonLat(const util::Coordinate coordinate); /** * Ensures that a bearing value is a whole number, and clamped to the range 0-359 @@ -86,14 +86,11 @@ util::json::Object makeRoute(const guidance::Route &route, const char *weight_name); // Creates a Waypoint without Hint, see the Hint overload below -util::json::Object -makeWaypoint(const util::Coordinate &location, const double &distance, std::string name); +util::json::Object makeWaypoint(const util::Coordinate location, std::string name); // Creates a Waypoint with Hint, see the overload above when Hint is not needed -util::json::Object makeWaypoint(const util::Coordinate &location, - const double &distance, - std::string name, - const Hint &hint); +util::json::Object +makeWaypoint(const util::Coordinate location, std::string name, const Hint &hint); util::json::Object makeRouteLeg(guidance::RouteLeg leg, util::json::Array steps); diff --git a/include/engine/api/nearest_api.hpp b/include/engine/api/nearest_api.hpp index bb55b0634..8793af6ca 100644 --- a/include/engine/api/nearest_api.hpp +++ b/include/engine/api/nearest_api.hpp @@ -41,6 +41,7 @@ class NearestAPI final : public BaseAPI [this](const PhantomNodeWithDistance &phantom_with_distance) { auto &phantom_node = phantom_with_distance.phantom_node; auto waypoint = MakeWaypoint(phantom_node); + waypoint.values["distance"] = phantom_with_distance.distance; util::json::Array nodes; diff --git a/src/engine/api/json_factory.cpp b/src/engine/api/json_factory.cpp index dc887f853..88d59f724 100644 --- a/src/engine/api/json_factory.cpp +++ b/src/engine/api/json_factory.cpp @@ -94,7 +94,7 @@ std::string waypointTypeToString(const guidance::WaypointType waypoint_type) return waypoint_type_names[static_cast(waypoint_type)]; } -util::json::Array coordinateToLonLat(const util::Coordinate &coordinate) +util::json::Array coordinateToLonLat(const util::Coordinate coordinate) { util::json::Array array; array.values.push_back(static_cast(util::toFloating(coordinate.lon))); @@ -240,22 +240,17 @@ util::json::Object makeRoute(const guidance::Route &route, return json_route; } -util::json::Object -makeWaypoint(const util::Coordinate &location, const double &distance, std::string name) +util::json::Object makeWaypoint(const util::Coordinate location, std::string name) { util::json::Object waypoint; waypoint.values["location"] = detail::coordinateToLonLat(location); waypoint.values["name"] = std::move(name); - waypoint.values["distance"] = distance; return waypoint; } -util::json::Object makeWaypoint(const util::Coordinate &location, - const double &distance, - std::string name, - const Hint &hint) +util::json::Object makeWaypoint(const util::Coordinate location, std::string name, const Hint &hint) { - auto waypoint = makeWaypoint(location, distance, name); + auto waypoint = makeWaypoint(location, name); waypoint.values["hint"] = hint.ToBase64(); return waypoint; } diff --git a/src/util/coordinate_calculation.cpp b/src/util/coordinate_calculation.cpp index 10e64c6cb..cb9adb10a 100644 --- a/src/util/coordinate_calculation.cpp +++ b/src/util/coordinate_calculation.cpp @@ -153,7 +153,7 @@ double perpendicularDistance(const Coordinate segment_source, web_mercator::fromWGS84(query_location)); nearest_location = web_mercator::toWGS84(projected_nearest); - const double approximate_distance = fccApproximateDistance(query_location, nearest_location); + const double approximate_distance = greatCircleDistance(query_location, nearest_location); BOOST_ASSERT(0.0 <= approximate_distance); return approximate_distance; } diff --git a/unit_tests/library/route.cpp b/unit_tests/library/route.cpp index 6a6faad96..2ce75b0e0 100644 --- a/unit_tests/library/route.cpp +++ b/unit_tests/library/route.cpp @@ -1,8 +1,6 @@ #include #include -#include - #include "coordinates.hpp" #include "equal_json.hpp" #include "fixture.hpp" @@ -34,28 +32,18 @@ BOOST_AUTO_TEST_CASE(test_route_same_coordinates_fixture) // unset snapping dependent hint for (auto &itr : result.values["waypoints"].get().values) - { - // Hint values aren't stable, so blank it out itr.get().values["hint"] = ""; - // Round value to 6 decimal places for double comparison later - itr.get().values["distance"] = - round(itr.get().values["distance"].get().value * 1000000); - } - const auto location = json::Array{{{7.437070}, {43.749248}}}; json::Object reference{ {{"code", "Ok"}, {"waypoints", - json::Array{{json::Object{{{"name", "Boulevard du Larvotto"}, - {"location", location}, - {"distance", round(0.137249 * 1000000)}, - {"hint", ""}}}, - json::Object{{{"name", "Boulevard du Larvotto"}, - {"location", location}, - {"distance", round(0.137249 * 1000000)}, - {"hint", ""}}}}}}, + json::Array{ + {json::Object{ + {{"name", "Boulevard du Larvotto"}, {"location", location}, {"hint", ""}}}, + json::Object{ + {{"name", "Boulevard du Larvotto"}, {"location", location}, {"hint", ""}}}}}}, {"routes", json::Array{{json::Object{ {{"distance", 0.},