Skip to content

Commit 8e84137

Browse files
author
mhugent
committed
Prevent rounding error if point is on segment. Fixes bug #2921
git-svn-id: http://svn.osgeo.org/qgis/trunk@15087 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent e88c990 commit 8e84137

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/core/qgspoint.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919

2020
#include "qgspoint.h"
21+
#include "qgis.h"
2122
#include <cmath>
2223
#include <QTextStream>
2324
#include <QObject> // for tr()
@@ -272,5 +273,13 @@ double QgsPoint::sqrDistToSegment( double x1, double y1, double x2, double y2, Q
272273
minDistPoint.setY( y1 + t *( y2 - y1 ) );
273274
}
274275

275-
return ( sqrDist( minDistPoint ) );
276+
double dist = sqrDist( minDistPoint );
277+
//prevent rounding errors if the point is directly on the segment
278+
if ( doubleNear( dist, 0.0 ) )
279+
{
280+
minDistPoint.setX( m_x );
281+
minDistPoint.setY( m_y );
282+
return 0.0;
283+
}
284+
return dist;
276285
}

0 commit comments

Comments
 (0)