Skip to content

Commit

Permalink
Add unit test for ticket #15116
Browse files Browse the repository at this point in the history
  • Loading branch information
mhugent committed Jun 27, 2016
1 parent 3e069c3 commit ef90c0b
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions tests/src/core/testqgsgeometryutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ class TestQgsGeometryUtils: public QObject
void testAverageAngle_data();
void testAverageAngle();
void testDistanceToVertex();
void testCircleCenterRadius_data();
void testCircleCenterRadius();
};


Expand Down Expand Up @@ -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"

0 comments on commit ef90c0b

Please sign in to comment.