From d98eb516f467da6e67c00aa5d75f61d7d92f2b54 Mon Sep 17 00:00:00 2001 From: Tats Date: Sat, 3 May 2014 13:29:30 -0400 Subject: [PATCH] Use method distSq and MM:: definitions for vertex selection. --- MapperGLCanvas.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/MapperGLCanvas.cpp b/MapperGLCanvas.cpp index 822ab2e..1175fe1 100644 --- a/MapperGLCanvas.cpp +++ b/MapperGLCanvas.cpp @@ -89,7 +89,9 @@ void MapperGLCanvas::mousePressEvent(QMouseEvent* event) int i, dist, maxdist, mindist; int xmouse = event->x(); int ymouse = event->y(); - maxdist = mindist = 50; + const QPointF& mousePos = event->posF(); + // Note: we compare with the square value for fastest computation of the distance + maxdist = mindist = MM::VERTEX_SELECT_RADIUS * MM::VERTEX_SELECT_RADIUS; if (event->buttons() & Qt::LeftButton) { Shape* shape = getCurrentShape(); @@ -97,8 +99,7 @@ void MapperGLCanvas::mousePressEvent(QMouseEvent* event) { for (i = 0; i < shape->nVertices(); i++) { - const QPointF& p = shape->getVertex(i); - dist = qAbs(xmouse - p.x()) + qAbs(ymouse - p.y()); + dist = distSq(mousePos, shape->getVertex(i)); // squared distance if (dist < maxdist && dist < mindist) { _active_vertex = i;