diff --git a/geometry/screenbase.cpp b/geometry/screenbase.cpp index 134339413b..50d2e751b5 100644 --- a/geometry/screenbase.cpp +++ b/geometry/screenbase.cpp @@ -225,6 +225,13 @@ void ScreenBase::PtoG(m2::RectD const & pxRect, m2::RectD & glbRect) const glbRect = m2::RectD(PtoG(pxRect.LeftTop()), PtoG(pxRect.RightBottom())); } +void ScreenBase::GetTouchRect(m2::PointD const & pixPoint, double pixRadius, + m2::AnyRectD & glbRect) const +{ + double const r = pixRadius * m_Scale; + glbRect = m2::AnyRectD(PtoG(pixPoint), m_Angle, m2::RectD(-r, -r, r, r)); +} + bool IsPanningAndRotate(ScreenBase const & s1, ScreenBase const & s2) { m2::RectD const & r1 = s1.GlobalRect().GetLocalRect(); diff --git a/geometry/screenbase.hpp b/geometry/screenbase.hpp index 0f90a4769e..6ab3b9bb65 100644 --- a/geometry/screenbase.hpp +++ b/geometry/screenbase.hpp @@ -97,6 +97,8 @@ public: void GtoP(m2::RectD const & gr, m2::RectD & sr) const; void PtoG(m2::RectD const & pr, m2::RectD & gr) const; + void GetTouchRect(m2::PointD const & pixPoint, double pixRadius, m2::AnyRectD & glbRect) const; + math::Matrix const & GtoPMatrix() const; math::Matrix const & PtoGMatrix() const; diff --git a/map/framework.cpp b/map/framework.cpp index 40dd226a5b..65811bef7e 100644 --- a/map/framework.cpp +++ b/map/framework.cpp @@ -422,9 +422,9 @@ BookmarkAndCategory Framework::GetBookmark(m2::PointD const & pxPoint) const BookmarkAndCategory Framework::GetBookmark(m2::PointD const & pxPoint, double visualScale) const { // Get the global rect of touching area. - int const sm = TOUCH_PIXEL_RADIUS * visualScale; - m2::RectD rect(PtoG(m2::PointD(pxPoint.x - sm, pxPoint.y - sm)), - PtoG(m2::PointD(pxPoint.x + sm, pxPoint.y + sm))); + m2::AnyRectD rect; + m_navigator.GetTouchRect(pxPoint, TOUCH_PIXEL_RADIUS * visualScale, rect); + m2::PointD const center = rect.GlobalCenter(); int retBookmarkCategory = -1; int retBookmark = -1; @@ -438,7 +438,7 @@ BookmarkAndCategory Framework::GetBookmark(m2::PointD const & pxPoint, double vi m2::PointD const pt = m_bmManager.AdditionalPoiLayerGetBookmark(i)->GetOrg(); if (rect.IsPointInside(pt)) { - double const d = rect.Center().SquareLength(pt); + double const d = center.SquareLength(pt); if (d < minD) { retBookmarkCategory = static_cast(additionalLayerCategory); @@ -463,7 +463,7 @@ BookmarkAndCategory Framework::GetBookmark(m2::PointD const & pxPoint, double vi if (rect.IsPointInside(pt)) { - double const d = rect.Center().SquareLength(pt); + double const d = center.SquareLength(pt); if ((currentCategoryIsVisible && !returnBookmarkIsVisible) || (d < minD)) { @@ -1601,9 +1601,10 @@ void Framework::DrawMapApiPoints(shared_ptr const & e) /// @todo Create method that will run all layers without copy/past bool Framework::GetMapApiPoint(m2::PointD const & pxPoint, url_scheme::ApiPoint & point) { - int const sm = TOUCH_PIXEL_RADIUS * GetVisualScale(); - m2::RectD const rect(PtoG(m2::PointD(pxPoint.x - sm, pxPoint.y - sm)), - PtoG(m2::PointD(pxPoint.x + sm, pxPoint.y + sm))); + m2::AnyRectD rect; + m_navigator.GetTouchRect(pxPoint, TOUCH_PIXEL_RADIUS * GetVisualScale(), rect); + m2::PointD const center = rect.GlobalCenter(); + double minD = numeric_limits::max(); bool result = false; @@ -1615,7 +1616,7 @@ bool Framework::GetMapApiPoint(m2::PointD const & pxPoint, url_scheme::ApiPoint MercatorBounds::LatToY(vect[i].m_lat))); if (rect.IsPointInside(pt)) { - double const d = rect.Center().SquareLength(pt); + double const d = center.SquareLength(pt); if (d < minD) { point = vect[i]; diff --git a/map/navigator.cpp b/map/navigator.cpp index 30a4c82fb2..75698f0f9a 100644 --- a/map/navigator.cpp +++ b/map/navigator.cpp @@ -118,6 +118,11 @@ m2::PointD Navigator::PtoG(m2::PointD const & pt) const return m_Screen.PtoG(ShiftPoint(pt)); } +void Navigator::GetTouchRect(m2::PointD const & pixPoint, double pixRadius, m2::AnyRectD & glbRect) const +{ + m_Screen.GetTouchRect(ShiftPoint(pixPoint), pixRadius, glbRect); +} + bool Navigator::CanShrinkInto(ScreenBase const & screen, m2::RectD const & boundRect) { m2::RectD clipRect = screen.ClipRect(); diff --git a/map/navigator.hpp b/map/navigator.hpp index 3bcb3820bf..bbb2030092 100644 --- a/map/navigator.hpp +++ b/map/navigator.hpp @@ -28,6 +28,8 @@ public: m2::PointD GtoP(m2::PointD const & pt) const; m2::PointD PtoG(m2::PointD const & pt) const; + void GetTouchRect(m2::PointD const & pixPoint, double pixRadius, m2::AnyRectD & glbRect) const; + void StartDrag(m2::PointD const & pt, double timeInSec); void DoDrag(m2::PointD const & pt, double timeInSec); void StopDrag(m2::PointD const & pt, double timeInSec, bool animate);