Skip to content

Commit

Permalink
Prevent rounding error if point is on segment. Fixes bug #2921
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@15087 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mhugent committed Jan 26, 2011
1 parent b0f064c commit d22fe45
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/core/qgspoint.cpp
Expand Up @@ -18,6 +18,7 @@


#include "qgspoint.h"
#include "qgis.h"
#include <cmath>
#include <QTextStream>
#include <QObject> // for tr()
Expand Down Expand Up @@ -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 d22fe45

Please sign in to comment.