Add unit test for ticket #15116

This commit is contained in:
Marco Hugentobler 2016-06-27 13:32:36 +02:00
parent 3e069c3806
commit ef90c0b2f7

View File

@ -44,6 +44,8 @@ class TestQgsGeometryUtils: public QObject
void testAverageAngle_data();
void testAverageAngle();
void testDistanceToVertex();
void testCircleCenterRadius_data();
void testCircleCenterRadius();
};
@ -361,6 +363,41 @@ void TestQgsGeometryUtils::testDistanceToVertex()
QCOMPARE( QgsGeometryUtils::distanceToVertex( point, QgsVertexId( 0, 0, 1 ) ), -1.0 );
}
void TestQgsGeometryUtils::testCircleCenterRadius_data()
{
QTest::addColumn<double>( "x1" );
QTest::addColumn<double>( "y1" );
QTest::addColumn<double>( "x2" );
QTest::addColumn<double>( "y2" );
QTest::addColumn<double>( "x3" );
QTest::addColumn<double>( "y3" );
QTest::addColumn<double>( "expectedRadius" );
QTest::addColumn<double>( "expectedCenterX" );
QTest::addColumn<double>( "expectedCenterY" );
QTest::newRow( "circleCenterRadius1" ) << 1.0 << 1.0 << 5.0 << 7.0 << 1.0 << 1.0 << sqrt( 13.0 ) << 3.0 << 4.0;
QTest::newRow( "circleCenterRadius1" ) << 0.0 << 2.0 << 2.0 << 2.0 << 0.0 << 2.0 << 1.0 << 1.0 << 2.0;
}
void TestQgsGeometryUtils::testCircleCenterRadius()
{
QFETCH( double, x1 );
QFETCH( double, y1 );
QFETCH( double, x2 );
QFETCH( double, y2 );
QFETCH( double, x3 );
QFETCH( double, y3 );
QFETCH( double, expectedRadius );
QFETCH( double, expectedCenterX );
QFETCH( double, expectedCenterY );
double radius, centerX, centerY;
QgsGeometryUtils::circleCenterRadius( QgsPointV2( x1, y1 ), QgsPointV2( x2, y2 ), QgsPointV2( x3, y3 ), radius, centerX, centerY );
QVERIFY( qgsDoubleNear( expectedRadius, radius ) );
QVERIFY( qgsDoubleNear( expectedCenterX, centerX ) );
QVERIFY( qgsDoubleNear( expectedCenterY, centerY ) );
}
QTEST_MAIN( TestQgsGeometryUtils )
#include "testqgsgeometryutils.moc"