Skip to content
Permalink
Browse files

modification of snapPoint

  • Loading branch information
leyan committed Mar 22, 2014
1 parent 1088c26 commit ff183245841f56221c7aea85f3f7a27d763a7dc7
Showing with 22 additions and 8 deletions.
  1. +22 −8 src/core/qgssnapper.cpp
@@ -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 );

@@ -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() );
}

0 comments on commit ff18324

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