[QGIS Commit] r15087 - trunk/qgis/src/core

svn_qgis at osgeo.org svn_qgis at osgeo.org
Wed Jan 26 11:43:09 EST 2011


Author: mhugent
Date: 2011-01-26 08:43:09 -0800 (Wed, 26 Jan 2011)
New Revision: 15087

Modified:
   trunk/qgis/src/core/qgspoint.cpp
Log:
Prevent rounding error if point is on segment. Fixes bug #2921

Modified: trunk/qgis/src/core/qgspoint.cpp
===================================================================
--- trunk/qgis/src/core/qgspoint.cpp	2011-01-26 13:49:53 UTC (rev 15086)
+++ trunk/qgis/src/core/qgspoint.cpp	2011-01-26 16:43:09 UTC (rev 15087)
@@ -18,6 +18,7 @@
 
 
 #include "qgspoint.h"
+#include "qgis.h"
 #include <cmath>
 #include <QTextStream>
 #include <QObject> // for tr()
@@ -272,5 +273,13 @@
     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;
 }



More information about the QGIS-commit mailing list