diff --git a/CHANGELOG.md b/CHANGELOG.md index 7610d47f0..507df3ac8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -39,6 +39,7 @@ - BREAKING: Traffic signals will no longer be represented as turns internally. This requires re-processing of data but enables via-way turn restrictions across highway=traffic_signals - Additional checks for empty segments when loading traffic data files - Tunes the constants for turns in sharp curves just a tiny bit to circumvent a mix-up in fork directions at a specific intersection (https://github.com/Project-OSRM/osrm-backend/issues/4331) + - BREAKING: added `is_left_hand_driving` vector to `.ebg_nodes` file - Infrastructure - Refactor datafacade to make implementing additional DataFacades simpler - Bugfixes diff --git a/features/testbot/approaches.feature b/features/testbot/approaches.feature index 202ba6198..599dd8ee4 100644 --- a/features/testbot/approaches.feature +++ b/features/testbot/approaches.feature @@ -202,9 +202,15 @@ Feature: Approach parameter Scenario: Start End same approach, option unrestricted for Start and curb for End, left-hand driving - Given the profile file "testbot" initialized with + Given the profile file """ - profile.properties.left_hand_driving = true + local functions = require('testbot') + local testbot_process_way = functions.process_way + functions.process_way = function(profile, way, result) + testbot_process_way(profile, way, result) + result.is_left_hand_driving = true + end + return functions """ And the node map """ diff --git a/include/engine/datafacade/contiguous_internalmem_datafacade.hpp b/include/engine/datafacade/contiguous_internalmem_datafacade.hpp index 44e322d85..cc2aaf18b 100644 --- a/include/engine/datafacade/contiguous_internalmem_datafacade.hpp +++ b/include/engine/datafacade/contiguous_internalmem_datafacade.hpp @@ -362,11 +362,18 @@ class ContiguousInternalMemoryDataFacadeBase : public BaseDataFacade util::vector_view classes( classes_list_ptr, layout.num_entries[storage::DataLayout::CLASSES_LIST]); + auto is_left_hand_driving_ptr = layout.GetBlockPtr( + memory_ptr, storage::DataLayout::IS_LEFT_HAND_DRIVING_LIST); + util::vector_view is_left_hand_driving( + is_left_hand_driving_ptr, + layout.num_entries[storage::DataLayout::IS_LEFT_HAND_DRIVING_LIST]); + edge_based_node_data = extractor::EdgeBasedNodeDataView(std::move(geometry_ids), std::move(name_ids), std::move(component_ids), std::move(travel_modes), - std::move(classes)); + std::move(classes), + std::move(is_left_hand_driving)); } void InitializeEdgeInformationPointers(storage::DataLayout &layout, char *memory_ptr) @@ -939,9 +946,10 @@ class ContiguousInternalMemoryDataFacadeBase : public BaseDataFacade m_lane_description_offsets[lane_description_id + 1]); } - bool IsLeftHandDriving() const override final + bool IsLeftHandDriving(const NodeID id) const override final { - return m_profile_properties->left_hand_driving; // TODO: remove + // TODO: can be moved to a data block indexed by GeometryID + return edge_based_node_data.IsLeftHandDriving(id); } }; diff --git a/include/engine/datafacade/datafacade_base.hpp b/include/engine/datafacade/datafacade_base.hpp index 1011d853e..a816ed5d2 100644 --- a/include/engine/datafacade/datafacade_base.hpp +++ b/include/engine/datafacade/datafacade_base.hpp @@ -190,7 +190,7 @@ class BaseDataFacade virtual util::guidance::EntryClass GetEntryClass(const EdgeID turn_id) const = 0; - virtual bool IsLeftHandDriving() const = 0; + virtual bool IsLeftHandDriving(const NodeID id) const = 0; }; } } diff --git a/include/engine/geospatial_query.hpp b/include/engine/geospatial_query.hpp index 70c984bc9..d5b78986d 100644 --- a/include/engine/geospatial_query.hpp +++ b/include/engine/geospatial_query.hpp @@ -650,7 +650,7 @@ template class GeospatialQuery bool input_coordinate_is_at_right = !util::coordinate_calculation::isCCW( coordinates[segment.data.u], coordinates[segment.data.v], input_coordinate); - if (datafacade.IsLeftHandDriving()) + if (datafacade.IsLeftHandDriving(segment.data.forward_segment_id.id)) input_coordinate_is_at_right = !input_coordinate_is_at_right; return std::make_pair(input_coordinate_is_at_right, (!input_coordinate_is_at_right)); diff --git a/include/extractor/node_data_container.hpp b/include/extractor/node_data_container.hpp index 4032dd694..611c73ac2 100644 --- a/include/extractor/node_data_container.hpp +++ b/include/extractor/node_data_container.hpp @@ -42,7 +42,8 @@ template class EdgeBasedNodeDataContainerImpl EdgeBasedNodeDataContainerImpl() = default; EdgeBasedNodeDataContainerImpl(std::size_t size) - : geometry_ids(size), name_ids(size), component_ids(size), travel_modes(size), classes(size) + : geometry_ids(size), name_ids(size), component_ids(size), travel_modes(size), + classes(size), is_left_hand_driving(size) { } @@ -50,10 +51,11 @@ template class EdgeBasedNodeDataContainerImpl Vector name_ids, Vector component_ids, Vector travel_modes, - Vector classes) + Vector classes, + Vector is_left_hand_driving) : geometry_ids(std::move(geometry_ids)), name_ids(std::move(name_ids)), component_ids(std::move(component_ids)), travel_modes(std::move(travel_modes)), - classes(std::move(classes)) + classes(std::move(classes)), is_left_hand_driving(std::move(is_left_hand_driving)) { } @@ -67,18 +69,25 @@ template class EdgeBasedNodeDataContainerImpl ClassData GetClassData(const NodeID node_id) const { return classes[node_id]; } + ClassData IsLeftHandDriving(const NodeID node_id) const + { + return is_left_hand_driving[node_id]; + } + // Used by EdgeBasedGraphFactory to fill data structure template > void SetData(NodeID node_id, GeometryID geometry_id, NameID name_id, TravelMode travel_mode, - ClassData class_data) + ClassData class_data, + bool is_left_hand_driving_flag) { geometry_ids[node_id] = geometry_id; name_ids[node_id] = name_id; travel_modes[node_id] = travel_mode; classes[node_id] = class_data; + is_left_hand_driving[node_id] = is_left_hand_driving_flag; } // Used by EdgeBasedGraphFactory to fill data structure @@ -102,6 +111,8 @@ template class EdgeBasedNodeDataContainerImpl util::inplacePermutation(component_ids.begin(), component_ids.end(), permutation); util::inplacePermutation(travel_modes.begin(), travel_modes.end(), permutation); util::inplacePermutation(classes.begin(), classes.end(), permutation); + util::inplacePermutation( + is_left_hand_driving.begin(), is_left_hand_driving.end(), permutation); } // all containers have the exact same size @@ -111,6 +122,7 @@ template class EdgeBasedNodeDataContainerImpl BOOST_ASSERT(geometry_ids.size() == component_ids.size()); BOOST_ASSERT(geometry_ids.size() == travel_modes.size()); BOOST_ASSERT(geometry_ids.size() == classes.size()); + BOOST_ASSERT(geometry_ids.size() == is_left_hand_driving.size()); return geometry_ids.size(); } @@ -120,6 +132,7 @@ template class EdgeBasedNodeDataContainerImpl Vector component_ids; Vector travel_modes; Vector classes; + Vector is_left_hand_driving; }; } diff --git a/include/extractor/serialization.hpp b/include/extractor/serialization.hpp index 8a361e194..02b1e54a3 100644 --- a/include/extractor/serialization.hpp +++ b/include/extractor/serialization.hpp @@ -125,6 +125,7 @@ inline void read(storage::io::FileReader &reader, storage::serialization::read(reader, node_data_container.component_ids); storage::serialization::read(reader, node_data_container.travel_modes); storage::serialization::read(reader, node_data_container.classes); + storage::serialization::read(reader, node_data_container.is_left_hand_driving); } template @@ -136,6 +137,7 @@ inline void write(storage::io::FileWriter &writer, storage::serialization::write(writer, node_data_container.component_ids); storage::serialization::write(writer, node_data_container.travel_modes); storage::serialization::write(writer, node_data_container.classes); + storage::serialization::write(writer, node_data_container.is_left_hand_driving); } inline void read(storage::io::FileReader &reader, NodeRestriction &restriction) diff --git a/include/storage/serialization.hpp b/include/storage/serialization.hpp index b52c9115e..fbd7e4c5a 100644 --- a/include/storage/serialization.hpp +++ b/include/storage/serialization.hpp @@ -137,7 +137,7 @@ template <> inline void write(io::FileWriter &writer, const util::vector_v template <> inline void read(io::FileReader &reader, std::vector &data) { const auto count = reader.ReadElementCount64(); - BOOST_ASSERT(data.size() == count); + data.resize(count); for (const auto index : util::irange(0, count)) { data[index] = reader.ReadOne(); diff --git a/include/storage/shared_datatype.hpp b/include/storage/shared_datatype.hpp index 3851a115e..a7c493714 100644 --- a/include/storage/shared_datatype.hpp +++ b/include/storage/shared_datatype.hpp @@ -24,6 +24,7 @@ const constexpr char *block_id_to_name[] = {"NAME_CHAR_DATA", "COMPONENT_ID_LIST", "TRAVEL_MODE_LIST", "CLASSES_LIST", + "IS_LEFT_HAND_DRIVING_LIST", "CH_GRAPH_NODE_LIST", "CH_GRAPH_EDGE_LIST", "CH_EDGE_FILTER_0", @@ -111,6 +112,7 @@ struct DataLayout COMPONENT_ID_LIST, TRAVEL_MODE_LIST, CLASSES_LIST, + IS_LEFT_HAND_DRIVING_LIST, CH_GRAPH_NODE_LIST, CH_GRAPH_EDGE_LIST, CH_EDGE_FILTER_0, diff --git a/src/extractor/edge_based_graph_factory.cpp b/src/extractor/edge_based_graph_factory.cpp index 20012bc97..968ffa665 100644 --- a/src/extractor/edge_based_graph_factory.cpp +++ b/src/extractor/edge_based_graph_factory.cpp @@ -168,14 +168,16 @@ NBGToEBG EdgeBasedGraphFactory::InsertEdgeBasedNode(const NodeID node_u, const N GeometryID{packed_geometry_id, true}, forward_data.name_id, forward_data.travel_mode, - forward_data.classes); + forward_data.classes, + forward_data.is_left_hand_driving); if (reverse_data.edge_id != SPECIAL_EDGEID) { m_edge_based_node_container.SetData(reverse_data.edge_id, GeometryID{packed_geometry_id, false}, reverse_data.name_id, reverse_data.travel_mode, - reverse_data.classes); + reverse_data.classes, + reverse_data.is_left_hand_driving); } // Add segments of edge-based nodes @@ -378,7 +380,8 @@ EdgeBasedGraphFactory::GenerateEdgeExpandedNodes(const WayRestrictionMap &way_re m_edge_based_node_container.GetGeometryID(static_cast(edge_data.edge_id)), edge_data.name_id, edge_data.travel_mode, - edge_data.classes); + edge_data.classes, + edge_data.is_left_hand_driving); m_edge_based_node_weights.push_back(m_edge_based_node_weights[eid]); diff --git a/src/storage/storage.cpp b/src/storage/storage.cpp index a8d52b639..fe1d05da7 100644 --- a/src/storage/storage.cpp +++ b/src/storage/storage.cpp @@ -259,6 +259,7 @@ void Storage::PopulateLayout(DataLayout &layout) layout.SetBlockSize(DataLayout::COMPONENT_ID_LIST, nodes_number); layout.SetBlockSize(DataLayout::TRAVEL_MODE_LIST, nodes_number); layout.SetBlockSize(DataLayout::CLASSES_LIST, nodes_number); + layout.SetBlockSize(DataLayout::IS_LEFT_HAND_DRIVING_LIST, nodes_number); } if (boost::filesystem::exists(config.GetPath(".osrm.hsgr"))) @@ -733,11 +734,18 @@ void Storage::PopulateData(const DataLayout &layout, char *memory_ptr) util::vector_view classes( classes_list_ptr, layout.num_entries[storage::DataLayout::CLASSES_LIST]); + auto is_left_hand_driving_ptr = layout.GetBlockPtr( + memory_ptr, storage::DataLayout::IS_LEFT_HAND_DRIVING_LIST); + util::vector_view is_left_hand_driving( + is_left_hand_driving_ptr, + layout.num_entries[storage::DataLayout::IS_LEFT_HAND_DRIVING_LIST]); + extractor::EdgeBasedNodeDataView node_data(std::move(geometry_ids), std::move(name_ids), std::move(component_ids), std::move(travel_modes), - std::move(classes)); + std::move(classes), + std::move(is_left_hand_driving)); extractor::files::readNodeData(config.GetPath(".osrm.ebg_nodes"), node_data); } diff --git a/unit_tests/engine/offline_facade.cpp b/unit_tests/engine/offline_facade.cpp index 6a43ee50d..20b433011 100644 --- a/unit_tests/engine/offline_facade.cpp +++ b/unit_tests/engine/offline_facade.cpp @@ -365,7 +365,7 @@ class ContiguousInternalMemoryDataFacade } util::guidance::EntryClass GetEntryClass(const EdgeID /*turn_id*/) const override { return {}; } - bool IsLeftHandDriving() const override { return false; } + bool IsLeftHandDriving(const NodeID /*id*/) const override { return false; } }; } // datafacade diff --git a/unit_tests/mocks/mock_datafacade.hpp b/unit_tests/mocks/mock_datafacade.hpp index 0a09a537b..331f11f41 100644 --- a/unit_tests/mocks/mock_datafacade.hpp +++ b/unit_tests/mocks/mock_datafacade.hpp @@ -223,7 +223,7 @@ class MockBaseDataFacade : public engine::datafacade::BaseDataFacade const char *GetWeightName() const override final { return "duration"; } unsigned GetWeightPrecision() const override final { return 1; } double GetWeightMultiplier() const override final { return 10.; } - bool IsLeftHandDriving() const override { return false; } + bool IsLeftHandDriving(const NodeID /*id*/) const override { return false; } util::guidance::TurnBearing PreTurnBearing(const EdgeID /*eid*/) const override final {