Add support for opposite approach request parameter (#6842)

* Added approach on the opposite side of the road.

* Additional test and docs coverage for opposite approach

---------

Co-authored-by: Aleksandrs Saveljevs <Aleksandrs.Saveljevs@gmail.com>
This commit is contained in:
Michael Bell
2024-04-03 19:59:15 +01:00
committed by GitHub
parent 367933fc1a
commit 8ef366e061
12 changed files with 400 additions and 38 deletions
+2 -1
View File
@@ -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
+2 -1
View File
@@ -36,7 +36,8 @@ namespace osrm::engine
enum class Approach : std::uint8_t
{
CURB = 0,
UNRESTRICTED = 1
UNRESTRICTED = 1,
OPPOSITE = 2
};
} // namespace osrm::engine
+4 -1
View File
@@ -558,7 +558,7 @@ template <typename RTreeT, typename DataFacadeT> 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 <typename RTreeT, typename DataFacadeT> 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);
+7 -2
View File
@@ -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,14 @@ 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;
}
}
@@ -166,8 +166,9 @@ struct BaseParametersGrammar : boost::spirit::qi::grammar<Iterator, Signature>
qi::lit("bearings=") >
(-(qi::short_ > ',' > qi::short_))[ph::bind(add_bearing, qi::_r1, qi::_1)] % ';';
approach_type.add("unrestricted", engine::Approach::UNRESTRICTED)("curb",
engine::Approach::CURB);
approach_type.add("unrestricted", engine::Approach::UNRESTRICTED)(
"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];