Skip to content

Commit

Permalink
fix circularstring and add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lbartoletti committed Aug 24, 2020
1 parent 6981c0a commit 56b603a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/core/geometry/qgscircularstring.cpp
Expand Up @@ -320,7 +320,11 @@ bool QgsCircularString::fromWkt( const QString &wkt )
if ( parts.second.compare( QLatin1String( "NULL" ), Qt::CaseInsensitive ) == 0 )
return false;

setPoints( QgsGeometryUtils::pointsFromWKT( parts.second, is3D(), isMeasure() ) );
QgsPointSequence points = QgsGeometryUtils::pointsFromWKT( parts.second, is3D(), isMeasure() );
if ( points.isEmpty() )
return false;

setPoints( points );
return true;
}

Expand Down
16 changes: 16 additions & 0 deletions tests/src/core/testqgsgeometry.cpp
Expand Up @@ -18178,6 +18178,22 @@ void TestQgsGeometry::wktParser()
QCOMPARE( poly.asWkt(), QStringLiteral( "Polygon ((0 1, 2 3, 3 4, 0 1))" ) );
QVERIFY( poly.fromWkt( "Polygon((0 1e3, -2 3, +3 4, 0 1))" ) );
QCOMPARE( poly.asWkt(), QStringLiteral( "Polygon ((0 1000, -2 3, 3 4, 0 1))" ) );

// Circular string
// unbalanced parenthesis
QVERIFY( ! QgsCircularString().fromWkt( "CircularString(0 1, 1 2, 3 3) )" ) );
QVERIFY( ! QgsCircularString().fromWkt( "CircularString (0 1, 1 2, 3 3) )" ) );
QVERIFY( ! QgsCircularString().fromWkt( "CircularString( (0 1, 1 2, 3 3) )) " ) );
QVERIFY( ! QgsCircularString().fromWkt( "CircularString ( (0 1, 1 2, 3 3) )) " ) );
// not a number
QVERIFY( ! QgsCircularString().fromWkt( "CircularString (0 a, b 2, 3 3) " ) );
QVERIFY( ! QgsCircularString().fromWkt( "CircularString (0 a, b 2, 3 3, 0 a) " ) );
// valid
QgsCircularString c;
QVERIFY( c.fromWkt( "CircularString( 0 1, 2 3, 3 4)" ) );
QCOMPARE( c.asWkt(), QStringLiteral( "CircularString (0 1, 2 3, 3 4)" ) );
QVERIFY( c.fromWkt( "CircularString(0 1e3, -2 3, +3 4)" ) );
QCOMPARE( c.asWkt(), QStringLiteral( "CircularString (0 1000, -2 3, 3 4)" ) );
}
QGSTEST_MAIN( TestQgsGeometry )
#include "testqgsgeometry.moc"

0 comments on commit 56b603a

Please sign in to comment.