This commit is contained in:
Daniel Patterson 2019-01-23 16:28:55 -08:00
parent df52111674
commit 709b4d6ef0
No known key found for this signature in database
GPG Key ID: 19C12BE1725A028B
8 changed files with 85 additions and 43 deletions

View File

@ -31,10 +31,10 @@ class BaseAPI
util::json::Array MakeWaypoints(const std::vector<PhantomNodes> &segment_end_coordinates) const util::json::Array MakeWaypoints(const std::vector<PhantomNodes> &segment_end_coordinates) const
{ {
BOOST_ASSERT(parameters.coordinates.size() > 0); BOOST_ASSERT(parameters.coordinates.size() > 0);
// BOOST_ASSERT(parameters.coordinates.size() == segment_end_coordinates.size() + 1); BOOST_ASSERT(parameters.coordinates.size() == segment_end_coordinates.size() + 1);
util::json::Array waypoints; util::json::Array waypoints;
waypoints.values.resize(segment_end_coordinates.size() + 1); waypoints.values.resize(parameters.coordinates.size());
waypoints.values[0] = MakeWaypoint(segment_end_coordinates.front().source_phantom); waypoints.values[0] = MakeWaypoint(segment_end_coordinates.front().source_phantom);
auto out_iter = std::next(waypoints.values.begin()); auto out_iter = std::next(waypoints.values.begin());
@ -75,8 +75,8 @@ class BaseAPI
const BaseParameters &parameters; const BaseParameters &parameters;
}; };
} // namespace api } // ns api
} // namespace engine } // ns engine
} // namespace osrm } // ns osrm
#endif #endif

View File

@ -63,7 +63,7 @@ struct MatchParameters : public RouteParameters
RouteParameters::GeometriesType::Polyline, RouteParameters::GeometriesType::Polyline,
RouteParameters::OverviewType::Simplified, RouteParameters::OverviewType::Simplified,
{}), {}),
gaps(GapsType::Split), tidy(false), waypoints() gaps(GapsType::Split), tidy(false)
{ {
} }
@ -79,24 +79,19 @@ struct MatchParameters : public RouteParameters
bool tidy_, bool tidy_,
std::vector<std::size_t> waypoints_, std::vector<std::size_t> waypoints_,
Args... args_) Args... args_)
: RouteParameters{std::forward<Args>(args_)...}, timestamps{std::move(timestamps_)}, : RouteParameters{std::forward<Args>(args_)..., waypoints_},
gaps(gaps_), tidy(tidy_), waypoints{std::move(waypoints_)} timestamps{std::move(timestamps_)}, gaps(gaps_), tidy(tidy_)
{ {
} }
std::vector<unsigned> timestamps; std::vector<unsigned> timestamps;
GapsType gaps; GapsType gaps;
bool tidy; bool tidy;
std::vector<std::size_t> waypoints;
bool IsValid() const bool IsValid() const
{ {
const auto valid_waypoints =
std::all_of(waypoints.begin(), waypoints.end(), [this](const auto &w) {
return w < coordinates.size();
});
return RouteParameters::IsValid() && return RouteParameters::IsValid() &&
(timestamps.empty() || timestamps.size() == coordinates.size()) && valid_waypoints; (timestamps.empty() || timestamps.size() == coordinates.size());
} }
}; };
} }

View File

@ -359,8 +359,8 @@ class RouteAPI : public BaseAPI
const RouteParameters &parameters; const RouteParameters &parameters;
}; };
} // namespace api } // ns api
} // namespace engine } // ns engine
} // namespace osrm } // ns osrm
#endif #endif

View File

@ -90,10 +90,16 @@ struct RouteParameters : public BaseParameters
Args... args_) Args... args_)
// Once we perfectly-forward `args` (see #2990) this constructor can delegate to the one // Once we perfectly-forward `args` (see #2990) this constructor can delegate to the one
// below. // below.
: BaseParameters{std::forward<Args>(args_)...}, steps{steps_}, alternatives{alternatives_}, : BaseParameters{std::forward<Args>(args_)...},
number_of_alternatives{alternatives_ ? 1u : 0u}, annotations{false}, steps{steps_},
annotations_type{AnnotationsType::None}, geometries{geometries_}, overview{overview_}, alternatives{alternatives_},
continue_straight{continue_straight_} number_of_alternatives{alternatives_ ? 1u : 0u},
annotations{false},
annotations_type{AnnotationsType::None},
geometries{geometries_},
overview{overview_},
continue_straight{continue_straight_},
waypoints()
{ {
} }
@ -109,7 +115,9 @@ struct RouteParameters : public BaseParameters
: BaseParameters{std::forward<Args>(args_)...}, steps{steps_}, alternatives{alternatives_}, : BaseParameters{std::forward<Args>(args_)...}, steps{steps_}, alternatives{alternatives_},
number_of_alternatives{alternatives_ ? 1u : 0u}, annotations{annotations_}, number_of_alternatives{alternatives_ ? 1u : 0u}, annotations{annotations_},
annotations_type{annotations_ ? AnnotationsType::All : AnnotationsType::None}, annotations_type{annotations_ ? AnnotationsType::All : AnnotationsType::None},
geometries{geometries_}, overview{overview_}, continue_straight{continue_straight_} geometries{geometries_}, overview{overview_}, continue_straight{continue_straight_},
waypoints()
{ {
} }
@ -126,7 +134,43 @@ struct RouteParameters : public BaseParameters
number_of_alternatives{alternatives_ ? 1u : 0u}, number_of_alternatives{alternatives_ ? 1u : 0u},
annotations{annotations_ == AnnotationsType::None ? false : true}, annotations{annotations_ == AnnotationsType::None ? false : true},
annotations_type{annotations_}, geometries{geometries_}, overview{overview_}, annotations_type{annotations_}, geometries{geometries_}, overview{overview_},
continue_straight{continue_straight_} continue_straight{continue_straight_}, waypoints()
{
}
// RouteParameters constructor adding the `waypoints` parameter
template <typename... Args>
RouteParameters(const bool steps_,
const bool alternatives_,
const bool annotations_,
const GeometriesType geometries_,
const OverviewType overview_,
const boost::optional<bool> continue_straight_,
std::vector<std::size_t> waypoints_,
const Args... args_)
: BaseParameters{std::forward<Args>(args_)...}, steps{steps_}, alternatives{alternatives_},
number_of_alternatives{alternatives_ ? 1u : 0u}, annotations{annotations_},
annotations_type{annotations_ ? AnnotationsType::All : AnnotationsType::None},
geometries{geometries_}, overview{overview_}, continue_straight{continue_straight_},
waypoints{waypoints_}
{
}
// RouteParameters constructor adding the `waypoints` parameter
template <typename... Args>
RouteParameters(const bool steps_,
const bool alternatives_,
const AnnotationsType annotations_,
const GeometriesType geometries_,
const OverviewType overview_,
const boost::optional<bool> continue_straight_,
std::vector<std::size_t> waypoints_,
Args... args_)
: BaseParameters{std::forward<Args>(args_)...}, steps{steps_}, alternatives{alternatives_},
number_of_alternatives{alternatives_ ? 1u : 0u},
annotations{annotations_ == AnnotationsType::None ? false : true},
annotations_type{annotations_}, geometries{geometries_}, overview{overview_},
continue_straight{continue_straight_}, waypoints{waypoints_}
{ {
} }
@ -145,7 +189,11 @@ struct RouteParameters : public BaseParameters
{ {
const auto coordinates_ok = coordinates.size() >= 2; const auto coordinates_ok = coordinates.size() >= 2;
const auto base_params_ok = BaseParameters::IsValid(); const auto base_params_ok = BaseParameters::IsValid();
return coordinates_ok && base_params_ok; const auto valid_waypoints =
std::all_of(waypoints.begin(), waypoints.end(), [this](const auto &w) {
return w < coordinates.size();
});
return coordinates_ok && base_params_ok && valid_waypoints;
} }
}; };
@ -169,8 +217,8 @@ inline RouteParameters::AnnotationsType operator|=(RouteParameters::AnnotationsT
{ {
return lhs = lhs | rhs; return lhs = lhs | rhs;
} }
} // namespace api } // ns api
} // namespace engine } // ns engine
} // namespace osrm } // ns osrm
#endif #endif

View File

@ -18,7 +18,7 @@ namespace
{ {
namespace ph = boost::phoenix; namespace ph = boost::phoenix;
namespace qi = boost::spirit::qi; namespace qi = boost::spirit::qi;
} // namespace }
template <typename Iterator = std::string::iterator, template <typename Iterator = std::string::iterator,
typename Signature = void(engine::api::MatchParameters &)> typename Signature = void(engine::api::MatchParameters &)>
@ -48,7 +48,6 @@ struct MatchParametersGrammar final : public RouteParametersGrammar<Iterator, Si
root_rule = root_rule =
BaseGrammar::query_rule(qi::_r1) > -qi::lit(".json") > BaseGrammar::query_rule(qi::_r1) > -qi::lit(".json") >
-('?' > (timestamps_rule(qi::_r1) | BaseGrammar::base_rule(qi::_r1) | -('?' > (timestamps_rule(qi::_r1) | BaseGrammar::base_rule(qi::_r1) |
waypoints_rule(qi::_r1) |
(qi::lit("gaps=") > (qi::lit("gaps=") >
gaps_type[ph::bind(&engine::api::MatchParameters::gaps, qi::_r1) = qi::_1]) | gaps_type[ph::bind(&engine::api::MatchParameters::gaps, qi::_r1) = qi::_1]) |
(qi::lit("tidy=") > (qi::lit("tidy=") >
@ -59,13 +58,12 @@ struct MatchParametersGrammar final : public RouteParametersGrammar<Iterator, Si
private: private:
qi::rule<Iterator, Signature> root_rule; qi::rule<Iterator, Signature> root_rule;
qi::rule<Iterator, Signature> timestamps_rule; qi::rule<Iterator, Signature> timestamps_rule;
qi::rule<Iterator, Signature> waypoints_rule;
qi::rule<Iterator, std::size_t()> size_t_; qi::rule<Iterator, std::size_t()> size_t_;
qi::symbols<char, engine::api::MatchParameters::GapsType> gaps_type; qi::symbols<char, engine::api::MatchParameters::GapsType> gaps_type;
}; };
} // namespace api }
} // namespace server }
} // namespace osrm }
#endif #endif

View File

@ -18,7 +18,7 @@ namespace
{ {
namespace ph = boost::phoenix; namespace ph = boost::phoenix;
namespace qi = boost::spirit::qi; namespace qi = boost::spirit::qi;
} // namespace }
template <typename Iterator = std::string::iterator, template <typename Iterator = std::string::iterator,
typename Signature = void(engine::api::RouteParameters &)> typename Signature = void(engine::api::RouteParameters &)>
@ -113,8 +113,8 @@ struct RouteParametersGrammar : public BaseParametersGrammar<Iterator, Signature
qi::symbols<char, engine::api::RouteParameters::OverviewType> overview_type; qi::symbols<char, engine::api::RouteParameters::OverviewType> overview_type;
qi::symbols<char, engine::api::RouteParameters::AnnotationsType> annotations_type; qi::symbols<char, engine::api::RouteParameters::AnnotationsType> annotations_type;
}; };
} // namespace api }
} // namespace server }
} // namespace osrm }
#endif #endif

View File

@ -209,6 +209,7 @@ Status MatchPlugin::HandleRequest(const RoutingAlgorithmsInterface &algorithms,
{ {
return routing_algorithms::DEFAULT_GPS_PRECISION * RADIUS_MULTIPLIER; return routing_algorithms::DEFAULT_GPS_PRECISION * RADIUS_MULTIPLIER;
} }
}); });
} }
@ -316,6 +317,6 @@ Status MatchPlugin::HandleRequest(const RoutingAlgorithmsInterface &algorithms,
return Status::Ok; return Status::Ok;
} }
} // namespace plugins }
} // namespace engine }
} // namespace osrm }

View File

@ -200,6 +200,6 @@ Status ViaRoutePlugin::HandleRequest(const RoutingAlgorithmsInterface &algorithm
return Status::Ok; return Status::Ok;
} }
} // namespace plugins }
} // namespace engine }
} // namespace osrm }