From 25be811a83323b66f29fec7c4818b57d2b68d189 Mon Sep 17 00:00:00 2001 From: Sergey Magidovich Date: Fri, 26 Jan 2018 16:04:07 +0300 Subject: [OpenLR] Use double for distances. --- openlr/candidate_paths_getter.cpp | 21 ++++++++++----------- openlr/candidate_paths_getter.hpp | 18 +++++++++--------- openlr/helpers.cpp | 5 ++--- openlr/helpers.hpp | 3 +-- openlr/openlr_decoder.cpp | 25 ++++++++++++------------- openlr/paths_connector.cpp | 9 +++++---- openlr/paths_connector.hpp | 2 +- 7 files changed, 40 insertions(+), 43 deletions(-) (limited to 'openlr') 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 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 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 & allPaths) { @@ -244,7 +244,7 @@ void CandidatePathsGetter::GetAllSuitablePaths(Graph::EdgeVector const & startLi void CandidatePathsGetter::GetBestCandidatePaths( vector const & allPaths, bool const isLastPoint, uint32_t const requiredBearing, - uint32_t const bearDistM, m2::PointD const & startPoint, vector & candidates) + double const bearDistM, m2::PointD const & startPoint, vector & candidates) { set candidatePaths; set 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(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 const & pointCandidates, vector & 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::max(); // Domain is roughly [0, 30] - uint32_t m_pathDistanceDiff = + double m_pathDistanceDiff = std::numeric_limits::max(); // Domain is roughly [0, 25] - uint32_t m_startPointDistance = + double m_startPointDistance = std::numeric_limits::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 & allPaths); void GetBestCandidatePaths(std::vector 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 & candidates); void GetLineCandidates(openlr::LocationReferencePoint const & p, bool const isLastPoint, - uint32_t const distanceToNextPoint, + double const distanceToNextPointM, std::vector const & pointCandidates, std::vector & 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(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 -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(actualRouteDistanceM) / requiredRouteDistanceM; + auto const scale = actualRouteDistanceM / requiredRouteDistanceM; LOG(LDEBUG, ("actualRouteDistance:", actualRouteDistanceM, "requiredRouteDistance:", requiredRouteDistanceM, "scale:", scale)); - auto const positiveOffset = - static_cast(segment.m_locationReference.m_positiveOffsetMeters * scale); - auto const negativeOffset = - static_cast(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 #include -#include #include #include @@ -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 const & po bool found = false; auto const & point = points[i - 1]; - auto const distanceToNextPoint = point.m_distanceToNextPoint; + auto const distanceToNextPoint = static_cast(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, greater> q; map scores; map 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; -- cgit v1.2.3