Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Test addTopologicalPoints results
  • Loading branch information
gacarrillor committed Jul 5, 2021
1 parent 966ac4c commit aeece71
Showing 1 changed file with 24 additions and 7 deletions.
31 changes: 24 additions & 7 deletions tests/src/core/testqgsvectorlayer.cpp
Expand Up @@ -334,7 +334,7 @@ void TestQgsVectorLayer::testAddTopologicalPoints()
QVERIFY( layerLine->isValid() );

QgsPolylineXY line1;
line1 << QgsPointXY( 2, 1 ) << QgsPointXY( 1, 1 ) << QgsPointXY( 1, 3 );
line1 << QgsPointXY( 2, 1 ) << QgsPointXY( 1, 1 ) << QgsPointXY( 1, 5 );
QgsFeature lineF1;
lineF1.setGeometry( QgsGeometry::fromPolylineXY( line1 ) );

Expand All @@ -346,22 +346,39 @@ void TestQgsVectorLayer::testAddTopologicalPoints()
QCOMPARE( layerLine->undoStack()->index(), 1 );

// outside of the linestring - nothing should happen
layerLine->addTopologicalPoints( QgsPoint( 2, 2 ) );
int result = layerLine->addTopologicalPoints( QgsPoint( 2, 2 ) );
QCOMPARE( result, 2 );

QCOMPARE( layerLine->undoStack()->index(), 1 );
QCOMPARE( layerLine->getFeature( fidLineF1 ).geometry().asWkt(), QgsGeometry::fromWkt( "LINESTRING(2 1, 1 1, 1 3)" ).asWkt() );
QCOMPARE( layerLine->getFeature( fidLineF1 ).geometry().asWkt(), QgsGeometry::fromWkt( "LINESTRING(2 1, 1 1, 1 5)" ).asWkt() );

// add point at an existing vertex
layerLine->addTopologicalPoints( QgsPoint( 1, 1 ) );
result = layerLine->addTopologicalPoints( QgsPoint( 1, 1 ) );
QCOMPARE( result, 2 );

QCOMPARE( layerLine->undoStack()->index(), 1 );
QCOMPARE( layerLine->getFeature( fidLineF1 ).geometry().asWkt(), QgsGeometry::fromWkt( "LINESTRING(2 1, 1 1, 1 3)" ).asWkt() );
QCOMPARE( layerLine->getFeature( fidLineF1 ).geometry().asWkt(), QgsGeometry::fromWkt( "LINESTRING(2 1, 1 1, 1 5)" ).asWkt() );

// add point on segment of linestring
layerLine->addTopologicalPoints( QgsPoint( 1, 2 ) );
result = layerLine->addTopologicalPoints( QgsPoint( 1, 2 ) );
QCOMPARE( result, 0 );

QCOMPARE( layerLine->undoStack()->index(), 2 );
QCOMPARE( layerLine->getFeature( fidLineF1 ).geometry().asWkt(), QgsGeometry::fromWkt( "LINESTRING(2 1, 1 1, 1 2, 1 3)" ).asWkt() );
QCOMPARE( layerLine->getFeature( fidLineF1 ).geometry().asWkt(), QgsGeometry::fromWkt( "LINESTRING(2 1, 1 1, 1 2, 1 5)" ).asWkt() );

// add points from disjoint geometry - nothing should happen
result = layerLine->addTopologicalPoints( QgsGeometry::fromWkt( "LINESTRING(2 0, 2 1, 2 2)" ) );
QCOMPARE( result, 2 );

QCOMPARE( layerLine->undoStack()->index(), 2 );
QCOMPARE( layerLine->getFeature( fidLineF1 ).geometry().asWkt(), QgsGeometry::fromWkt( "LINESTRING(2 1, 1 1, 1 2, 1 5)" ).asWkt() );

// add 2 out of 3 points from intersecting geometry
result = layerLine->addTopologicalPoints( QgsGeometry::fromWkt( "LINESTRING(2 0, 2 1, 2 3, 1 3, 0 3, 0 4, 1 4)" ) );
QCOMPARE( result, 0 );

QCOMPARE( layerLine->undoStack()->index(), 2 );
QCOMPARE( layerLine->getFeature( fidLineF1 ).geometry().asWkt(), QgsGeometry::fromWkt( "LINESTRING(2 1, 1 1, 1 2, 1 3, 1 4, 1 5)" ).asWkt() );

delete layerLine;
}
Expand Down

0 comments on commit aeece71

Please sign in to comment.