forked from organicmaps/organicmaps
added selectOverlayElements by Rect
This commit is contained in:
parent
2d54dda155
commit
eae2259f62
2 changed files with 40 additions and 3 deletions
|
@ -153,12 +153,12 @@ namespace yg
|
|||
m_tree.Add(oe);
|
||||
}
|
||||
|
||||
struct DoPreciseSelect
|
||||
struct DoPreciseSelectByPoint
|
||||
{
|
||||
m2::PointD m_pt;
|
||||
list<shared_ptr<OverlayElement> > * m_elements;
|
||||
|
||||
DoPreciseSelect(m2::PointD const & pt, list<shared_ptr<OverlayElement> > * elements)
|
||||
DoPreciseSelectByPoint(m2::PointD const & pt, list<shared_ptr<OverlayElement> > * elements)
|
||||
: m_pt(pt), m_elements(elements)
|
||||
{}
|
||||
|
||||
|
@ -169,6 +169,36 @@ namespace yg
|
|||
}
|
||||
};
|
||||
|
||||
struct DoPreciseSelectByRect
|
||||
{
|
||||
m2::AnyRectD m_rect;
|
||||
list<shared_ptr<OverlayElement> > * m_elements;
|
||||
|
||||
DoPreciseSelectByRect(m2::RectD const & rect,
|
||||
list<shared_ptr<OverlayElement> > * elements)
|
||||
: m_rect(rect),
|
||||
m_elements(elements)
|
||||
{}
|
||||
|
||||
void operator()(shared_ptr<OverlayElement> const & e)
|
||||
{
|
||||
vector<m2::AnyRectD> const & rects = e->boundRects();
|
||||
|
||||
for (vector<m2::AnyRectD>::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<OverlayElement> m_oe;
|
||||
|
@ -199,9 +229,15 @@ namespace yg
|
|||
}
|
||||
};
|
||||
|
||||
void Overlay::selectOverlayElements(m2::RectD const & rect, list<shared_ptr<OverlayElement> > & res)
|
||||
{
|
||||
DoPreciseSelectByRect fn(rect, &res);
|
||||
m_tree.ForEachInRect(rect, fn);
|
||||
}
|
||||
|
||||
void Overlay::selectOverlayElements(m2::PointD const & pt, list<shared_ptr<OverlayElement> > & 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);
|
||||
}
|
||||
|
||||
|
|
|
@ -38,6 +38,7 @@ namespace yg
|
|||
void draw(gl::OverlayRenderer * r, math::Matrix<double, 3, 3> const & m);
|
||||
|
||||
void selectOverlayElements(m2::PointD const & pt, list<shared_ptr<OverlayElement> > & res);
|
||||
void selectOverlayElements(m2::RectD const & rect, list<shared_ptr<OverlayElement> > & res);
|
||||
|
||||
void removeOverlayElement(shared_ptr<OverlayElement> const & oe, m2::RectD const & r);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue