|
@@ -151,6 +151,7 @@ class TestQgsGeometry : public QObject |
|
|
|
|
|
void makeValid(); |
|
|
|
|
|
void isSimple_data(); |
|
|
void isSimple(); |
|
|
|
|
|
void reshapeGeometryLineMerge(); |
|
|
|
|
} |
|
|
} |
|
|
|
|
|
void TestQgsGeometry::isSimple_data() |
|
|
{ |
|
|
QTest::addColumn<QString>( "wkt" ); |
|
|
QTest::addColumn<bool>( "simple" ); |
|
|
|
|
|
QTest::newRow( "linestring" ) << QStringLiteral( "LINESTRING(0 0, 1 0, 1 1)" ) << true; |
|
|
QTest::newRow( "may be closed (linear ring)" ) << QStringLiteral( "LINESTRING(0 0, 1 0, 1 1, 0 0)" ) << true; |
|
|
QTest::newRow( "self-intersection" ) << QStringLiteral( "LINESTRING(0 0, 1 0, 1 1, 0 -1)" ) << false; |
|
|
QTest::newRow( "self-tangency" ) << QStringLiteral( "LINESTRING(0 0, 1 0, 1 1, 0.5 0, 0 1)" ) << false; |
|
|
QTest::newRow( "points are simple" ) << QStringLiteral( "POINT(1 1)" ) << true; |
|
|
QTest::newRow( "polygons are always simple, even if they are invalid" ) << QStringLiteral( "POLYGON((0 0, 1 1, 1 1, 0 0))" ) << true; |
|
|
QTest::newRow( "multipoint" ) << QStringLiteral( "MULTIPOINT((1 1), (2 2))" ) << true; |
|
|
QTest::newRow( "must not contain the same point twice" ) << QStringLiteral( "MULTIPOINT((1 1), (1 1))" ) << false; |
|
|
QTest::newRow( "multiline string simple" ) << QStringLiteral( "MULTILINESTRING((0 0, 1 0), (0 1, 1 1))" ) << true; |
|
|
QTest::newRow( "may be touching at endpoints" ) << QStringLiteral( "MULTILINESTRING((0 0, 1 0), (0 0, 1 0))" ) << true; |
|
|
QTest::newRow( "must not intersect each other" ) << QStringLiteral( "MULTILINESTRING((0 0, 1 1), (0 1, 1 0))" ) << false; |
|
|
QTest::newRow( "multi-polygons are always simple" ) << QStringLiteral( "MULTIPOLYGON(((0 0, 1 1, 1 1, 0 0)),((0 0, 1 1, 1 1, 0 0)))" ) << true; |
|
|
} |
|
|
|
|
|
void TestQgsGeometry::isSimple() |
|
|
{ |
|
|
typedef QPair<QString, bool> InputWktAndExpectedResult; |
|
|
QList<InputWktAndExpectedResult> geoms; |
|
|
geoms << qMakePair( QStringLiteral( "LINESTRING(0 0, 1 0, 1 1)" ), true ); |
|
|
geoms << qMakePair( QStringLiteral( "LINESTRING(0 0, 1 0, 1 1, 0 0)" ), true ); // may be closed (linear ring) |
|
|
geoms << qMakePair( QStringLiteral( "LINESTRING(0 0, 1 0, 1 1, 0 -1)" ), false ); // self-intersection |
|
|
geoms << qMakePair( QStringLiteral( "LINESTRING(0 0, 1 0, 1 1, 0.5 0, 0 1)" ), false ); // self-tangency |
|
|
geoms << qMakePair( QStringLiteral( "POINT(1 1)" ), true ); // points are simple |
|
|
geoms << qMakePair( QStringLiteral( "POLYGON((0 0, 1 1, 1 1, 0 0))" ), true ); // polygons are always simple, even if they are invalid |
|
|
geoms << qMakePair( QStringLiteral( "MULTIPOINT((1 1), (2 2))" ), true ); |
|
|
geoms << qMakePair( QStringLiteral( "MULTIPOINT((1 1), (1 1))" ), false ); // must not contain the same point twice |
|
|
geoms << qMakePair( QStringLiteral( "MULTILINESTRING((0 0, 1 0), (0 1, 1 1))" ), true ); |
|
|
geoms << qMakePair( QStringLiteral( "MULTILINESTRING((0 0, 1 0), (0 0, 1 0))" ), true ); // may be touching at endpoints |
|
|
geoms << qMakePair( QStringLiteral( "MULTILINESTRING((0 0, 1 1), (0 1, 1 0))" ), false ); // must not intersect each other |
|
|
geoms << qMakePair( QStringLiteral( "MULTIPOLYGON(((0 0, 1 1, 1 1, 0 0)),((0 0, 1 1, 1 1, 0 0)))" ), true ); // multi-polygons are always simple |
|
|
|
|
|
Q_FOREACH ( const InputWktAndExpectedResult &pair, geoms ) |
|
|
{ |
|
|
QgsGeometry gInput = QgsGeometry::fromWkt( pair.first ); |
|
|
QVERIFY( !gInput.isNull() ); |
|
|
QFETCH( QString, wkt ); |
|
|
QFETCH( bool, simple ); |
|
|
|
|
|
bool res = gInput.isSimple(); |
|
|
QCOMPARE( res, pair.second ); |
|
|
} |
|
|
QgsGeometry gInput = QgsGeometry::fromWkt( wkt ); |
|
|
QVERIFY( !gInput.isNull() ); |
|
|
|
|
|
bool res = gInput.isSimple(); |
|
|
QCOMPARE( res, simple ); |
|
|
} |
|
|
|
|
|
void TestQgsGeometry::reshapeGeometryLineMerge() |