Skip to content

Commit

Permalink
modification of snapPoint
Browse files Browse the repository at this point in the history
  • Loading branch information
leyan committed Mar 22, 2014
1 parent 1088c26 commit ff18324
Showing 1 changed file with 22 additions and 8 deletions.
30 changes: 22 additions & 8 deletions src/core/qgssnapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ int QgsSnapper::snapPoint( const QPoint& startPoint, QList<QgsSnappingResult>& s
if ( !snapLayerIt->mLayer->hasGeometryType() )
continue;

currentResultList.clear();
//transform point from map coordinates to layer coordinates
layerCoordPoint = mMapSettings.mapToLayerCoordinates( snapLayerIt->mLayer, mapCoordPoint );

Expand Down Expand Up @@ -93,31 +94,44 @@ int QgsSnapper::snapPoint( const QPoint& startPoint, QList<QgsSnappingResult>& s
return 0;
}


//Gives a priority to vertex snapping over segment snapping
QgsSnappingResult returnResult = evalIt.value();
for ( evalIt = snappingResultList.begin(); evalIt != snappingResultList.end(); ++evalIt )
{
if( evalIt.value().snappedVertexNr != -1 )
{
returnResult = evalIt.value();
snappingResultList.erase( evalIt );
break;
}
}

//We return the preferred result
snappingResult.push_back( returnResult );

if ( mSnapMode == QgsSnapper::SnapWithOneResult )
{
//return only closest result
snappingResult.push_back( evalIt.value() );
//return only a single result, nothing more to do
}
else if ( mSnapMode == QgsSnapper::SnapWithResultsForSamePosition )
{
//take all snapping Results within a certain tolerance because rounding differences may occur
//take all snapping results within a certain tolerance because rounding differences may occur
double tolerance = 0.000001;
double minDistance = evalIt.key();

for ( evalIt = snappingResultList.begin(); evalIt != snappingResultList.end(); ++evalIt )
{
if ( evalIt.key() > ( minDistance + tolerance ) )
if ( returnResult.snappedVertex.sqrDist( evalIt.value().snappedVertex ) < tolerance*tolerance )
{
break;
snappingResult.push_back( evalIt.value() );
}
snappingResult.push_back( evalIt.value() );
}

}

else //take all results
{
for ( ; evalIt != snappingResultList.end(); ++evalIt )
for ( evalIt = snappingResultList.begin(); evalIt != snappingResultList.end(); ++evalIt )
{
snappingResult.push_back( evalIt.value() );
}
Expand Down

0 comments on commit ff18324

Please sign in to comment.