@@ -43,6 +43,7 @@ class TestQgsGeometryUtils: public QObject
43
43
void testLinePerpendicularAngle ();
44
44
void testAverageAngle_data ();
45
45
void testAverageAngle ();
46
+ void testDistanceToVertex ();
46
47
};
47
48
48
49
@@ -330,6 +331,36 @@ void TestQgsGeometryUtils::testAverageAngle()
330
331
QVERIFY ( qgsDoubleNear ( averageAngle, expected, 0.0000000001 ) );
331
332
}
332
333
334
+ void TestQgsGeometryUtils::testDistanceToVertex ()
335
+ {
336
+ // test with linestring
337
+ QgsLineStringV2* outerRing1 = new QgsLineStringV2 ();
338
+ outerRing1->setPoints ( QList<QgsPointV2>() << QgsPointV2 ( 1 , 1 ) << QgsPointV2 ( 1 , 2 ) << QgsPointV2 ( 2 , 2 ) << QgsPointV2 ( 2 , 1 ) << QgsPointV2 ( 1 , 1 ) );
339
+ QCOMPARE ( QgsGeometryUtils::distanceToVertex ( *outerRing1, QgsVertexId ( 0 , 0 , 0 ) ), 0.0 );
340
+ QCOMPARE ( QgsGeometryUtils::distanceToVertex ( *outerRing1, QgsVertexId ( 0 , 0 , 1 ) ), 1.0 );
341
+ QCOMPARE ( QgsGeometryUtils::distanceToVertex ( *outerRing1, QgsVertexId ( 0 , 0 , 2 ) ), 2.0 );
342
+ QCOMPARE ( QgsGeometryUtils::distanceToVertex ( *outerRing1, QgsVertexId ( 0 , 0 , 3 ) ), 3.0 );
343
+ QCOMPARE ( QgsGeometryUtils::distanceToVertex ( *outerRing1, QgsVertexId ( 0 , 0 , 4 ) ), 4.0 );
344
+ QCOMPARE ( QgsGeometryUtils::distanceToVertex ( *outerRing1, QgsVertexId ( 0 , 0 , 5 ) ), -1.0 );
345
+ QCOMPARE ( QgsGeometryUtils::distanceToVertex ( *outerRing1, QgsVertexId ( 0 , 1 , 1 ) ), -1.0 );
346
+
347
+ // test with polygon
348
+ QgsPolygonV2 polygon1;
349
+ polygon1.setExteriorRing ( outerRing1 );
350
+ QCOMPARE ( QgsGeometryUtils::distanceToVertex ( polygon1, QgsVertexId ( 0 , 0 , 0 ) ), 0.0 );
351
+ QCOMPARE ( QgsGeometryUtils::distanceToVertex ( polygon1, QgsVertexId ( 0 , 0 , 1 ) ), 1.0 );
352
+ QCOMPARE ( QgsGeometryUtils::distanceToVertex ( polygon1, QgsVertexId ( 0 , 0 , 2 ) ), 2.0 );
353
+ QCOMPARE ( QgsGeometryUtils::distanceToVertex ( polygon1, QgsVertexId ( 0 , 0 , 3 ) ), 3.0 );
354
+ QCOMPARE ( QgsGeometryUtils::distanceToVertex ( polygon1, QgsVertexId ( 0 , 0 , 4 ) ), 4.0 );
355
+ QCOMPARE ( QgsGeometryUtils::distanceToVertex ( polygon1, QgsVertexId ( 0 , 0 , 5 ) ), -1.0 );
356
+ QCOMPARE ( QgsGeometryUtils::distanceToVertex ( polygon1, QgsVertexId ( 0 , 1 , 1 ) ), -1.0 );
357
+
358
+ // test with point
359
+ QgsPointV2 point ( 1 , 2 );
360
+ QCOMPARE ( QgsGeometryUtils::distanceToVertex ( point, QgsVertexId ( 0 , 0 , 0 ) ), 0.0 );
361
+ QCOMPARE ( QgsGeometryUtils::distanceToVertex ( point, QgsVertexId ( 0 , 0 , 1 ) ), -1.0 );
362
+ }
363
+
333
364
334
365
QTEST_MAIN ( TestQgsGeometryUtils )
335
366
#include " testqgsgeometryutils.moc"
0 commit comments