@@ -44,6 +44,8 @@ class TestQgsGeometryUtils: public QObject
44
44
void testAverageAngle_data ();
45
45
void testAverageAngle ();
46
46
void testDistanceToVertex ();
47
+ void testCircleCenterRadius_data ();
48
+ void testCircleCenterRadius ();
47
49
};
48
50
49
51
@@ -361,6 +363,41 @@ void TestQgsGeometryUtils::testDistanceToVertex()
361
363
QCOMPARE ( QgsGeometryUtils::distanceToVertex ( point, QgsVertexId ( 0 , 0 , 1 ) ), -1.0 );
362
364
}
363
365
366
+ void TestQgsGeometryUtils::testCircleCenterRadius_data ()
367
+ {
368
+ QTest::addColumn<double >( " x1" );
369
+ QTest::addColumn<double >( " y1" );
370
+ QTest::addColumn<double >( " x2" );
371
+ QTest::addColumn<double >( " y2" );
372
+ QTest::addColumn<double >( " x3" );
373
+ QTest::addColumn<double >( " y3" );
374
+ QTest::addColumn<double >( " expectedRadius" );
375
+ QTest::addColumn<double >( " expectedCenterX" );
376
+ QTest::addColumn<double >( " expectedCenterY" );
377
+
378
+ QTest::newRow ( " circleCenterRadius1" ) << 1.0 << 1.0 << 5.0 << 7.0 << 1.0 << 1.0 << sqrt ( 13.0 ) << 3.0 << 4.0 ;
379
+ QTest::newRow ( " circleCenterRadius1" ) << 0.0 << 2.0 << 2.0 << 2.0 << 0.0 << 2.0 << 1.0 << 1.0 << 2.0 ;
380
+ }
381
+
382
+ void TestQgsGeometryUtils::testCircleCenterRadius ()
383
+ {
384
+ QFETCH ( double , x1 );
385
+ QFETCH ( double , y1 );
386
+ QFETCH ( double , x2 );
387
+ QFETCH ( double , y2 );
388
+ QFETCH ( double , x3 );
389
+ QFETCH ( double , y3 );
390
+ QFETCH ( double , expectedRadius );
391
+ QFETCH ( double , expectedCenterX );
392
+ QFETCH ( double , expectedCenterY );
393
+
394
+ double radius, centerX, centerY;
395
+ QgsGeometryUtils::circleCenterRadius ( QgsPointV2 ( x1, y1 ), QgsPointV2 ( x2, y2 ), QgsPointV2 ( x3, y3 ), radius, centerX, centerY );
396
+ QVERIFY ( qgsDoubleNear ( expectedRadius, radius ) );
397
+ QVERIFY ( qgsDoubleNear ( expectedCenterX, centerX ) );
398
+ QVERIFY ( qgsDoubleNear ( expectedCenterY, centerY ) );
399
+ }
400
+
364
401
365
402
QTEST_MAIN ( TestQgsGeometryUtils )
366
403
#include " testqgsgeometryutils.moc"
0 commit comments