Change qi::lit for qi::symbols for the sides parameter parser.
Refactor code : - Suppress StartSide Enum - Change Side Structure for Enum Signed-off-by: FILLAU Jean-Maxime <jean-maxime.fillau@mapotempo.com>
This commit is contained in:
parent
2de17f3fd0
commit
ec7934ea33
@ -714,14 +714,14 @@ class ContiguousInternalMemoryDataFacadeBase : public BaseDataFacade
|
|||||||
input_coordinate, max_results, max_distance, bearing, bearing_range);
|
input_coordinate, max_results, max_distance, bearing, bearing_range);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::pair<PhantomNode, PhantomNode> NearestPhantomNodeWithAlternativeFromBigComponent(
|
std::pair<PhantomNode, PhantomNode>
|
||||||
const util::Coordinate input_coordinate,
|
NearestPhantomNodeWithAlternativeFromBigComponent(const util::Coordinate input_coordinate,
|
||||||
const engine::SideValue side_value) const override final
|
const engine::Side side) const override final
|
||||||
{
|
{
|
||||||
BOOST_ASSERT(m_geospatial_query.get());
|
BOOST_ASSERT(m_geospatial_query.get());
|
||||||
|
|
||||||
return m_geospatial_query->NearestPhantomNodeWithAlternativeFromBigComponent(
|
return m_geospatial_query->NearestPhantomNodeWithAlternativeFromBigComponent(
|
||||||
input_coordinate, side_value);
|
input_coordinate, side);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::pair<PhantomNode, PhantomNode> NearestPhantomNodeWithAlternativeFromBigComponent(
|
std::pair<PhantomNode, PhantomNode> NearestPhantomNodeWithAlternativeFromBigComponent(
|
||||||
|
@ -120,7 +120,7 @@ class BaseDataFacade
|
|||||||
|
|
||||||
virtual std::pair<PhantomNode, PhantomNode>
|
virtual std::pair<PhantomNode, PhantomNode>
|
||||||
NearestPhantomNodeWithAlternativeFromBigComponent(const util::Coordinate input_coordinate,
|
NearestPhantomNodeWithAlternativeFromBigComponent(const util::Coordinate input_coordinate,
|
||||||
const engine::SideValue side_value) const = 0;
|
const engine::Side side) const = 0;
|
||||||
virtual std::pair<PhantomNode, PhantomNode>
|
virtual std::pair<PhantomNode, PhantomNode>
|
||||||
NearestPhantomNodeWithAlternativeFromBigComponent(const util::Coordinate input_coordinate,
|
NearestPhantomNodeWithAlternativeFromBigComponent(const util::Coordinate input_coordinate,
|
||||||
const double max_distance) const = 0;
|
const double max_distance) const = 0;
|
||||||
|
@ -212,19 +212,20 @@ template <typename RTreeT, typename DataFacadeT> class GeospatialQuery
|
|||||||
// a second phantom node is return that is the nearest coordinate in a big component.
|
// a second phantom node is return that is the nearest coordinate in a big component.
|
||||||
std::pair<PhantomNode, PhantomNode>
|
std::pair<PhantomNode, PhantomNode>
|
||||||
NearestPhantomNodeWithAlternativeFromBigComponent(const util::Coordinate input_coordinate,
|
NearestPhantomNodeWithAlternativeFromBigComponent(const util::Coordinate input_coordinate,
|
||||||
const engine::SideValue side_value) const
|
const engine::Side side) const
|
||||||
{
|
{
|
||||||
bool has_small_component = false;
|
bool has_small_component = false;
|
||||||
bool has_big_component = false;
|
bool has_big_component = false;
|
||||||
auto results = rtree.Nearest(
|
auto results = rtree.Nearest(
|
||||||
input_coordinate,
|
input_coordinate,
|
||||||
[this, &side_value, &input_coordinate, &has_big_component, &has_small_component](const CandidateSegment &segment) {
|
[this, &side, &input_coordinate, &has_big_component, &has_small_component](
|
||||||
|
const CandidateSegment &segment) {
|
||||||
auto use_segment =
|
auto use_segment =
|
||||||
(!has_small_component || (!has_big_component && !IsTinyComponent(segment)));
|
(!has_small_component || (!has_big_component && !IsTinyComponent(segment)));
|
||||||
auto use_directions = std::make_pair(use_segment, use_segment);
|
auto use_directions = std::make_pair(use_segment, use_segment);
|
||||||
bool isOnewaySegment = !(segment.data.forward_segment_id.enabled &&
|
bool isOnewaySegment = !(segment.data.forward_segment_id.enabled &&
|
||||||
segment.data.reverse_segment_id.enabled);
|
segment.data.reverse_segment_id.enabled);
|
||||||
if (!isOnewaySegment && side_value != BOTH)
|
if (!isOnewaySegment && side != BOTH)
|
||||||
{
|
{
|
||||||
// Check the counter clockwise
|
// Check the counter clockwise
|
||||||
//
|
//
|
||||||
@ -241,8 +242,8 @@ template <typename RTreeT, typename DataFacadeT> class GeospatialQuery
|
|||||||
// if drive left
|
// if drive left
|
||||||
// input_coordinate_is_at_right = !input_coordinate_is_at_right
|
// input_coordinate_is_at_right = !input_coordinate_is_at_right
|
||||||
|
|
||||||
// We reverse goCountrySide if side_value is OPPOSITE
|
// We reverse goCountrySide if side is OPPOSITE
|
||||||
if (side_value == OPPOSITE)
|
if (side == OPPOSITE)
|
||||||
input_coordinate_is_at_right = !input_coordinate_is_at_right;
|
input_coordinate_is_at_right = !input_coordinate_is_at_right;
|
||||||
|
|
||||||
// Apply the side.
|
// Apply the side.
|
||||||
|
@ -231,11 +231,11 @@ class BasePlugin
|
|||||||
BOOST_ASSERT(parameters.IsValid());
|
BOOST_ASSERT(parameters.IsValid());
|
||||||
for (const auto i : util::irange<std::size_t>(0UL, parameters.coordinates.size()))
|
for (const auto i : util::irange<std::size_t>(0UL, parameters.coordinates.size()))
|
||||||
{
|
{
|
||||||
SideValue sideValue = engine::SideValue::BOTH;
|
Side side = engine::Side::BOTH;
|
||||||
// TODO init at SIDE for test
|
// TODO init at SIDE for test
|
||||||
// SideValue sideValue = engine::SideValue::DEFAULT;
|
// SideValue side = engine::SideValue::DEFAULT;
|
||||||
if (use_sides && parameters.sides[i])
|
if (use_sides && parameters.sides[i])
|
||||||
sideValue = parameters.sides[i]->side;
|
side = parameters.sides[i].get();
|
||||||
|
|
||||||
if (use_hints && parameters.hints[i] &&
|
if (use_hints && parameters.hints[i] &&
|
||||||
parameters.hints[i]->IsValid(parameters.coordinates[i], facade))
|
parameters.hints[i]->IsValid(parameters.coordinates[i], facade))
|
||||||
@ -277,7 +277,7 @@ class BasePlugin
|
|||||||
{
|
{
|
||||||
phantom_node_pairs[i] =
|
phantom_node_pairs[i] =
|
||||||
facade.NearestPhantomNodeWithAlternativeFromBigComponent(
|
facade.NearestPhantomNodeWithAlternativeFromBigComponent(
|
||||||
parameters.coordinates[i], sideValue);
|
parameters.coordinates[i], side);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,56 +28,18 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||||||
#ifndef OSRM_ENGINE_SIDE_HPP
|
#ifndef OSRM_ENGINE_SIDE_HPP
|
||||||
#define OSRM_ENGINE_SIDE_HPP
|
#define OSRM_ENGINE_SIDE_HPP
|
||||||
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
namespace osrm
|
namespace osrm
|
||||||
{
|
{
|
||||||
namespace engine
|
namespace engine
|
||||||
{
|
{
|
||||||
|
|
||||||
enum SideValue
|
enum Side
|
||||||
{
|
{
|
||||||
DEFAULT,
|
DEFAULT,
|
||||||
OPPOSITE,
|
OPPOSITE,
|
||||||
BOTH
|
BOTH
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Side
|
|
||||||
{
|
|
||||||
SideValue side;
|
|
||||||
static SideValue fromString(const std::string &str)
|
|
||||||
{
|
|
||||||
if (str == "d")
|
|
||||||
return DEFAULT;
|
|
||||||
else if (str == "o")
|
|
||||||
return OPPOSITE;
|
|
||||||
else
|
|
||||||
return BOTH;
|
|
||||||
}
|
|
||||||
static std::string toString(const Side &side)
|
|
||||||
{
|
|
||||||
switch(side.side)
|
|
||||||
{
|
|
||||||
case(DEFAULT) :
|
|
||||||
return "0";
|
|
||||||
case(OPPOSITE) :
|
|
||||||
return "d";
|
|
||||||
case(BOTH) :
|
|
||||||
return "b";
|
|
||||||
default :
|
|
||||||
//TODO I don't know what to do here.
|
|
||||||
return "b";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
|
||||||
inline bool operator==(const Side lhs, const Side rhs)
|
|
||||||
{
|
|
||||||
return lhs.side == rhs.side;
|
|
||||||
}
|
|
||||||
inline bool operator!=(const Side lhs, const Side rhs) { return !(lhs == rhs); }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -99,16 +99,6 @@ struct BaseParametersGrammar : boost::spirit::qi::grammar<Iterator, Signature>
|
|||||||
base_parameters.bearings.push_back(std::move(bearing));
|
base_parameters.bearings.push_back(std::move(bearing));
|
||||||
};
|
};
|
||||||
|
|
||||||
const auto add_side = [](engine::api::BaseParameters &base_parameters,
|
|
||||||
const boost::optional<std::string> &side_string) {
|
|
||||||
boost::optional<engine::Side> side;
|
|
||||||
if (side_string)
|
|
||||||
{
|
|
||||||
side = engine::Side{engine::Side::fromString(side_string.get())};
|
|
||||||
}
|
|
||||||
base_parameters.sides.push_back(std::move(side));
|
|
||||||
};
|
|
||||||
|
|
||||||
polyline_chars = qi::char_("a-zA-Z0-9_.--[]{}@?|\\%~`^");
|
polyline_chars = qi::char_("a-zA-Z0-9_.--[]{}@?|\\%~`^");
|
||||||
base64_char = qi::char_("a-zA-Z0-9--_=");
|
base64_char = qi::char_("a-zA-Z0-9--_=");
|
||||||
unlimited_rule = qi::lit("unlimited")[qi::_val = std::numeric_limits<double>::infinity()];
|
unlimited_rule = qi::lit("unlimited")[qi::_val = std::numeric_limits<double>::infinity()];
|
||||||
@ -159,13 +149,16 @@ struct BaseParametersGrammar : boost::spirit::qi::grammar<Iterator, Signature>
|
|||||||
qi::lit("bearings=") >
|
qi::lit("bearings=") >
|
||||||
(-(qi::short_ > ',' > qi::short_))[ph::bind(add_bearing, qi::_r1, qi::_1)] % ';';
|
(-(qi::short_ > ',' > qi::short_))[ph::bind(add_bearing, qi::_r1, qi::_1)] % ';';
|
||||||
|
|
||||||
sides_rule = qi::lit("sides=") >
|
side_type.add("d", engine::Side::DEFAULT)("o", engine::Side::OPPOSITE)("b", engine::Side::BOTH);
|
||||||
(-qi::as_string[qi::char_("a-zA")])[ph::bind(add_side, qi::_r1, qi::_1)] % ';';
|
sides_rule =
|
||||||
|
qi::lit("sides=") >
|
||||||
|
(-side_type % ';')[ph::bind(&engine::api::BaseParameters::sides, qi::_r1) = qi::_1];
|
||||||
|
|
||||||
base_rule = radiuses_rule(qi::_r1) //
|
base_rule = radiuses_rule(qi::_r1) //
|
||||||
| hints_rule(qi::_r1) //
|
| hints_rule(qi::_r1) //
|
||||||
| bearings_rule(qi::_r1) //
|
| bearings_rule(qi::_r1) //
|
||||||
| generate_hints_rule(qi::_r1) | sides_rule(qi::_r1);
|
| generate_hints_rule(qi::_r1)
|
||||||
|
| sides_rule(qi::_r1);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
@ -176,9 +169,9 @@ struct BaseParametersGrammar : boost::spirit::qi::grammar<Iterator, Signature>
|
|||||||
qi::rule<Iterator, Signature> bearings_rule;
|
qi::rule<Iterator, Signature> bearings_rule;
|
||||||
qi::rule<Iterator, Signature> radiuses_rule;
|
qi::rule<Iterator, Signature> radiuses_rule;
|
||||||
qi::rule<Iterator, Signature> hints_rule;
|
qi::rule<Iterator, Signature> hints_rule;
|
||||||
qi::rule<Iterator, Signature> sides_rule;
|
|
||||||
|
|
||||||
qi::rule<Iterator, Signature> generate_hints_rule;
|
qi::rule<Iterator, Signature> generate_hints_rule;
|
||||||
|
qi::rule<Iterator, Signature> sides_rule;
|
||||||
|
|
||||||
qi::rule<Iterator, osrm::engine::Bearing()> bearing_rule;
|
qi::rule<Iterator, osrm::engine::Bearing()> bearing_rule;
|
||||||
qi::rule<Iterator, osrm::util::Coordinate()> location_rule;
|
qi::rule<Iterator, osrm::util::Coordinate()> location_rule;
|
||||||
@ -188,6 +181,8 @@ struct BaseParametersGrammar : boost::spirit::qi::grammar<Iterator, Signature>
|
|||||||
qi::rule<Iterator, std::string()> polyline_chars;
|
qi::rule<Iterator, std::string()> polyline_chars;
|
||||||
qi::rule<Iterator, double()> unlimited_rule;
|
qi::rule<Iterator, double()> unlimited_rule;
|
||||||
qi::real_parser<double, json_policy> double_;
|
qi::real_parser<double, json_policy> double_;
|
||||||
|
|
||||||
|
qi::symbols<char, engine::Side> side_type;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -146,9 +146,8 @@ class MockBaseDataFacade : public engine::datafacade::BaseDataFacade
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::pair<engine::PhantomNode, engine::PhantomNode>
|
std::pair<engine::PhantomNode, engine::PhantomNode>
|
||||||
NearestPhantomNodeWithAlternativeFromBigComponent(
|
NearestPhantomNodeWithAlternativeFromBigComponent(const util::Coordinate /*input_coordinate*/,
|
||||||
const util::Coordinate /*input_coordinate*/,
|
const engine::Side /*side*/) const override
|
||||||
const engine::SideValue /*side_value*/) const override
|
|
||||||
{
|
{
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
@ -57,7 +57,7 @@ inline std::ostream &operator<<(std::ostream &out, Bearing bearing)
|
|||||||
|
|
||||||
inline std::ostream &operator<<(std::ostream &out, Side side)
|
inline std::ostream &operator<<(std::ostream &out, Side side)
|
||||||
{
|
{
|
||||||
out << Side::toString(side);
|
out << side;
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -46,7 +46,7 @@ BOOST_AUTO_TEST_CASE(invalid_route_urls)
|
|||||||
BOOST_CHECK_EQUAL(testInvalidOptions<RouteParameters>("1,2;3,4?overview=false&radiuses=foo"),
|
BOOST_CHECK_EQUAL(testInvalidOptions<RouteParameters>("1,2;3,4?overview=false&radiuses=foo"),
|
||||||
32UL);
|
32UL);
|
||||||
BOOST_CHECK_EQUAL(testInvalidOptions<RouteParameters>("1,2;3,4?overview=false&sides=foo"),
|
BOOST_CHECK_EQUAL(testInvalidOptions<RouteParameters>("1,2;3,4?overview=false&sides=foo"),
|
||||||
30UL);
|
29UL);
|
||||||
BOOST_CHECK_EQUAL(testInvalidOptions<RouteParameters>("1,2;3,4?overview=false&hints=foo"),
|
BOOST_CHECK_EQUAL(testInvalidOptions<RouteParameters>("1,2;3,4?overview=false&hints=foo"),
|
||||||
29UL);
|
29UL);
|
||||||
BOOST_CHECK_EQUAL(testInvalidOptions<RouteParameters>("1,2;3,4?overview=false&hints=;;; ;"),
|
BOOST_CHECK_EQUAL(testInvalidOptions<RouteParameters>("1,2;3,4?overview=false&hints=;;; ;"),
|
||||||
@ -400,10 +400,7 @@ BOOST_AUTO_TEST_CASE(valid_route_urls)
|
|||||||
BOOST_CHECK_EQUAL(result_17->annotations, true);
|
BOOST_CHECK_EQUAL(result_17->annotations, true);
|
||||||
|
|
||||||
std::vector<boost::optional<engine::Side>> sides_18 = {
|
std::vector<boost::optional<engine::Side>> sides_18 = {
|
||||||
boost::none,
|
boost::none, engine::Side::DEFAULT, engine::Side::BOTH, engine::Side::OPPOSITE,
|
||||||
engine::Side{engine::SideValue::DEFAULT},
|
|
||||||
engine::Side{engine::SideValue::BOTH},
|
|
||||||
engine::Side{engine::SideValue::OPPOSITE},
|
|
||||||
};
|
};
|
||||||
RouteParameters reference_18{false,
|
RouteParameters reference_18{false,
|
||||||
false,
|
false,
|
||||||
|
Loading…
Reference in New Issue
Block a user