Skip to content
Permalink
Browse files

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
  • Loading branch information
mhugent
mhugent committed Jan 26, 2011
1 parent e88c990 commit 8e84137ae8c4b8659161f2af2bcb6669dec312d4
Showing with 10 additions and 1 deletion.
  1. +10 −1 src/core/qgspoint.cpp
@@ -18,6 +18,7 @@


#include "qgspoint.h"
#include "qgis.h"
#include <cmath>
#include <QTextStream>
#include <QObject> // 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;
}

0 comments on commit 8e84137

Please sign in to comment.
You can’t perform that action at this time.