Skip to content

Commit

Permalink
fix duplicate point at the beginning of a digitized curve #39974
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] authored and nyalldawson committed Nov 18, 2020
1 parent 61a2f92 commit 0bc0caf
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
3 changes: 3 additions & 0 deletions src/gui/qgsmaptoolcapture.cpp
Expand Up @@ -651,6 +651,9 @@ int QgsMapToolCapture::addCurve( QgsCurve *c )
c->transform( ct, QgsCoordinateTransform::ReverseTransform );
}
int countBefore = mCaptureCurve.vertexCount();
//if there is only one point, this the first digitized point that are in the this first curve added --> remove the point
if ( mCaptureCurve.numPoints() == 1 )
mCaptureCurve.removeCurve( 0 );
mCaptureCurve.addCurve( c );
int countAfter = mCaptureCurve.vertexCount();
int addedPoint = countAfter - countBefore;
Expand Down
13 changes: 10 additions & 3 deletions tests/src/app/testqgsmaptooladdfeatureline.cpp
Expand Up @@ -289,7 +289,7 @@ void TestQgsMapToolAddFeatureLine::testNoTracing()
utils.mouseClick( 3, 2, Qt::LeftButton );
utils.mouseClick( 3, 2, Qt::RightButton );

// Cirular string need 3 points, so no feature created
// Circular string need 3 points, so no feature created
QCOMPARE( mLayerLine->undoStack()->index(), 1 );
QCOMPARE( utils.existingFeatureIds().count(), 1 );

Expand All @@ -298,13 +298,20 @@ void TestQgsMapToolAddFeatureLine::testNoTracing()
utils.mouseClick( 3, 2, Qt::LeftButton );
utils.mouseMove( 5, 5 );
utils.mouseClick( 4, 2, Qt::LeftButton );

mCaptureTool->setCircularDigitizingEnabled( false );

utils.mouseMove( 5, 5 );
utils.mouseClick( 4, 3, Qt::LeftButton );

utils.mouseMove( 5, 5 );
utils.mouseClick( 4, 2, Qt::RightButton );
utils.mouseClick( 4, 4, Qt::RightButton );

newFid = utils.newFeatureId( oldFids );

QCOMPARE( mLayerLine->undoStack()->index(), 2 );
QCOMPARE( mLayerLine->getFeature( newFid ).geometry(), QgsGeometry::fromWkt( "CIRCULARSTRING(1 1, 3 2, 4 2)" ) );
// as here, QCOMPARE with QgsGeometry uses isGeosEqual() and geos does not support curve (need to convert curve to line string), test with wkt string
QCOMPARE( mLayerLine->getFeature( newFid ).geometry().asWkt(), QStringLiteral( "CompoundCurve (CircularString (1 1, 3 2, 4 2),(4 2, 4 3))" ) ) ;

mLayerLine->undoStack()->undo();
QCOMPARE( mLayerLine->undoStack()->index(), 1 );
Expand Down

0 comments on commit 0bc0caf

Please sign in to comment.