Commit
vertex from the start of the geometry
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,6 +43,7 @@ class TestQgsGeometryUtils: public QObject | |
void testLinePerpendicularAngle(); | ||
void testAverageAngle_data(); | ||
void testAverageAngle(); | ||
void testDistanceToVertex(); | ||
}; | ||
|
||
|
||
|
@@ -330,6 +331,36 @@ void TestQgsGeometryUtils::testAverageAngle() | |
QVERIFY( qgsDoubleNear( averageAngle, expected, 0.0000000001 ) ); | ||
} | ||
|
||
void TestQgsGeometryUtils::testDistanceToVertex() | ||
{ | ||
//test with linestring | ||
QgsLineStringV2* outerRing1 = new QgsLineStringV2(); | ||
This comment has been minimized.
Sorry, something went wrong.
luipir
Contributor
|
||
outerRing1->setPoints( QList<QgsPointV2>() << QgsPointV2( 1, 1 ) << QgsPointV2( 1, 2 ) << QgsPointV2( 2, 2 ) << QgsPointV2( 2, 1 ) << QgsPointV2( 1, 1 ) ); | ||
QCOMPARE( QgsGeometryUtils::distanceToVertex( *outerRing1, QgsVertexId( 0, 0, 0 ) ), 0.0 ); | ||
QCOMPARE( QgsGeometryUtils::distanceToVertex( *outerRing1, QgsVertexId( 0, 0, 1 ) ), 1.0 ); | ||
QCOMPARE( QgsGeometryUtils::distanceToVertex( *outerRing1, QgsVertexId( 0, 0, 2 ) ), 2.0 ); | ||
QCOMPARE( QgsGeometryUtils::distanceToVertex( *outerRing1, QgsVertexId( 0, 0, 3 ) ), 3.0 ); | ||
QCOMPARE( QgsGeometryUtils::distanceToVertex( *outerRing1, QgsVertexId( 0, 0, 4 ) ), 4.0 ); | ||
QCOMPARE( QgsGeometryUtils::distanceToVertex( *outerRing1, QgsVertexId( 0, 0, 5 ) ), -1.0 ); | ||
QCOMPARE( QgsGeometryUtils::distanceToVertex( *outerRing1, QgsVertexId( 0, 1, 1 ) ), -1.0 ); | ||
|
||
//test with polygon | ||
QgsPolygonV2 polygon1; | ||
polygon1.setExteriorRing( outerRing1 ); | ||
QCOMPARE( QgsGeometryUtils::distanceToVertex( polygon1, QgsVertexId( 0, 0, 0 ) ), 0.0 ); | ||
QCOMPARE( QgsGeometryUtils::distanceToVertex( polygon1, QgsVertexId( 0, 0, 1 ) ), 1.0 ); | ||
QCOMPARE( QgsGeometryUtils::distanceToVertex( polygon1, QgsVertexId( 0, 0, 2 ) ), 2.0 ); | ||
QCOMPARE( QgsGeometryUtils::distanceToVertex( polygon1, QgsVertexId( 0, 0, 3 ) ), 3.0 ); | ||
QCOMPARE( QgsGeometryUtils::distanceToVertex( polygon1, QgsVertexId( 0, 0, 4 ) ), 4.0 ); | ||
QCOMPARE( QgsGeometryUtils::distanceToVertex( polygon1, QgsVertexId( 0, 0, 5 ) ), -1.0 ); | ||
QCOMPARE( QgsGeometryUtils::distanceToVertex( polygon1, QgsVertexId( 0, 1, 1 ) ), -1.0 ); | ||
|
||
//test with point | ||
QgsPointV2 point( 1, 2 ); | ||
QCOMPARE( QgsGeometryUtils::distanceToVertex( point, QgsVertexId( 0, 0, 0 ) ), 0.0 ); | ||
QCOMPARE( QgsGeometryUtils::distanceToVertex( point, QgsVertexId( 0, 0, 1 ) ), -1.0 ); | ||
} | ||
|
||
|
||
QTEST_MAIN( TestQgsGeometryUtils ) | ||
#include "testqgsgeometryutils.moc" |
https://qgis.org/api/qgsgeometryutils_8cpp_source.html#l00161
does not take into account that QgsPointV2 can belogs to a GeometryV2 geometry with Z: