Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Compare square distance with square tolerance in duplicated node check
  • Loading branch information
mhugent authored and github-actions[bot] committed Nov 2, 2021
1 parent 93fc612 commit 8c66a35
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
Expand Up @@ -25,6 +25,8 @@ void QgsGeometryDuplicateNodesCheck::collectErrors( const QMap<QString, QgsFeatu

const QMap<QString, QgsFeatureIds> featureIds = ids.isEmpty() ? allLayerFeatureIds( featurePools ) : ids.toMap();
const QgsGeometryCheckerUtils::LayerFeatures layerFeatures( featurePools, featureIds, compatibleGeometryTypes(), feedback, mContext );
const double sqrTolerance = mContext->tolerance * mContext->tolerance;

for ( const QgsGeometryCheckerUtils::LayerFeature &layerFeature : layerFeatures )
{
const QgsAbstractGeometry *geom = layerFeature.geometry().constGet();
Expand All @@ -39,7 +41,7 @@ void QgsGeometryDuplicateNodesCheck::collectErrors( const QMap<QString, QgsFeatu
{
const QgsPoint pi = geom->vertexAt( QgsVertexId( iPart, iRing, iVert ) );
const QgsPoint pj = geom->vertexAt( QgsVertexId( iPart, iRing, jVert ) );
if ( QgsGeometryUtils::sqrDistance2D( pi, pj ) < mContext->tolerance )
if ( QgsGeometryUtils::sqrDistance2D( pi, pj ) < sqrTolerance )
{
errors.append( new QgsGeometryCheckError( this, layerFeature, pj, QgsVertexId( iPart, iRing, jVert ) ) );
}
Expand Down
22 changes: 22 additions & 0 deletions tests/src/geometry_checker/testqgsgeometrychecks.cpp
Expand Up @@ -83,6 +83,7 @@ class TestQgsGeometryChecks: public QObject
void testDegeneratePolygonCheck();
void testDuplicateCheck();
void testDuplicateNodesCheck();
void testDuplicateNodesCheckTolerance();
void testFollowBoundariesCheck();
void testGapCheck();
void testAllowedGaps();
Expand Down Expand Up @@ -490,6 +491,27 @@ void TestQgsGeometryChecks::testDuplicateNodesCheck()
cleanupTestContext( testContext );
}

void TestQgsGeometryChecks::testDuplicateNodesCheckTolerance()
{
QTemporaryDir dir;
QMap<QString, QString> layers;
layers.insert( "line_layer.shp", "" );
auto testContext = createTestContext( dir, layers, QgsCoordinateReferenceSystem( "EPSG:4326" ), 3 );

QList<QgsGeometryCheckError *> checkErrors;
QStringList messages;
QgsFeedback feedback;

const QgsGeometryDuplicateNodesCheck check( testContext.first, QVariantMap() );
check.collectErrors( testContext.second, checkErrors, messages, &feedback );
listErrors( checkErrors, messages );

int nErrors = checkErrors.size();
QCOMPARE( nErrors, 3 );

cleanupTestContext( testContext );
}

void TestQgsGeometryChecks::testFollowBoundariesCheck()
{
QTemporaryDir dir;
Expand Down

0 comments on commit 8c66a35

Please sign in to comment.