Skip to content
Permalink
Browse files

fix circularstring and add tests

  • Loading branch information
lbartoletti committed Aug 24, 2020
1 parent 6981c0a commit 56b603ac38f319d83559b597d8ad991c0726590a
Showing with 21 additions and 1 deletion.
  1. +5 −1 src/core/geometry/qgscircularstring.cpp
  2. +16 −0 tests/src/core/testqgsgeometry.cpp
@@ -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;
}

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.
You can’t perform that action at this time.