aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSamuel Fadel <samuelfadel@gmail.com>2016-01-27 18:08:06 +0100
committerSamuel Fadel <samuelfadel@gmail.com>2016-01-27 18:08:06 +0100
commit6d075f34ef264f257288748b2d57c9950ae0888d (patch)
tree345962c8937d0cb0f28f3bfb937f4b6ec0461f2c
parentc4a5ebf02bf014b58df272007d18a2a3b9253e88 (diff)
Scatterplot: reduced search space for brushing.
-rw-r--r--scatterplot.cpp39
1 files changed, 20 insertions, 19 deletions
diff --git a/scatterplot.cpp b/scatterplot.cpp
index fe65384..f10f1b4 100644
--- a/scatterplot.cpp
+++ b/scatterplot.cpp
@@ -121,19 +121,26 @@ bool QuadTree::insert(float x, float y, int value)
int QuadTree::nearestTo(float x, float y) const
{
- if (!m_nw) {
- return m_value;
+ if (!m_bounds.contains(x, y)) {
+ return -1;
}
- int nearest = -1;
- float dist = 1.0f / 0.0f;
- m_nw->nearestTo(x, y, nearest, dist);
- m_ne->nearestTo(x, y, nearest, dist);
- m_sw->nearestTo(x, y, nearest, dist);
- m_se->nearestTo(x, y, nearest, dist);
- if (dist < BRUSHING_MAX_DIST)
- return nearest;
+ int q;
+ if (m_nw) {
+ q = m_nw->nearestTo(x, y);
+ if (q >= 0) return q;
+ q = m_ne->nearestTo(x, y);
+ if (q >= 0) return q;
+ q = m_sw->nearestTo(x, y);
+ if (q >= 0) return q;
+ q = m_se->nearestTo(x, y);
+ if (q >= 0) return q;
+ }
+ float dist = 1.0f / 0.0f;
+ nearestTo(x, y, q, dist);
+ if (dist < BRUSHING_MAX_DIST * BRUSHING_MAX_DIST)
+ return q;
return -1;
}
@@ -144,7 +151,7 @@ void QuadTree::nearestTo(float x, float y, int &nearest, float &dist) const
m_ne->nearestTo(x, y, nearest, dist);
m_sw->nearestTo(x, y, nearest, dist);
m_se->nearestTo(x, y, nearest, dist);
- } else {
+ } else if (m_value >= 0) {
float d = (m_x - x)*(m_x - x) + (m_y - y)*(m_y - y);
if (d < dist) {
nearest = m_value;
@@ -617,10 +624,7 @@ void Scatterplot::mouseReleaseEvent(QMouseEvent *event)
void Scatterplot::hoverEnterEvent(QHoverEvent *event)
{
QPointF pos = event->posF();
- int item = m_quadtree->query(pos.x(), pos.y());
- m_brushedItem = item < 0
- ? m_quadtree->nearestTo(pos.x(), pos.y())
- : item;
+ m_brushedItem = m_quadtree->nearestTo(pos.x(), pos.y());
emit itemInteractivelyBrushed(m_brushedItem);
update();
@@ -629,10 +633,7 @@ void Scatterplot::hoverEnterEvent(QHoverEvent *event)
void Scatterplot::hoverMoveEvent(QHoverEvent *event)
{
QPointF pos = event->posF();
- int item = m_quadtree->query(pos.x(), pos.y());
- m_brushedItem = item < 0
- ? m_quadtree->nearestTo(pos.x(), pos.y())
- : item;
+ m_brushedItem = m_quadtree->nearestTo(pos.x(), pos.y());
emit itemInteractivelyBrushed(m_brushedItem);
update();