Skip to content

Commit

Permalink
[Geometry snapper] Don't delete vertices if this would result in a de…
Browse files Browse the repository at this point in the history
…generate geometry
  • Loading branch information
manisandro committed Jul 13, 2016
1 parent 258c899 commit d5869cf
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/plugins/geometry_snapper/qgsgeometrysnapper.cpp
Expand Up @@ -206,6 +206,7 @@ void QgsGeometrySnapper::processFeature( QgsFeatureId id )
{
for ( int iRing = 0, nRings = subjGeom->ringCount( iPart ); iRing < nRings; ++iRing )
{
bool ringIsClosed = subjGeom->vertexAt( QgsVertexId( iPart, iRing, 0 ) ) == subjGeom->vertexAt( QgsVertexId( iPart, iRing, subjGeom->vertexCount( iPart, iRing ) - 1 ) );
for ( int iVert = 0, nVerts = polyLineSize( subjGeom, iPart, iRing ); iVert < nVerts; ++iVert )
{
int iPrev = ( iVert - 1 + nVerts ) % nVerts;
Expand All @@ -219,10 +220,18 @@ void QgsGeometrySnapper::processFeature( QgsFeatureId id )
subjPointFlags[iPart][iRing][iNext] != Unsnapped &&
QgsGeometryUtils::sqrDistance2D( QgsGeometryUtils::projPointOnSegment( pMid, pPrev, pNext ), pMid ) < 1E-12 )
{
subjGeom->deleteVertex( QgsVertexId( iPart, iRing, iVert ) );
subjPointFlags[iPart][iRing].removeAt( iVert );
iVert -= 1;
nVerts -= 1;
if (( ringIsClosed && nVerts > 3 ) || ( !ringIsClosed && nVerts > 2 ) )
{
subjGeom->deleteVertex( QgsVertexId( iPart, iRing, iVert ) );
subjPointFlags[iPart][iRing].removeAt( iVert );
iVert -= 1;
nVerts -= 1;
}
else
{
// Don't delete vertices if this would result in a degenerate geometry
break;
}
}
}
}
Expand Down

0 comments on commit d5869cf

Please sign in to comment.