From d22fe4596ea66423a7dd667c6c4d2671095841c1 Mon Sep 17 00:00:00 2001 From: mhugent Date: Wed, 26 Jan 2011 16:43:09 +0000 Subject: [PATCH] Prevent rounding error if point is on segment. Fixes bug #2921 git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@15087 c8812cc2-4d05-0410-92ff-de0c093fc19c --- src/core/qgspoint.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/core/qgspoint.cpp b/src/core/qgspoint.cpp index b07e1dfc63c9..4c17cb46bc29 100644 --- a/src/core/qgspoint.cpp +++ b/src/core/qgspoint.cpp @@ -18,6 +18,7 @@ #include "qgspoint.h" +#include "qgis.h" #include #include #include // for tr() @@ -272,5 +273,13 @@ double QgsPoint::sqrDistToSegment( double x1, double y1, double x2, double y2, Q minDistPoint.setY( y1 + t *( y2 - y1 ) ); } - return ( sqrDist( minDistPoint ) ); + double dist = sqrDist( minDistPoint ); + //prevent rounding errors if the point is directly on the segment + if ( doubleNear( dist, 0.0 ) ) + { + minDistPoint.setX( m_x ); + minDistPoint.setY( m_y ); + return 0.0; + } + return dist; }