Correct Framework::ShowRect with minimal possible rect.

This commit is contained in:
vng 2011-06-12 02:54:23 +03:00 committed by Alex Zolotarev
parent 4f146a7170
commit 2ac332749e
3 changed files with 25 additions and 13 deletions

View file

@ -133,8 +133,8 @@ namespace m2
bool IsRectInside(Rect<T> const & rect) const
{
return (IsPointInside(Point<T>(rect.minX(), rect.minY()))
&& IsPointInside(Point<T>(rect.maxX(), rect.maxY())));
return (IsPointInside(Point<T>(rect.minX(), rect.minY())) &&
IsPointInside(Point<T>(rect.maxX(), rect.maxY())));
}
Point<T> Center() const { return Point<T>((m_minX + m_maxX) / 2.0, (m_minY + m_maxY) / 2.0); }
@ -157,6 +157,21 @@ namespace m2
}
}
void SetSizes(T dx, T dy)
{
ASSERT_GREATER ( dx, 0, () );
ASSERT_GREATER ( dy, 0, () );
dx /= 2;
dy /= 2;
Point<T> const c = Center();
m_minX = c.x - dx;
m_minY = c.y - dy;
m_maxX = c.x + dx;
m_maxY = c.y + dy;
}
T minX() const { return m_minX; }
T minY() const { return m_minY; }
T maxX() const { return m_maxX; }

View file

@ -856,17 +856,14 @@ void FrameWork<TModel>::AddRedrawCommandSure()
}
template <typename TModel>
void FrameWork<TModel>::ShowRect(m2::RectD const & rect)
void FrameWork<TModel>::ShowRect(m2::RectD rect)
{
m2::RectD r(rect);
if (my::AlmostEqual(rect.minX(), rect.maxX())
|| my::AlmostEqual(rect.minY(), rect.maxY()))
{
double const minWidthX = MercatorBounds::ConvertMetresToX(rect.minX(), 6 * m_metresMinWidth);
double const minWidthY = MercatorBounds::ConvertMetresToY(rect.minY(), 6 * m_metresMinWidth);
r.Inflate(minWidthX, minWidthY);
}
m_navigator.SetFromRect(r);
double const minSizeX = MercatorBounds::ConvertMetresToX(rect.minX(), 6 * m_metresMinWidth);
double const minSizeY = MercatorBounds::ConvertMetresToY(rect.minY(), 6 * m_metresMinWidth);
if (rect.SizeX() < minSizeX && rect.SizeY() < minSizeY)
rect.SetSizes(minSizeX, minSizeY);
m_navigator.SetFromRect(rect);
UpdateNow();
}

View file

@ -262,7 +262,7 @@ public:
void CenterViewport(m2::PointD const & pt);
void ShowRect(m2::RectD const & rect);
void ShowRect(m2::RectD rect);
void MemoryWarning();