From f3f4c50b2e2f5cb7cade5601c8fa33dd405f0614 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Germ=C3=A1n=20Carrillo?= Date: Mon, 28 Jun 2021 22:12:07 -0500 Subject: [PATCH] Test addTopologicalPoints results --- tests/src/core/testqgsvectorlayer.cpp | 31 +++++++++++++++++++++------ 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/tests/src/core/testqgsvectorlayer.cpp b/tests/src/core/testqgsvectorlayer.cpp index 74d89cddc213..32e11c1d3b12 100644 --- a/tests/src/core/testqgsvectorlayer.cpp +++ b/tests/src/core/testqgsvectorlayer.cpp @@ -350,7 +350,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 ) ); @@ -362,22 +362,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; }