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
path: root/openlr
diff options
context:
space:
mode:
authorSergey Magidovich <mgsergio@mapswithme.com>2018-01-26 16:04:07 +0300
committerYuri Gorshenin <mipt.vi002@gmail.com>2018-02-09 12:19:56 +0300
commit25be811a83323b66f29fec7c4818b57d2b68d189 (patch)
tree21d45493b68cb255a11e1a33bfd17af6913a8513 /openlr
parentb99673f4e6dc568ce056fa1dde50ad77c70cfae2 (diff)
[OpenLR] Use double for distances.
Diffstat (limited to 'openlr')
-rw-r--r--openlr/candidate_paths_getter.cpp21
-rw-r--r--openlr/candidate_paths_getter.hpp18
-rw-r--r--openlr/helpers.cpp5
-rw-r--r--openlr/helpers.hpp3
-rw-r--r--openlr/openlr_decoder.cpp25
-rw-r--r--openlr/paths_connector.cpp9
-rw-r--r--openlr/paths_connector.hpp2
7 files changed, 40 insertions, 43 deletions
diff --git a/openlr/candidate_paths_getter.cpp b/openlr/candidate_paths_getter.cpp
index a61e3bb407..85aa916826 100644
--- a/openlr/candidate_paths_getter.cpp
+++ b/openlr/candidate_paths_getter.cpp
@@ -63,7 +63,7 @@ public:
return m_isLastPoint ? e.GetEndPoint() : e.GetStartPoint();
}
- m2::PointD GetBearingEndPoint(Graph::Edge const & e, uint32_t const distanceM)
+ m2::PointD GetBearingEndPoint(Graph::Edge const & e, double const distanceM)
{
if (distanceM < m_bearDistM && m_bearDistM <= distanceM + EdgeLength(e))
{
@@ -79,7 +79,7 @@ public:
}
private:
- uint32_t m_bearDistM;
+ double m_bearDistM;
bool m_isLastPoint;
};
} // namespace
@@ -144,13 +144,13 @@ bool CandidatePathsGetter::GetLineCandidatesForPoints(
lineCandidates.emplace_back();
auto const isLastPoint = i == points.size() - 1;
- auto const distanceToNextPoint =
+ double const distanceToNextPointM =
(isLastPoint ? points[i - 1] : points[i]).m_distanceToNextPoint;
vector<m2::PointD> pointCandidates;
m_pointsGetter.GetCandidatePoints(MercatorBounds::FromLatLon(points[i].m_latLon),
pointCandidates);
- GetLineCandidates(points[i], isLastPoint, distanceToNextPoint, pointCandidates,
+ GetLineCandidates(points[i], isLastPoint, distanceToNextPointM, pointCandidates,
lineCandidates.back());
if (lineCandidates.back().empty())
@@ -182,7 +182,7 @@ void CandidatePathsGetter::GetStartLines(vector<m2::PointD> const & points, bool
}
void CandidatePathsGetter::GetAllSuitablePaths(Graph::EdgeVector const & startLines,
- bool const isLastPoint, uint32_t const bearDistM,
+ bool const isLastPoint, double const bearDistM,
FunctionalRoadClass const frc,
vector<LinkPtr> & allPaths)
{
@@ -244,7 +244,7 @@ void CandidatePathsGetter::GetAllSuitablePaths(Graph::EdgeVector const & startLi
void CandidatePathsGetter::GetBestCandidatePaths(
vector<LinkPtr> const & allPaths, bool const isLastPoint, uint32_t const requiredBearing,
- uint32_t const bearDistM, m2::PointD const & startPoint, vector<Graph::EdgeVector> & candidates)
+ double const bearDistM, m2::PointD const & startPoint, vector<Graph::EdgeVector> & candidates)
{
set<CandidatePath> candidatePaths;
set<CandidatePath> fakeEndingsCandidatePaths;
@@ -253,8 +253,7 @@ void CandidatePathsGetter::GetBestCandidatePaths(
for (auto const & l : allPaths)
{
auto const bearStartPoint = pointsSelector.GetBearingStartPoint(l->GetStartEdge());
- auto const startPointsDistance =
- static_cast<uint32_t>(MercatorBounds::DistanceOnEarth(bearStartPoint, startPoint));
+ auto const startPointsDistance = MercatorBounds::DistanceOnEarth(bearStartPoint, startPoint);
// Number of edges counting from the last one to check bearing on. Accorfing to OpenLR spec
// we have to check bearing on a point that is no longer than 25 meters traveling down the path.
@@ -324,12 +323,12 @@ void CandidatePathsGetter::GetBestCandidatePaths(
void CandidatePathsGetter::GetLineCandidates(openlr::LocationReferencePoint const & p,
bool const isLastPoint,
- uint32_t const distanceToNextPoint,
+ double const distanceToNextPointM,
vector<m2::PointD> const & pointCandidates,
vector<Graph::EdgeVector> & candidates)
{
- uint32_t const kDefaultBearDistM = 25;
- uint32_t const bearDistM = min(kDefaultBearDistM, distanceToNextPoint);
+ double const kDefaultBearDistM = 25.0;
+ double const bearDistM = min(kDefaultBearDistM, distanceToNextPointM);
LOG(LINFO, ("BearDist is", bearDistM));
diff --git a/openlr/candidate_paths_getter.hpp b/openlr/candidate_paths_getter.hpp
index e59226bd7f..ceb790bd82 100644
--- a/openlr/candidate_paths_getter.hpp
+++ b/openlr/candidate_paths_getter.hpp
@@ -39,7 +39,7 @@ private:
// TODO(mgsergio): Rename to Vertex.
struct Link
{
- Link(LinkPtr const & parent, Graph::Edge const & edge, uint32_t const distanceM)
+ Link(LinkPtr const & parent, Graph::Edge const & edge, double const distanceM)
: m_parent(parent)
, m_edge(edge)
, m_distanceM(distanceM)
@@ -54,7 +54,7 @@ private:
LinkPtr const m_parent;
Graph::Edge const m_edge;
- uint32_t const m_distanceM;
+ double const m_distanceM;
bool const m_hasFake;
};
@@ -66,8 +66,8 @@ private:
CandidatePath() = default;
- CandidatePath(LinkPtr const path, uint32_t const bearingDiff, uint32_t const pathDistanceDiff,
- uint32_t const startPointDistance)
+ CandidatePath(LinkPtr const path, uint32_t const bearingDiff, double const pathDistanceDiff,
+ double const startPointDistance)
: m_path(path)
, m_bearingDiff(bearingDiff)
, m_pathDistanceDiff(pathDistanceDiff)
@@ -87,9 +87,9 @@ private:
LinkPtr m_path = nullptr;
uint32_t m_bearingDiff = std::numeric_limits<uint32_t>::max(); // Domain is roughly [0, 30]
- uint32_t m_pathDistanceDiff =
+ double m_pathDistanceDiff =
std::numeric_limits<uint32_t>::max(); // Domain is roughly [0, 25]
- uint32_t m_startPointDistance =
+ double m_startPointDistance =
std::numeric_limits<uint32_t>::max(); // Domain is roughly [0, 50]
};
@@ -109,16 +109,16 @@ private:
Graph::EdgeVector & edges);
void GetAllSuitablePaths(Graph::EdgeVector const & startLines, bool const isLastPoint,
- uint32_t const bearDistM, FunctionalRoadClass const frc,
+ double const bearDistM, FunctionalRoadClass const frc,
std::vector<LinkPtr> & allPaths);
void GetBestCandidatePaths(std::vector<LinkPtr> const & allPaths, bool const isLastPoint,
- uint32_t const requiredBearing, uint32_t const bearDistM,
+ uint32_t const requiredBearing, double const bearDistM,
m2::PointD const & startPoint,
std::vector<Graph::EdgeVector> & candidates);
void GetLineCandidates(openlr::LocationReferencePoint const & p, bool const isLastPoint,
- uint32_t const distanceToNextPoint,
+ double const distanceToNextPointM,
std::vector<m2::PointD> const & pointCandidates,
std::vector<Graph::EdgeVector> & candidates);
diff --git a/openlr/helpers.cpp b/openlr/helpers.cpp
index 7f6403819f..0be8b92bb0 100644
--- a/openlr/helpers.cpp
+++ b/openlr/helpers.cpp
@@ -18,10 +18,9 @@ bool PointsAreClose(m2::PointD const & p1, m2::PointD const & p2)
return MercatorBounds::DistanceOnEarth(p1, p2) < kMwmRoadCrossingRadiusMeters;
}
-// TODO(mgsergio): Try to use double instead of uint32_t and leave whait is better.
-uint32_t EdgeLength(Graph::Edge const & e)
+double EdgeLength(Graph::Edge const & e)
{
- return static_cast<uint32_t>(MercatorBounds::DistanceOnEarth(e.GetStartPoint(), e.GetEndPoint()));
+ return MercatorBounds::DistanceOnEarth(e.GetStartPoint(), e.GetEndPoint());
}
bool EdgesAreAlmostEqual(Graph::Edge const & e1, Graph::Edge const & e2)
diff --git a/openlr/helpers.hpp b/openlr/helpers.hpp
index 475415f5c7..e3a06f0ac4 100644
--- a/openlr/helpers.hpp
+++ b/openlr/helpers.hpp
@@ -13,8 +13,7 @@ class RoadInfoGetter;
bool PointsAreClose(m2::PointD const & p1, m2::PointD const & p2);
-// TODO(mgsergio): Try to use double instead of uint32_t and leave whait is better.
-uint32_t EdgeLength(Graph::Edge const & e);
+double EdgeLength(Graph::Edge const & e);
bool EdgesAreAlmostEqual(Graph::Edge const & e1, Graph::Edge const & e2);
diff --git a/openlr/openlr_decoder.cpp b/openlr/openlr_decoder.cpp
index 30045cbb87..1e6abaa93a 100644
--- a/openlr/openlr_decoder.cpp
+++ b/openlr/openlr_decoder.cpp
@@ -132,12 +132,12 @@ void ExpandFakes(Index const & index, Graph & g, Graph::EdgeVector & path)
// to some point alog that path and drop everything form the start to that point or from
// that point to the end.
template <typename InputIterator>
-InputIterator CutOffset(InputIterator start, InputIterator const stop, uint32_t const offset)
+InputIterator CutOffset(InputIterator start, InputIterator const stop, double const offset)
{
if (offset == 0)
return start;
- for (uint32_t distance = 0; start != stop; ++start)
+ for (double distance = 0.0; start != stop; ++start)
{
auto const edgeLen = EdgeLength(*start);
if (distance <= offset && offset < distance + edgeLen)
@@ -384,25 +384,24 @@ bool OpenLRDecoder::DecodeSingleSegment(LinearSegment const & segment, Index con
for (auto const & part : resultPath)
route.insert(end(route), begin(part), end(part));
- uint32_t requiredRouteDistanceM = 0;
+ double requiredRouteDistanceM = 0.0;
// Sum app all distances between points. Last point's m_distanceToNextPoint
// should be equal to zero, but let's skip it just in case.
for (auto it = begin(points); it != prev(end(points)); ++it)
requiredRouteDistanceM += it->m_distanceToNextPoint;
- uint32_t actualRouteDistanceM = 0;
+
+ double actualRouteDistanceM = 0.0;
for (auto const & e : route)
actualRouteDistanceM += EdgeLength(e);
- auto const scale = static_cast<double>(actualRouteDistanceM) / requiredRouteDistanceM;
+ auto const scale = actualRouteDistanceM / requiredRouteDistanceM;
LOG(LDEBUG, ("actualRouteDistance:", actualRouteDistanceM,
"requiredRouteDistance:", requiredRouteDistanceM, "scale:", scale));
- auto const positiveOffset =
- static_cast<uint32_t>(segment.m_locationReference.m_positiveOffsetMeters * scale);
- auto const negativeOffset =
- static_cast<uint32_t>(segment.m_locationReference.m_negativeOffsetMeters * scale);
+ auto const positiveOffsetM = segment.m_locationReference.m_positiveOffsetMeters * scale;
+ auto const negativeOffsetM = segment.m_locationReference.m_negativeOffsetMeters * scale;
- if (positiveOffset + negativeOffset >= requiredRouteDistanceM)
+ if (positiveOffsetM + negativeOffsetM >= requiredRouteDistanceM)
{
++stat.m_wrongOffsets;
LOG(LINFO, ("Wrong offsets for segment:", segment.m_segmentId));
@@ -410,9 +409,9 @@ bool OpenLRDecoder::DecodeSingleSegment(LinearSegment const & segment, Index con
}
ExpandFakes(index, graph, route);
- ASSERT(none_of(begin(route), end(route), mem_fn(&Graph::Edge::IsFake)), ());
- CopyWithoutOffsets(begin(route), end(route), back_inserter(path.m_path), positiveOffset,
- negativeOffset);
+ ASSERT(none_of(begin(route), end(route), mem_fn(&Graph::Edge::IsFake)), (segment.m_segmentId));
+ CopyWithoutOffsets(begin(route), end(route), back_inserter(path.m_path), positiveOffsetM,
+ negativeOffsetM);
if (path.m_path.empty())
{
diff --git a/openlr/paths_connector.cpp b/openlr/paths_connector.cpp
index 57a9c46f35..95fe768b26 100644
--- a/openlr/paths_connector.cpp
+++ b/openlr/paths_connector.cpp
@@ -6,7 +6,6 @@
#include <algorithm>
#include <map>
-#include <numeric>
#include <queue>
#include <tuple>
@@ -42,7 +41,7 @@ int32_t PathOverlappingLen(Graph::EdgeVector const & a, Graph::EdgeVector const
}
bool ValidatePath(Graph::EdgeVector const & path,
- uint32_t const distanceToNextPoint,
+ double const distanceToNextPoint,
double const pathLengthTolerance)
{
@@ -88,7 +87,7 @@ bool PathsConnector::ConnectCandidates(vector<LocationReferencePoint> const & po
bool found = false;
auto const & point = points[i - 1];
- auto const distanceToNextPoint = point.m_distanceToNextPoint;
+ auto const distanceToNextPoint = static_cast<double>(point.m_distanceToNextPoint);
auto const & fromCandidates = lineCandidates[i - 1];
auto const & toCandidates = lineCandidates[i];
auto & resultPathPart = resultPath[i - 1];
@@ -159,6 +158,8 @@ bool PathsConnector::FindShortestPath(Graph::Edge const & from, Graph::Edge cons
uint32_t m_score;
};
+ ASSERT(from.HasRealPart() && to.HasRealPart(), ());
+
priority_queue<State, vector<State>, greater<State>> q;
map<Graph::Edge, uint32_t> scores;
map<Graph::Edge, Graph::Edge> links;
@@ -218,7 +219,7 @@ bool PathsConnector::FindShortestPath(Graph::Edge const & from, Graph::Edge cons
bool PathsConnector::ConnectAdjacentCandidateLines(Graph::EdgeVector const & from,
Graph::EdgeVector const & to,
FunctionalRoadClass const frc,
- uint32_t const distanceToNextPoint,
+ double const distanceToNextPoint,
Graph::EdgeVector & resultPath)
{
diff --git a/openlr/paths_connector.hpp b/openlr/paths_connector.hpp
index 4db1187b31..bd16d15f22 100644
--- a/openlr/paths_connector.hpp
+++ b/openlr/paths_connector.hpp
@@ -26,7 +26,7 @@ private:
bool ConnectAdjacentCandidateLines(Graph::EdgeVector const & from, Graph::EdgeVector const & to,
FunctionalRoadClass const frc,
- uint32_t const distanceToNextPoint,
+ double const distanceToNextPoint,
Graph::EdgeVector & resultPath);
double m_pathLengthTolerance;