From ce9dd44c2e82f855fa4ddbc31a4778e0ce0a2ca5 Mon Sep 17 00:00:00 2001 From: Aleksandrs Saveljevs Date: Fri, 6 Jan 2023 14:31:32 +0000 Subject: [PATCH] Added approach on the opposite side of the road (main C++ files only). --- include/engine/api/base_parameters.hpp | 3 ++- include/engine/approach.hpp | 3 ++- include/engine/geospatial_query.hpp | 5 ++++- include/nodejs/node_osrm_support.hpp | 8 ++++++-- include/server/api/base_parameters_grammar.hpp | 3 ++- src/nodejs/node_osrm.cpp | 8 ++++---- 6 files changed, 20 insertions(+), 10 deletions(-) diff --git a/include/engine/api/base_parameters.hpp b/include/engine/api/base_parameters.hpp index 9cc13ae01..56b8604ed 100644 --- a/include/engine/api/base_parameters.hpp +++ b/include/engine/api/base_parameters.hpp @@ -52,7 +52,8 @@ namespace osrm::engine::api * optional per coordinate * - bearings: limits the search for segments in the road network to given bearing(s) in degree * towards true north in clockwise direction, optional per coordinate - * - approaches: force the phantom node to start towards the node with the road country side. + * - approaches: force the phantom node to start towards the node with the road country side or + * its opposite * * \see OSRM, Coordinate, Hint, Bearing, RouteParameters, TableParameters, * NearestParameters, TripParameters, MatchParameters and TileParameters diff --git a/include/engine/approach.hpp b/include/engine/approach.hpp index 185dcfcf5..abd35bd9d 100644 --- a/include/engine/approach.hpp +++ b/include/engine/approach.hpp @@ -36,7 +36,8 @@ namespace osrm::engine enum class Approach : std::uint8_t { CURB = 0, - UNRESTRICTED = 1 + OPPOSITE = 1, + UNRESTRICTED = 2 }; } // namespace osrm::engine diff --git a/include/engine/geospatial_query.hpp b/include/engine/geospatial_query.hpp index 7ea666c4e..f25122afb 100644 --- a/include/engine/geospatial_query.hpp +++ b/include/engine/geospatial_query.hpp @@ -558,7 +558,7 @@ template class GeospatialQuery { bool isOnewaySegment = !(segment.data.forward_segment_id.enabled && segment.data.reverse_segment_id.enabled); - if (!isOnewaySegment && approach == Approach::CURB) + if (!isOnewaySegment && (approach == Approach::CURB || approach == Approach::OPPOSITE)) { // Check the counter clockwise // @@ -573,6 +573,9 @@ template class GeospatialQuery if (datafacade.IsLeftHandDriving(segment.data.forward_segment_id.id)) input_coordinate_is_at_right = !input_coordinate_is_at_right; + if (approach == Approach::OPPOSITE) + input_coordinate_is_at_right = !input_coordinate_is_at_right; + return std::make_pair(input_coordinate_is_at_right, (!input_coordinate_is_at_right)); } return std::make_pair(true, true); diff --git a/include/nodejs/node_osrm_support.hpp b/include/nodejs/node_osrm_support.hpp index d321bb4a0..f698374b5 100644 --- a/include/nodejs/node_osrm_support.hpp +++ b/include/nodejs/node_osrm_support.hpp @@ -560,6 +560,10 @@ inline bool argumentsToParameter(const Napi::CallbackInfo &args, { params->approaches.push_back(osrm::Approach::CURB); } + else if (approach_str == "opposite") + { + params->approaches.push_back(osrm::Approach::OPPOSITE); + } else if (approach_str == "unrestricted") { params->approaches.push_back(osrm::Approach::UNRESTRICTED); @@ -567,13 +571,13 @@ inline bool argumentsToParameter(const Napi::CallbackInfo &args, else { ThrowError(args.Env(), - "'approaches' param must be one of [curb, unrestricted]"); + "'approaches' param must be one of [curb, opposite, unrestricted]"); return false; } } else { - ThrowError(args.Env(), "Approach must be a string: [curb, unrestricted] or null"); + ThrowError(args.Env(), "Approach must be a string: [curb, opposite, unrestricted] or null"); return false; } } diff --git a/include/server/api/base_parameters_grammar.hpp b/include/server/api/base_parameters_grammar.hpp index dfc99c037..a303c6a80 100644 --- a/include/server/api/base_parameters_grammar.hpp +++ b/include/server/api/base_parameters_grammar.hpp @@ -167,7 +167,8 @@ struct BaseParametersGrammar : boost::spirit::qi::grammar (-(qi::short_ > ',' > qi::short_))[ph::bind(add_bearing, qi::_r1, qi::_1)] % ';'; approach_type.add("unrestricted", engine::Approach::UNRESTRICTED)("curb", - engine::Approach::CURB); + engine::Approach::CURB)("opposite", engine::Approach::OPPOSITE); + approach_rule = qi::lit("approaches=") > (-approach_type % ';')[ph::bind(&engine::api::BaseParameters::approaches, qi::_r1) = qi::_1]; diff --git a/src/nodejs/node_osrm.cpp b/src/nodejs/node_osrm.cpp index 9ff5db22f..02cef8422 100644 --- a/src/nodejs/node_osrm.cpp +++ b/src/nodejs/node_osrm.cpp @@ -292,7 +292,7 @@ inline void asyncForTiles(const Napi::CallbackInfo &info, * @param {String} [options.geometries=polyline] Returned route geometry format (influences overview and per step). Can also be `geojson`. * @param {String} [options.overview=simplified] Add overview geometry either `full`, `simplified` according to highest zoom level it could be display on, or not at all (`false`). * @param {Boolean} [options.continue_straight] Forces the route to keep going straight at waypoints and don't do a uturn even if it would be faster. Default value depends on the profile. - * @param {Array} [options.approaches] Keep waypoints on curb side. Can be `null` (unrestricted, default) or `curb`. + * @param {Array} [options.approaches] Keep waypoints on curb or opposite side of the road. Can be `null` (unrestricted, default), `curb` or `opposite`. * `null`/`true`/`false` * @param {Array} [options.waypoints] Indices to coordinates to treat as waypoints. If not supplied, all coordinates are waypoints. Must include first and last coordinate index. * @param {String} [options.format] Which output format to use, either `json`, or [`flatbuffers`](https://github.com/Project-OSRM/osrm-backend/tree/master/include/engine/api/flatbuffers). @@ -337,7 +337,7 @@ Napi::Value Engine::route(const Napi::CallbackInfo &info) * @param {Boolean} [options.generate_hints=true] Whether or not adds a Hint to the response which can be used in subsequent requests. * @param {Number} [options.number=1] Number of nearest segments that should be returned. * Must be an integer greater than or equal to `1`. - * @param {Array} [options.approaches] Keep waypoints on curb side. Can be `null` (unrestricted, default) or `curb`. + * @param {Array} [options.approaches] Keep waypoints on curb or opposite side of the road. Can be `null` (unrestricted, default), `curb` or `opposite`. * @param {String} [options.format] Which output format to use, either `json`, or [`flatbuffers`](https://github.com/Project-OSRM/osrm-backend/tree/master/include/engine/api/flatbuffers). * @param {String} [options.snapping] Which edges can be snapped to, either `default`, or `any`. `default` only snaps to edges marked by the profile as `is_startpoint`, `any` will allow snapping to any edge in the routing graph. * @param {Function} callback @@ -384,7 +384,7 @@ Napi::Value Engine::nearest(const Napi::CallbackInfo &info) * @param {Array} [options.sources] An array of `index` elements (`0 <= integer < #coordinates`) to use * location with given index as source. Default is to use all. * @param {Array} [options.destinations] An array of `index` elements (`0 <= integer < #coordinates`) to use location with given index as destination. Default is to use all. - * @param {Array} [options.approaches] Keep waypoints on curb side. Can be `null` (unrestricted, default) or `curb`. + * @param {Array} [options.approaches] Keep waypoints on curb or opposite side of the road. Can be `null` (unrestricted, default), `curb` or `opposite`. * @param {Number} [options.fallback_speed] Replace `null` responses in result with as-the-crow-flies estimates based on `fallback_speed`. Value is in metres/second. * @param {String} [options.fallback_coordinate] Either `input` (default) or `snapped`. If using a `fallback_speed`, use either the user-supplied coordinate (`input`), or the snapped coordinate (`snapped`) for calculating the as-the-crow-flies distance between two points. * @param {Number} [options.scale_factor] Multiply the table duration values in the table by this number for more controlled input into a route optimization solver. @@ -565,7 +565,7 @@ Napi::Value Engine::match(const Napi::CallbackInfo &info) * @param {Boolean} [options.roundtrip=true] Return route is a roundtrip. * @param {String} [options.source=any] Return route starts at `any` or `first` coordinate. * @param {String} [options.destination=any] Return route ends at `any` or `last` coordinate. - * @param {Array} [options.approaches] Keep waypoints on curb side. Can be `null` (unrestricted, default) or `curb`. + * @param {Array} [options.approaches] Keep waypoints on curb or opposite side of the road. Can be `null` (unrestricted, default), `curb` or `opposite`. * @param {String} [options.snapping] Which edges can be snapped to, either `default`, or `any`. `default` only snaps to edges marked by the profile as `is_startpoint`, `any` will allow snapping to any edge in the routing graph. * * @returns {Object} containing `waypoints` and `trips`.