From b39ae74700758e60dc7b06a3044225248b0bb281 Mon Sep 17 00:00:00 2001 From: Daria Volvenkova Date: Tue, 17 Mar 2020 16:47:33 +0300 Subject: [PATCH] [bookmarks] Track selection. Review fixes. --- map/bookmark_manager.cpp | 48 ++++++++++++++++++++-------------------- map/framework.cpp | 22 +++++++++--------- map/track.cpp | 14 ++++++------ map/track.hpp | 5 +++-- 4 files changed, 46 insertions(+), 43 deletions(-) diff --git a/map/bookmark_manager.cpp b/map/bookmark_manager.cpp index 2de92b2aca..4d52b9e8e4 100644 --- a/map/bookmark_manager.cpp +++ b/map/bookmark_manager.cpp @@ -1082,33 +1082,33 @@ BookmarkManager::TrackSelectionInfo BookmarkManager::FindNearestTrack(m2::RectD for (auto trackId : category.GetUserLines()) { auto const track = GetTrack(trackId); - auto const trackRect = track->GetLimitRect(); + auto const & trackRect = track->GetLimitRect(); - if (trackRect.IsIntersect(touchRect)) + if (!trackRect.IsIntersect(touchRect)) + continue; + + auto const & pointsWithAlt = track->GetPointsWithAltitudes(); + for (size_t i = 0; i + 1 < pointsWithAlt.size(); ++i) { - auto const & pointsWithAlt = track->GetPointsWithAltitudes(); - for (size_t i = 0; i + 1 < pointsWithAlt.size(); ++i) - { - auto pt1 = pointsWithAlt[i].GetPoint(); - auto pt2 = pointsWithAlt[i + 1].GetPoint(); - if (m2::Intersect(touchRect, pt1, pt2)) - { - m2::ParametrizedSegment seg(pt1, pt2); - auto const closestPoint = seg.ClosestPointTo(touchRect.Center()); - auto const squaredDist = closestPoint.SquaredLength(touchRect.Center()); - if (squaredDist < minSquaredDist) - { - minSquaredDist = squaredDist; - selectionInfo.m_trackId = trackId; - selectionInfo.m_trackPoint = closestPoint; + auto pt1 = pointsWithAlt[i].GetPoint(); + auto pt2 = pointsWithAlt[i + 1].GetPoint(); + if (!m2::Intersect(touchRect, pt1, pt2)) + continue; - auto const segDistInMeters = mercator::DistanceOnEarth(pointsWithAlt[i].GetPoint(), - closestPoint); - selectionInfo.m_distanceInMeters = segDistInMeters; - if (i > 0) - selectionInfo.m_distanceInMeters += track->GetLengthMeters(i - 1); - } - } + m2::ParametrizedSegment seg(pt1, pt2); + auto const closestPoint = seg.ClosestPointTo(touchRect.Center()); + auto const squaredDist = closestPoint.SquaredLength(touchRect.Center()); + if (squaredDist < minSquaredDist) + { + minSquaredDist = squaredDist; + selectionInfo.m_trackId = trackId; + selectionInfo.m_trackPoint = closestPoint; + + auto const segDistInMeters = mercator::DistanceOnEarth(pointsWithAlt[i].GetPoint(), + closestPoint); + selectionInfo.m_distanceInMeters = segDistInMeters; + if (i > 0) + selectionInfo.m_distanceInMeters += track->GetLengthMeters(i - 1); } } } diff --git a/map/framework.cpp b/map/framework.cpp index 441e8ce6a4..c987d250f8 100644 --- a/map/framework.cpp +++ b/map/framework.cpp @@ -2611,16 +2611,6 @@ std::optional Framework::BuildPlacePageInfo( return outInfo; } - if (buildInfo.IsTrackMatchingEnabled()) - { - auto const trackSelectionInfo = FindTrackInTapPosition(buildInfo); - if (trackSelectionInfo.m_trackId != kml::kInvalidTrackId) - { - BuildTrackPlacePage(trackSelectionInfo, outInfo); - return outInfo; - } - } - if (!buildInfo.m_postcode.empty()) { outInfo.SetSelectedObject(df::SelectionShape::OBJECT_POI); @@ -2635,6 +2625,18 @@ std::optional Framework::BuildPlacePageInfo( FeatureID selectedFeature = buildInfo.m_featureId; auto const isFeatureMatchingEnabled = buildInfo.IsFeatureMatchingEnabled(); + + if (buildInfo.IsTrackMatchingEnabled() && !buildInfo.m_isLongTap && + !(isFeatureMatchingEnabled && selectedFeature.IsValid())) + { + auto const trackSelectionInfo = FindTrackInTapPosition(buildInfo); + if (trackSelectionInfo.m_trackId != kml::kInvalidTrackId) + { + BuildTrackPlacePage(trackSelectionInfo, outInfo); + return outInfo; + } + } + if (isFeatureMatchingEnabled && !selectedFeature.IsValid()) selectedFeature = FindBuildingAtPoint(buildInfo.m_mercator); diff --git a/map/track.cpp b/map/track.cpp index 9e91db592c..a244f28b85 100644 --- a/map/track.cpp +++ b/map/track.cpp @@ -13,11 +13,13 @@ Track::Track(kml::TrackData && data) { m_data.m_id = GetId(); CHECK_GREATER(m_data.m_pointsWithAltitudes.size(), 1, ()); - CacheLengths(); + CacheLengthsAndLimitRect(); } -void Track::CacheLengths() +void Track::CacheLengthsAndLimitRect() { + m_cachedLimitRect.MakeEmpty(); + m_cachedLimitRect.Add(m_data.m_pointsWithAltitudes.front().GetPoint()); m_cachedLengths.resize(m_data.m_pointsWithAltitudes.size() - 1); double length = 0.0; for (size_t i = 1; i < m_data.m_pointsWithAltitudes.size(); ++i) @@ -27,6 +29,7 @@ void Track::CacheLengths() auto const segmentLength = mercator::DistanceOnEarth(pt1, pt2); length += segmentLength; m_cachedLengths[i - 1] = length; + m_cachedLimitRect.Add(pt2); } } @@ -35,12 +38,9 @@ std::string Track::GetName() const return GetPreferredBookmarkStr(m_data.m_name); } -m2::RectD Track::GetLimitRect() const +m2::RectD const & Track::GetLimitRect() const { - m2::RectD rect; - for (auto const & point : m_data.m_pointsWithAltitudes) - rect.Add(point.GetPoint()); - return rect; + return m_cachedLimitRect; } double Track::GetLengthMeters() const diff --git a/map/track.hpp b/map/track.hpp index e93a1484d0..4f1be78c93 100644 --- a/map/track.hpp +++ b/map/track.hpp @@ -20,7 +20,7 @@ public: kml::TrackData const & GetData() const { return m_data; } std::string GetName() const; - m2::RectD GetLimitRect() const; + m2::RectD const & GetLimitRect() const; double GetLengthMeters() const; double GetLengthMeters(size_t segmentIndex) const; @@ -41,11 +41,12 @@ public: bool GetPoint(double distanceInMeters, m2::PointD & pt) const; private: - void CacheLengths(); + void CacheLengthsAndLimitRect(); kml::TrackData m_data; kml::MarkGroupId m_groupID = kml::kInvalidMarkGroupId; kml::MarkId m_selectionMarkId = kml::kInvalidMarkId; std::vector m_cachedLengths; + m2::RectD m_cachedLimitRect; mutable bool m_isDirty = true; };