Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--base/base_tests/stl_helpers_test.cpp64
-rw-r--r--base/stl_helpers.hpp10
-rw-r--r--routing/features_road_graph.cpp4
-rw-r--r--routing/features_road_graph.hpp2
-rw-r--r--routing/road_graph.cpp70
-rw-r--r--routing/road_graph.hpp36
-rw-r--r--routing/routing_tests/road_graph_builder.cpp2
-rw-r--r--routing/routing_tests/road_graph_builder.hpp2
-rw-r--r--routing/vehicle_model.hpp1
9 files changed, 81 insertions, 110 deletions
diff --git a/base/base_tests/stl_helpers_test.cpp b/base/base_tests/stl_helpers_test.cpp
index ac60b8c064..f42e8ac4df 100644
--- a/base/base_tests/stl_helpers_test.cpp
+++ b/base/base_tests/stl_helpers_test.cpp
@@ -77,41 +77,37 @@ UNIT_TEST(EqualsBy)
UNIT_TEST(SortUnique)
{
- vector<int> v = {1, 2, 1, 4, 3, 5, 2, 7, 1};
- my::SortUnique(v);
- vector<int> const expected = {1, 2, 3, 4, 5, 7};
- TEST_EQUAL(v, expected, ());
-}
+ {
+ vector<int> v = {1, 2, 1, 4, 3, 5, 2, 7, 1};
+ my::SortUnique(v);
+ vector<int> const expected = {1, 2, 3, 4, 5, 7};
+ TEST_EQUAL(v, expected, ());
+ }
+ {
+ using TValue = int;
+ using TPair = pair<TValue, int>;
+ vector<TPair> v =
+ {{1, 22}, {2, 33}, {1, 23}, {4, 54}, {3, 34}, {5, 23}, {2, 23}, {7, 32}, {1, 12}};
-UNIT_TEST(SortUniqueCompPredTest1)
-{
- using TValue = int;
- using TPair = pair<TValue, int>;
- vector<TPair> v =
- {{1, 22}, {2, 33}, {1, 23}, {4, 54}, {3, 34}, {5, 23}, {2, 23}, {7, 32}, {1, 12}};
-
- my::SortUnique<TPair>(v, my::CompareBy(&TPair::first),
- [](TPair const & p1, TPair const & p2) { return p1.first == p2.first; });
-
- vector<TValue> const expected = {1, 2, 3, 4, 5, 7};
- TEST_EQUAL(v.size(), expected.size(), ());
- for (int i = 0; i < v.size(); ++i)
- TEST_EQUAL(v[i].first, expected[i], (i));
-}
+ my::SortUnique<TPair>(v, my::LessBy(&TPair::first), my::EqualsBy(&TPair::first));
-UNIT_TEST(SortUniqueCompPredTest2)
-{
- using TValue = double;
- using TPair = pair<TValue, int>;
- vector<TPair> v =
- {{0.5, 11}, {1000.99, 234}, {0.5, 23}, {1234.56789, 54}, {1000.99, 34}};
-
- my::SortUnique<TPair>(v, my::CompareBy(&TPair::first),
- [](TPair const & p1, TPair const & p2) { return p1.first == p2.first; });
-
- vector<TValue> const expected = {0.5, 1000.99, 1234.56789};
- TEST_EQUAL(v.size(), expected.size(), ());
- for (int i = 0; i < v.size(); ++i)
- TEST_EQUAL(v[i].first, expected[i], (i));
+ vector<TValue> const expected = {1, 2, 3, 4, 5, 7};
+ TEST_EQUAL(v.size(), expected.size(), ());
+ for (int i = 0; i < v.size(); ++i)
+ TEST_EQUAL(v[i].first, expected[i], (i));
+ }
+ {
+ using TValue = double;
+ using TPair = pair<TValue, int>;
+ vector<TPair> v =
+ {{0.5, 11}, {1000.99, 234}, {0.5, 23}, {1234.56789, 54}, {1000.99, 34}};
+
+ my::SortUnique<TPair>(v, my::LessBy(&TPair::first), my::EqualsBy(&TPair::first));
+
+ vector<TValue> const expected = {0.5, 1000.99, 1234.56789};
+ TEST_EQUAL(v.size(), expected.size(), ());
+ for (int i = 0; i < v.size(); ++i)
+ TEST_EQUAL(v[i].first, expected[i], (i));
+ }
}
} // namespace
diff --git a/base/stl_helpers.hpp b/base/stl_helpers.hpp
index b11f95eec7..0121e12613 100644
--- a/base/stl_helpers.hpp
+++ b/base/stl_helpers.hpp
@@ -2,8 +2,10 @@
#include "std/algorithm.hpp"
#include "std/functional.hpp"
+#include "std/utility.hpp"
#include "std/vector.hpp"
+
namespace my
{
namespace impl
@@ -89,11 +91,11 @@ void SortUnique(vector<T> & v)
// Sorts according to |comp| and removes duplicate entries according to |pred| from |v|.
// Note. If several entries are equal according to |pred| an arbitrary entry of them
// is left in |v| after a call of this function.
-template <typename T, typename TComp, typename TPred>
-void SortUnique(vector<T> & v, TComp && comp, TPred && pred)
+template <typename T, typename TLess, typename TEquals>
+void SortUnique(vector<T> & v, TLess && less, TEquals && equals)
{
- sort(v.begin(), v.end(), comp);
- v.erase(unique(v.begin(), v.end(), pred), v.end());
+ sort(v.begin(), v.end(), forward<TLess>(less));
+ v.erase(unique(v.begin(), v.end(), forward<TEquals>(equals)), v.end());
}
template <typename T, class TFn>
diff --git a/routing/features_road_graph.cpp b/routing/features_road_graph.cpp
index 2112e765c3..f32794f4a6 100644
--- a/routing/features_road_graph.cpp
+++ b/routing/features_road_graph.cpp
@@ -212,7 +212,7 @@ void FeaturesRoadGraph::GetJunctionTypes(Junction const & junction, feature::Typ
if (ft.GetFeatureType() != feature::GEOM_POINT)
return;
- if (!PointsAlmostEqualAbs(ft.GetCenter(), cross))
+ if (!my::AlmostEqualAbs(ft.GetCenter(), cross, routing::kPointsEqualEpsilon))
return;
feature::TypesHolder typesHolder(ft);
@@ -224,7 +224,7 @@ void FeaturesRoadGraph::GetJunctionTypes(Junction const & junction, feature::Typ
m_index.ForEachInRect(f, rect, GetStreetReadScale());
}
-IRoadGraph::Mode FeaturesRoadGraph::ConsiderOnewayFeaturesAsBidirectional() const
+IRoadGraph::Mode FeaturesRoadGraph::GetMode() const
{
return m_mode;
};
diff --git a/routing/features_road_graph.hpp b/routing/features_road_graph.hpp
index 28ed0c54f8..af61afd11f 100644
--- a/routing/features_road_graph.hpp
+++ b/routing/features_road_graph.hpp
@@ -71,7 +71,7 @@ public:
vector<pair<Edge, m2::PointD>> & vicinities) const override;
void GetFeatureTypes(FeatureID const & featureId, feature::TypesHolder & types) const override;
void GetJunctionTypes(Junction const & junction, feature::TypesHolder & types) const override;
- IRoadGraph::Mode ConsiderOnewayFeaturesAsBidirectional() const override;
+ IRoadGraph::Mode GetMode() const override;
void ClearState() override;
private:
diff --git a/routing/road_graph.cpp b/routing/road_graph.cpp
index 475f4fa0a3..31ef1db95f 100644
--- a/routing/road_graph.cpp
+++ b/routing/road_graph.cpp
@@ -30,7 +30,8 @@ vector<Edge>::const_iterator FindEdgeContainingPoint(vector<Edge> const & edges,
m2::PointD const v1 = e.GetStartJunction().GetPoint() - pt;
m2::PointD const v2 = e.GetEndJunction().GetPoint() - pt;
- if (PointsAlmostEqualAbs(v1, m2::PointD::Zero()) || PointsAlmostEqualAbs(v2, m2::PointD::Zero()))
+ if (my::AlmostEqualAbs(v1, m2::PointD::Zero(), kPointsEqualEpsilon)
+ || my::AlmostEqualAbs(v2, m2::PointD::Zero(), kPointsEqualEpsilon))
{
// Point p corresponds to the start or the end of the edge.
return true;
@@ -155,54 +156,35 @@ IRoadGraph::RoadInfo::RoadInfo(bool bidirectional, double speedKMPH, initializer
{}
// IRoadGraph::CrossOutgoingLoader ---------------------------------------------
-void IRoadGraph::CrossOutgoingLoader::LoadEdges(FeatureID const & featureId,
- RoadInfo const & roadInfo)
+void IRoadGraph::CrossOutgoingLoader::LoadEdges(FeatureID const & featureId, RoadInfo const & roadInfo)
{
ForEachEdge(roadInfo, [&featureId, &roadInfo, this](size_t i, m2::PointD const & p)
{
- ASSERT_LESS(i, roadInfo.m_points.size(), ());
- if (i > 0 && (roadInfo.m_bidirectional || m_mode == IRoadGraph::Mode::IgnoreOnewayTag))
- {
- // p
- // o------------>o
- m_edges.emplace_back(featureId, false /* forward */, i - 1, p, roadInfo.m_points[i - 1]);
- }
+ ASSERT_LESS(i, roadInfo.m_points.size() - 1, ());
+ m_edges.emplace_back(featureId, true /* forward */, i, p, roadInfo.m_points[i + 1]);
},
[&featureId, &roadInfo, this](size_t i, m2::PointD const & p)
{
ASSERT_LESS(i, roadInfo.m_points.size(), ());
- if (i < roadInfo.m_points.size() - 1)
- {
- // p
- // o------------>o
- m_edges.emplace_back(featureId, true /* forward */, i, p, roadInfo.m_points[i + 1]);
- }
+ if (roadInfo.m_bidirectional || m_mode == IRoadGraph::Mode::IgnoreOnewayTag)
+ m_edges.emplace_back(featureId, false /* forward */, i - 1, p, roadInfo.m_points[i - 1]);
});
}
// IRoadGraph::CrossIngoingLoader ----------------------------------------------
-void IRoadGraph::CrossIngoingLoader::LoadEdges(FeatureID const & featureId,
- RoadInfo const & roadInfo)
+void IRoadGraph::CrossIngoingLoader::LoadEdges(FeatureID const & featureId, RoadInfo const & roadInfo)
{
- ForEachEdge(roadInfo, [&featureId, &roadInfo, this](size_t i, m2::PointD const & p)
+ ForEachEdge(roadInfo,
+ [&featureId, &roadInfo, this](size_t i, m2::PointD const & p)
{
- ASSERT_LESS(i, roadInfo.m_points.size(), ());
- if (i > 0)
- {
- // p
- // o------------>o
- m_edges.emplace_back(featureId, true /* forward */, i - 1, roadInfo.m_points[i - 1], p);
- }
+ ASSERT_LESS(i, roadInfo.m_points.size() - 1, ());
+ if (roadInfo.m_bidirectional || m_mode == IRoadGraph::Mode::IgnoreOnewayTag)
+ m_edges.emplace_back(featureId, false /* forward */, i, roadInfo.m_points[i + 1], p);
},
[&featureId, &roadInfo, this](size_t i, m2::PointD const & p)
{
- ASSERT_LESS(i, roadInfo.m_points.size(), ());
- if (i < roadInfo.m_points.size() - 1 && (roadInfo.m_bidirectional || m_mode == IRoadGraph::Mode::IgnoreOnewayTag))
- {
- // p
- // o------------>o
- m_edges.emplace_back(featureId, false /* forward */, i, roadInfo.m_points[i + 1], p);
- }
+ ASSERT_LESS(i, roadInfo.m_points.size() , ());
+ m_edges.emplace_back(featureId, true /* forward */, i - 1, roadInfo.m_points[i - 1], p);
});
}
@@ -219,28 +201,18 @@ void IRoadGraph::GetIngoingEdges(Junction const & junction, TEdgeVector & edges)
GetRegularIngoingEdges(junction, edges);
}
-void IRoadGraph::LoadOutgoingEdges(m2::PointD const & cross, TEdgeVector & edges) const
-{
- CrossOutgoingLoader loader(cross, ConsiderOnewayFeaturesAsBidirectional(), edges);
- ForEachFeatureClosestToCross(cross, loader);
-}
-
-void IRoadGraph::LoadIngoingEdges(m2::PointD const & cross, TEdgeVector & edges) const
-{
- CrossIngoingLoader loader(cross, ConsiderOnewayFeaturesAsBidirectional(), edges);
- ForEachFeatureClosestToCross(cross, loader);
-}
-
void IRoadGraph::GetRegularOutgoingEdges(Junction const & junction, TEdgeVector & edges) const
{
m2::PointD const cross = junction.GetPoint();
- LoadOutgoingEdges(cross, edges);
+ CrossOutgoingLoader loader(cross, GetMode(), edges);
+ ForEachFeatureClosestToCross(cross, loader);
}
void IRoadGraph::GetRegularIngoingEdges(Junction const & junction, TEdgeVector & edges) const
{
m2::PointD const cross = junction.GetPoint();
- LoadIngoingEdges(cross, edges);
+ CrossIngoingLoader loader(cross, GetMode(), edges);
+ ForEachFeatureClosestToCross(cross, loader);
}
void IRoadGraph::GetFakeOutgoingEdges(Junction const & junction, TEdgeVector & edges) const
@@ -255,9 +227,9 @@ void IRoadGraph::GetFakeOutgoingEdges(Junction const & junction, TEdgeVector & e
void IRoadGraph::GetFakeIngoingEdges(Junction const & junction, TEdgeVector & edges) const
{
- size_t const wasSize = edges.size();
+ size_t const oldSize = edges.size();
GetFakeOutgoingEdges(junction, edges);
- ReverseEdges(wasSize, edges);
+ ReverseEdges(oldSize, edges);
}
void IRoadGraph::ResetFakes()
diff --git a/routing/road_graph.hpp b/routing/road_graph.hpp
index 3ba86baff0..f5fdf160c7 100644
--- a/routing/road_graph.hpp
+++ b/routing/road_graph.hpp
@@ -12,6 +12,7 @@
namespace routing
{
+double constexpr kPointsEqualEpsilon = 1e-6;
/// The Junction class represents a node description on a road network graph
class Junction
@@ -77,12 +78,6 @@ private:
Junction m_endJunction;
};
-inline bool PointsAlmostEqualAbs(const m2::PointD & pt1, const m2::PointD & pt2)
-{
- double constexpr kEpsilon = 1e-6;
- return my::AlmostEqualAbs(pt1.x, pt2.x, kEpsilon) && my::AlmostEqualAbs(pt1.y, pt2.y, kEpsilon);
-}
-
class IRoadGraph
{
public:
@@ -118,6 +113,7 @@ public:
: m_cross(cross), m_mode(mode), m_edges(edges)
{
}
+
virtual ~ICrossEdgesLoader() = default;
void operator()(FeatureID const & featureId, RoadInfo const & roadInfo)
@@ -136,11 +132,21 @@ public:
{
m2::PointD const & p = roadInfo.m_points[i];
- if (!PointsAlmostEqualAbs(m_cross, p))
+ if (!my::AlmostEqualAbs(m_cross, p, kPointsEqualEpsilon))
continue;
- tailFn(i, p);
- headFn(i, p);
+ if (i > 0)
+ {
+ // p
+ // o------------>o
+ tailFn(i, p);
+ }
+ if (i < roadInfo.m_points.size() - 1)
+ {
+ // p
+ // o------------>o
+ headFn(i, p);
+ }
}
}
@@ -153,9 +159,7 @@ public:
{
public:
CrossOutgoingLoader(m2::PointD const & cross, IRoadGraph::Mode mode, TEdgeVector & edges)
- : ICrossEdgesLoader(cross, mode, edges)
- {
- }
+ : ICrossEdgesLoader(cross, mode, edges) {}
private:
// ICrossEdgesLoader overrides:
@@ -166,9 +170,7 @@ public:
{
public:
CrossIngoingLoader(m2::PointD const & cross, IRoadGraph::Mode mode, TEdgeVector & edges)
- : ICrossEdgesLoader(cross, mode, edges)
- {
- }
+ : ICrossEdgesLoader(cross, mode, edges) {}
private:
// ICrossEdgesLoader overrides:
@@ -221,7 +223,7 @@ public:
/// @return Types for specified junction
virtual void GetJunctionTypes(Junction const & junction, feature::TypesHolder & types) const = 0;
- virtual IRoadGraph::Mode ConsiderOnewayFeaturesAsBidirectional() const = 0;
+ virtual IRoadGraph::Mode GetMode() const = 0;
/// Clear all temporary buffers.
virtual void ClearState() {}
@@ -231,8 +233,6 @@ private:
void GetRegularOutgoingEdges(Junction const & junction, TEdgeVector & edges) const;
/// \brief Finds all ingoing regular (non-fake) edges for junction.
void GetRegularIngoingEdges(Junction const & junction, TEdgeVector & edges) const;
- void LoadOutgoingEdges(m2::PointD const & cross, TEdgeVector & edges) const;
- void LoadIngoingEdges(m2::PointD const & cross, TEdgeVector & edges) const;
/// \brief Finds all outgoing fake edges for junction.
void GetFakeOutgoingEdges(Junction const & junction, TEdgeVector & edges) const;
/// \brief Finds all ingoing fake edges for junction.
diff --git a/routing/routing_tests/road_graph_builder.cpp b/routing/routing_tests/road_graph_builder.cpp
index b7308da201..158dec6321 100644
--- a/routing/routing_tests/road_graph_builder.cpp
+++ b/routing/routing_tests/road_graph_builder.cpp
@@ -110,7 +110,7 @@ void RoadGraphMockSource::GetJunctionTypes(Junction const & junction, feature::T
UNUSED_VALUE(types);
}
-IRoadGraph::Mode RoadGraphMockSource::ConsiderOnewayFeaturesAsBidirectional() const
+IRoadGraph::Mode RoadGraphMockSource::GetMode() const
{
return IRoadGraph::Mode::IgnoreOnewayTag;
}
diff --git a/routing/routing_tests/road_graph_builder.hpp b/routing/routing_tests/road_graph_builder.hpp
index de68330a33..bb7c2a6240 100644
--- a/routing/routing_tests/road_graph_builder.hpp
+++ b/routing/routing_tests/road_graph_builder.hpp
@@ -22,7 +22,7 @@ public:
vector<pair<routing::Edge, m2::PointD>> & vicinities) const override;
void GetFeatureTypes(FeatureID const & featureId, feature::TypesHolder & types) const override;
void GetJunctionTypes(routing::Junction const & junction, feature::TypesHolder & types) const override;
- routing::IRoadGraph::Mode ConsiderOnewayFeaturesAsBidirectional() const override;
+ routing::IRoadGraph::Mode GetMode() const override;
private:
vector<RoadInfo> m_roads;
diff --git a/routing/vehicle_model.hpp b/routing/vehicle_model.hpp
index a9778ed934..dbd1ef5205 100644
--- a/routing/vehicle_model.hpp
+++ b/routing/vehicle_model.hpp
@@ -64,6 +64,7 @@ public:
//@}
double GetSpeed(feature::TypesHolder const & types) const;
+
/// \returns true if |types| is a oneway feature.
/// \note According to OSM tag "oneway" could have value "-1". That means it's a oneway feature
/// with reversed geometry. In that case while map generation the geometry of such features