Skip to content
Permalink
Browse files

[Geometry snapper] Don't delete vertices if this would result in a de…

…generate geometry
  • Loading branch information
manisandro committed Jul 13, 2016
1 parent 258c899 commit d5869cf5d17fe8a0a5aab3cb8af335dc7d9b1a1e
Showing with 13 additions and 4 deletions.
  1. +13 −4 src/plugins/geometry_snapper/qgsgeometrysnapper.cpp
@@ -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;
@@ -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;
}
}
}
}

0 comments on commit d5869cf

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