From eae2259f620f03e598b99ac1f07629ea4debddb2 Mon Sep 17 00:00:00 2001 From: rachytski Date: Wed, 19 Sep 2012 17:40:17 +0300 Subject: [PATCH] added selectOverlayElements by Rect --- yg/overlay.cpp | 42 +++++++++++++++++++++++++++++++++++++++--- yg/overlay.hpp | 1 + 2 files changed, 40 insertions(+), 3 deletions(-) diff --git a/yg/overlay.cpp b/yg/overlay.cpp index da49510e5d..a80f56937a 100644 --- a/yg/overlay.cpp +++ b/yg/overlay.cpp @@ -153,12 +153,12 @@ namespace yg m_tree.Add(oe); } - struct DoPreciseSelect + struct DoPreciseSelectByPoint { m2::PointD m_pt; list > * m_elements; - DoPreciseSelect(m2::PointD const & pt, list > * elements) + DoPreciseSelectByPoint(m2::PointD const & pt, list > * elements) : m_pt(pt), m_elements(elements) {} @@ -169,6 +169,36 @@ namespace yg } }; + struct DoPreciseSelectByRect + { + m2::AnyRectD m_rect; + list > * m_elements; + + DoPreciseSelectByRect(m2::RectD const & rect, + list > * elements) + : m_rect(rect), + m_elements(elements) + {} + + void operator()(shared_ptr const & e) + { + vector const & rects = e->boundRects(); + + for (vector::const_iterator it = rects.begin(); + it != rects.end(); + ++it) + { + m2::AnyRectD const & rect = *it; + + if (m_rect.IsIntersect(rect)) + { + m_elements->push_back(e); + break; + } + } + } + }; + struct DoPreciseIntersect { shared_ptr m_oe; @@ -199,9 +229,15 @@ namespace yg } }; + void Overlay::selectOverlayElements(m2::RectD const & rect, list > & res) + { + DoPreciseSelectByRect fn(rect, &res); + m_tree.ForEachInRect(rect, fn); + } + void Overlay::selectOverlayElements(m2::PointD const & pt, list > & res) { - DoPreciseSelect fn(pt, &res); + DoPreciseSelectByPoint fn(pt, &res); m_tree.ForEachInRect(m2::RectD(pt - m2::PointD(1, 1), pt + m2::PointD(1, 1)), fn); } diff --git a/yg/overlay.hpp b/yg/overlay.hpp index 987da747dc..446750805b 100644 --- a/yg/overlay.hpp +++ b/yg/overlay.hpp @@ -38,6 +38,7 @@ namespace yg void draw(gl::OverlayRenderer * r, math::Matrix const & m); void selectOverlayElements(m2::PointD const & pt, list > & res); + void selectOverlayElements(m2::RectD const & rect, list > & res); void removeOverlayElement(shared_ptr const & oe, m2::RectD const & r);