From cdc5f9449082f2d857e18da01ed936d299f63cd9 Mon Sep 17 00:00:00 2001 From: vng Date: Wed, 2 Oct 2013 20:51:14 +0300 Subject: [PATCH] Better check for minimal rect (upper style scale). Fixed bug in different scales for yopme. --- map/framework.cpp | 42 ++++++++++++++++-------------------------- map/framework.hpp | 19 ++++++++++++------- 2 files changed, 28 insertions(+), 33 deletions(-) diff --git a/map/framework.cpp b/map/framework.cpp index b3fad7228c..7367e2eef8 100644 --- a/map/framework.cpp +++ b/map/framework.cpp @@ -830,8 +830,6 @@ void Framework::SetViewportCenter(m2::PointD const & pt) Invalidate(); } -static int const theMetersFactor = 6; - m2::AnyRectD Framework::ToRotated(m2::RectD const & rect) const { double const dx = rect.SizeX(); @@ -842,16 +840,11 @@ m2::AnyRectD Framework::ToRotated(m2::RectD const & rect) const m2::RectD(-dx/2, -dy/2, dx/2, dy/2)); } -void Framework::CheckMinGlobalRect(m2::AnyRectD & rect) const +void Framework::CheckMinGlobalRect(m2::RectD & rect) const { - m2::RectD const minRect = MercatorBounds::RectByCenterXYAndSizeInMeters( - rect.GlobalCenter(), theMetersFactor * m_metresMinWidth); - - m2::AnyRectD const minAnyRect = ToRotated(minRect); - - /// @todo It would be better here to check only AnyRect ortho-sizes with minimal values. - if (minAnyRect.IsRectInside(rect)) - rect = minAnyRect; + m2::RectD const minRect = m_scales.GetRectForDrawScale(scales::GetUpperStyleScale(), rect.Center()); + if (minRect.IsRectInside(rect)) + rect = minRect; } bool Framework::CheckMinMaxVisibleScale(m2::RectD & rect, int maxScale/* = -1*/) const @@ -880,44 +873,41 @@ bool Framework::CheckMinMaxVisibleScale(m2::RectD & rect, int maxScale/* = -1*/) void Framework::ShowRect(double lat, double lon, double zoom) { - m2::RectD rect = m_scales.GetRectForDrawScale(zoom, - m2::PointD(MercatorBounds::LonToX(lon), - MercatorBounds::LatToY(lat))); - ShowRectEx(rect); + m2::PointD center(MercatorBounds::LonToX(lon), MercatorBounds::LatToY(lat)); + ShowRectEx(m_scales.GetRectForDrawScale(zoom, center)); } -void Framework::ShowRect(m2::RectD const & r) +void Framework::ShowRect(m2::RectD rect) { - m2::AnyRectD rect(r); CheckMinGlobalRect(rect); - m_navigator.SetFromRect(rect); + m_navigator.SetFromRect(m2::AnyRectD(rect)); Invalidate(); } -void Framework::ShowRectEx(m2::RectD const & rect) +void Framework::ShowRectEx(m2::RectD rect) { - ShowRectFixed(ToRotated(rect)); + CheckMinGlobalRect(rect); + + ShowRectFixed(rect); } void Framework::ShowRectExVisibleScale(m2::RectD rect, int maxScale/* = -1*/) { CheckMinMaxVisibleScale(rect, maxScale); - ShowRectEx(rect); + + ShowRectFixed(rect); } -void Framework::ShowRectFixed(m2::AnyRectD const & r) +void Framework::ShowRectFixed(m2::RectD const & r) { - m2::AnyRectD rect(r); - CheckMinGlobalRect(rect); - double const halfSize = m_scales.GetTileSize() / 2.0; m2::RectD etalonRect(-halfSize, -halfSize, halfSize, halfSize); m2::PointD const pxCenter = m_navigator.Screen().PixelRect().Center(); etalonRect.Offset(pxCenter); - m_navigator.SetFromRects(rect, etalonRect); + m_navigator.SetFromRects(ToRotated(r), etalonRect); Invalidate(); } diff --git a/map/framework.hpp b/map/framework.hpp index b1bbe41846..41cd4112b7 100644 --- a/map/framework.hpp +++ b/map/framework.hpp @@ -368,19 +368,24 @@ public: virtual void EndPaint(shared_ptr const & e); private: - m2::AnyRectD ToRotated(m2::RectD const & rect) const; - void CheckMinGlobalRect(m2::AnyRectD & rect) const; + /// Always check rect in public function for minimal draw scale. + void CheckMinGlobalRect(m2::RectD & rect) const; /// @return true if rect was fixed to display downloaded zoom level (world map) bool CheckMinMaxVisibleScale(m2::RectD & rect, int maxScale = -1) const; - void ShowRectFixed(m2::AnyRectD const & rect); + + m2::AnyRectD ToRotated(m2::RectD const & rect) const; + void ShowRectFixed(m2::RectD const & rect); public: + /// Show rect for point and needed draw scale. void ShowRect(double lat, double lon, double zoom); - /// Set navigator viewport by rect as-is. - void ShowRect(m2::RectD const & rect); + + /// Set navigator viewport by rect as-is (rect should be in screen viewport). + void ShowRect(m2::RectD rect); + /// - Use navigator rotate angle. - /// - Check for fixed scales from navigator. - void ShowRectEx(m2::RectD const & rect); + /// - Check for fixed scales (rect scale matched on draw tile scale). + void ShowRectEx(m2::RectD rect); /// - Check minimal visible scale according to downloaded countries. void ShowRectExVisibleScale(m2::RectD rect, int maxScale = -1);