Skip to content
Permalink
Browse files

Consolidate QgsGeometryUtils tests

  • Loading branch information
nyalldawson committed Nov 30, 2015
1 parent 1c2454f commit 3910c457b11a207846c1282b4990030b31be1037
Showing with 56 additions and 61 deletions.
  1. +0 −45 tests/src/core/testqgsgeometry.cpp
  2. +56 −16 tests/src/core/testqgsgeometryutils.cpp
@@ -57,7 +57,6 @@ class TestQgsGeometry : public QObject
void isEmpty();
void pointV2(); //test QgsPointV2
void lineStringV2(); //test QgsLineStringV2
void utils(); //test QgsGeometryUtils

void fromQgsPoint();
void fromQPoint();
@@ -1921,50 +1920,6 @@ void TestQgsGeometry::lineStringV2()

}

void TestQgsGeometry::utils()
{
//test normalizedAngle
QVERIFY( qgsDoubleNear( QgsGeometryUtils::normalizedAngle( 0.0 ), 0.0, 0.0001 ) );
QVERIFY( qgsDoubleNear( QgsGeometryUtils::normalizedAngle( 1.5708 ), 1.5708, 0.0001 ) );
QVERIFY( qgsDoubleNear( QgsGeometryUtils::normalizedAngle( 3.1416 ), 3.1416, 0.0001 ) );
QVERIFY( qgsDoubleNear( QgsGeometryUtils::normalizedAngle( 4.7124 ), 4.7124, 0.0001 ) );
QVERIFY( qgsDoubleNear( QgsGeometryUtils::normalizedAngle( 2 * M_PI ), 0.0, 0.0001 ) );
QVERIFY( qgsDoubleNear( QgsGeometryUtils::normalizedAngle( 6.80678 ), 0.5236, 0.0001 ) );
QVERIFY( qgsDoubleNear( QgsGeometryUtils::normalizedAngle( 12.5664 ), 0.0, 0.0001 ) );
QVERIFY( qgsDoubleNear( QgsGeometryUtils::normalizedAngle( 12.7409 ), 0.174533, 0.0001 ) );
QVERIFY( qgsDoubleNear( QgsGeometryUtils::normalizedAngle( -0.174533 ), 6.10865, 0.0001 ) );
QVERIFY( qgsDoubleNear( QgsGeometryUtils::normalizedAngle( -6.28318 ), 0.0, 0.0001 ) );
QVERIFY( qgsDoubleNear( QgsGeometryUtils::normalizedAngle( -6.45772 ), 6.10865, 0.0001 ) );
QVERIFY( qgsDoubleNear( QgsGeometryUtils::normalizedAngle( -13.2645 ), 5.58505, 0.0001 ) );

//test lineAngle
( void )QgsGeometryUtils::lineAngle( 0.0, 0.0, 0.0, 0.0 ); //undefined, but don't want a crash
QVERIFY( qgsDoubleNear( QgsGeometryUtils::lineAngle( 0.0, 0.0, 0.0, 1.0 ), 0.0, 0.0001 ) );
QVERIFY( qgsDoubleNear( QgsGeometryUtils::lineAngle( 0.0, 0.0, 1.0, 1.0 ), 0.7854, 0.0001 ) );
QVERIFY( qgsDoubleNear( QgsGeometryUtils::lineAngle( 0.0, 0.0, 1.0, 0.0 ), 1.5708, 0.0001 ) );
QVERIFY( qgsDoubleNear( QgsGeometryUtils::lineAngle( 0.0, 0.0, 0.0, -1.0 ), 3.1416, 0.0001 ) );
QVERIFY( qgsDoubleNear( QgsGeometryUtils::lineAngle( 0.0, 0.0, -1.0, 0.0 ), 4.7124, 0.0001 ) );

//test linePerpendicularAngle
( void )QgsGeometryUtils::linePerpendicularAngle( 0.0, 0.0, 0.0, 0.0 ); //undefined, but don't want a crash
QVERIFY( qgsDoubleNear( QgsGeometryUtils::linePerpendicularAngle( 0.0, 0.0, 0.0, 1.0 ), 1.5708, 0.0001 ) );
QVERIFY( qgsDoubleNear( QgsGeometryUtils::linePerpendicularAngle( 0.0, 0.0, 1.0, 1.0 ), 2.3562, 0.0001 ) );
QVERIFY( qgsDoubleNear( QgsGeometryUtils::linePerpendicularAngle( 0.0, 0.0, 1.0, 0.0 ), 3.1416, 0.0001 ) );
QVERIFY( qgsDoubleNear( QgsGeometryUtils::linePerpendicularAngle( 0.0, 0.0, 0.0, -1.0 ), 4.7124, 0.0001 ) );
QVERIFY( qgsDoubleNear( QgsGeometryUtils::linePerpendicularAngle( 0.0, 0.0, -1.0, 0.0 ), 0.0, 0.0001 ) );

//test averageAngle
QVERIFY( qgsDoubleNear( QgsGeometryUtils::averageAngle( 0.0, 0.0 ), 0.0, 0.0001 ) );
QVERIFY( qgsDoubleNear( QgsGeometryUtils::averageAngle( 0.0, 6.28319 ), 0.0, 0.0001 ) );
QVERIFY( qgsDoubleNear( QgsGeometryUtils::averageAngle( 0.0, 12.5664 ), 0.0, 0.0001 ) );
QVERIFY( qgsDoubleNear( QgsGeometryUtils::averageAngle( 6.28319, 0.0 ), 0.0, 0.0001 ) );
QVERIFY( qgsDoubleNear( QgsGeometryUtils::averageAngle( -6.28318, 0.0 ), 0.0, 0.0001 ) );
QVERIFY( qgsDoubleNear( QgsGeometryUtils::averageAngle( -6.28318, -6.28318 ), 0.0, 0.0001 ) );
QVERIFY( qgsDoubleNear( QgsGeometryUtils::averageAngle( 0.0, 3.141592 ), 1.5708, 0.0001 ) );
QVERIFY( qgsDoubleNear( QgsGeometryUtils::averageAngle( 0.0, -3.141592 ), 4.71239, 0.0001 ) );
QVERIFY( qgsDoubleNear( QgsGeometryUtils::averageAngle( 5.49779, 4.71239 ), 5.1051, 0.0001 ) );
}

void TestQgsGeometry::fromQgsPoint()
{
QgsPoint point( 1.0, 2.0 );
@@ -31,6 +31,8 @@ class TestQgsGeometryUtils: public QObject
void testSegmentMidPoint();
void testCircleLength_data();
void testCircleLength();
void testNormalizedAngle_data();
void testNormalizedAngle();
void testLineAngle_data();
void testLineAngle();
void testLinePerpendicularAngle_data();
@@ -176,6 +178,31 @@ void TestQgsGeometryUtils::testCircleLength()
QVERIFY( qgsDoubleNear( expected, QgsGeometryUtils::circleLength( x1, y1, x2, y2, x3, y3 ) ) );
}

void TestQgsGeometryUtils::testNormalizedAngle_data()
{
QTest::addColumn<double>( "input" );
QTest::addColumn<double>( "expected" );
QTest::newRow( "normalizedAngle 0" ) << 0.0 << 0.0;
QTest::newRow( "normalizedAngle 1.5708" ) << 1.5708 << 1.5708;
QTest::newRow( "normalizedAngle 3.1416" ) << 3.1416 << 3.1416;
QTest::newRow( "normalizedAngle 4.7124" ) << 4.7124 << 4.7124;
QTest::newRow( "normalizedAngle 2 * M_PI" ) << 2 * M_PI << 0.0;
QTest::newRow( "normalizedAngle 6.80678" ) << 6.80678 << 0.5236;
QTest::newRow( "normalizedAngle 12.5664" ) << 12.5664 << 0.0;
QTest::newRow( "normalizedAngle 12.7409" ) << 12.7409 << 0.174533;
QTest::newRow( "normalizedAngle -0.174533" ) << -0.174533 << 6.10865;
QTest::newRow( "normalizedAngle -6.28318" ) << -6.28318 << 0.0;
QTest::newRow( "normalizedAngle -6.45772" ) << -6.45772 << 6.10865;
QTest::newRow( "normalizedAngle -13.2645" ) << -13.2645 << 5.58505;
}

void TestQgsGeometryUtils::testNormalizedAngle()
{
QFETCH( double, input );
QFETCH( double, expected );
QVERIFY( qgsDoubleNear( expected, QgsGeometryUtils::normalizedAngle( input ), 0.0001 ) );
}

void TestQgsGeometryUtils::testLineAngle_data()
{
QTest::addColumn<double>( "x1" );
@@ -184,6 +211,7 @@ void TestQgsGeometryUtils::testLineAngle_data()
QTest::addColumn<double>( "y2" );
QTest::addColumn<double>( "expected" );

QTest::newRow( "lineAngle undefined" ) << 0.0 << 0.0 << 0.0 << 0.0 << -99999.0; //value is unimportant, we just don't want a crash
QTest::newRow( "lineAngle1" ) << 0.0 << 0.0 << 10.0 << 10.0 << 45.0;
QTest::newRow( "lineAngle2" ) << 0.0 << 0.0 << 10.0 << 0.0 << 90.0;
QTest::newRow( "lineAngle3" ) << 0.0 << 0.0 << 10.0 << -10.0 << 135.0;
@@ -203,7 +231,8 @@ void TestQgsGeometryUtils::testLineAngle()
QFETCH( double, expected );

double lineAngle = QgsGeometryUtils::lineAngle( x1, y1, x2, y2 ) * 180 / M_PI;
QVERIFY( qgsDoubleNear( lineAngle, expected ) );
if ( expected > -99999 )
QVERIFY( qgsDoubleNear( lineAngle, expected ) );
}

void TestQgsGeometryUtils::testLinePerpendicularAngle_data()
@@ -214,14 +243,15 @@ void TestQgsGeometryUtils::testLinePerpendicularAngle_data()
QTest::addColumn<double>( "y2" );
QTest::addColumn<double>( "expected" );

QTest::newRow( "lineAngle1" ) << 0.0 << 0.0 << 10.0 << 10.0 << 135.0;
QTest::newRow( "lineAngle2" ) << 0.0 << 0.0 << 10.0 << 0.0 << 180.0;
QTest::newRow( "lineAngle3" ) << 0.0 << 0.0 << 10.0 << -10.0 << 225.0;
QTest::newRow( "lineAngle4" ) << 0.0 << 0.0 << 0.0 << -10.0 << 270.0;
QTest::newRow( "lineAngle5" ) << 0.0 << 0.0 << -10.0 << -10.0 << 315.0;
QTest::newRow( "lineAngle6" ) << 0.0 << 0.0 << -10.0 << 0.0 << 0.0;
QTest::newRow( "lineAngle7" ) << 0.0 << 0.0 << -10.0 << 10.0 << 45.0;
QTest::newRow( "lineAngle8" ) << 0.0 << 0.0 << 0.0 << 10.0 << 90.0;
QTest::newRow( "linePerpendicularAngle undefined" ) << 0.0 << 0.0 << 0.0 << 0.0 << -99999.0; //value is unimportant, we just don't want a crash
QTest::newRow( "linePerpendicularAngle1" ) << 0.0 << 0.0 << 10.0 << 10.0 << 135.0;
QTest::newRow( "linePerpendicularAngle2" ) << 0.0 << 0.0 << 10.0 << 0.0 << 180.0;
QTest::newRow( "linePerpendicularAngle3" ) << 0.0 << 0.0 << 10.0 << -10.0 << 225.0;
QTest::newRow( "linePerpendicularAngle4" ) << 0.0 << 0.0 << 0.0 << -10.0 << 270.0;
QTest::newRow( "linePerpendicularAngle5" ) << 0.0 << 0.0 << -10.0 << -10.0 << 315.0;
QTest::newRow( "linePerpendicularAngle6" ) << 0.0 << 0.0 << -10.0 << 0.0 << 0.0;
QTest::newRow( "linePerpendicularAngle7" ) << 0.0 << 0.0 << -10.0 << 10.0 << 45.0;
QTest::newRow( "linePerpendicularAngle8" ) << 0.0 << 0.0 << 0.0 << 10.0 << 90.0;
}

void TestQgsGeometryUtils::testLinePerpendicularAngle()
@@ -233,7 +263,8 @@ void TestQgsGeometryUtils::testLinePerpendicularAngle()
QFETCH( double, expected );

double pAngle = QgsGeometryUtils::linePerpendicularAngle( x1, y1, x2, y2 ) * 180 / M_PI;
QVERIFY( qgsDoubleNear( pAngle, expected ) );
if ( expected > -99999 )
QVERIFY( qgsDoubleNear( pAngle, expected, 0.01 ) );
}

void TestQgsGeometryUtils::testAverageAngle_data()
@@ -242,12 +273,21 @@ void TestQgsGeometryUtils::testAverageAngle_data()
QTest::addColumn<double>( "angle2" );
QTest::addColumn<double>( "expected" );

QTest::newRow( "testAverage1" ) << 45.0 << 135.0 << 90.0;
QTest::newRow( "testAverage2" ) << 315.0 << 45.0 << 0.0;
QTest::newRow( "testAverage3" ) << 45.0 << 315.0 << 0.0;
QTest::newRow( "testAverage4" ) << 315.0 << 270.0 << 292.5;
QTest::newRow( "testAverage5" ) << 140.0 << 240.0 << 190.0;
QTest::newRow( "testAverage6" ) << 240.0 << 140.0 << 190.0;
QTest::newRow( "testAverageAngle1" ) << 0.0 << 0.0 << 0.0;
QTest::newRow( "testAverageAngle2" ) << 0.0 << 360.0 << 0.0;
QTest::newRow( "testAverageAngle3" ) << 0.0 << 720.0 << 0.0;
QTest::newRow( "testAverageAngle4" ) << 360.0 << 0.0 << 0.0;
QTest::newRow( "testAverageAngle5" ) << -360.0 << 0.0 << 0.0;
QTest::newRow( "testAverageAngle6" ) << -360.0 << -360.0 << 0.0;
QTest::newRow( "testAverageAngle7" ) << 0.0 << 180.0 << 90.0;
QTest::newRow( "testAverageAngle8" ) << 0.0 << -179.999999999999 << 270.0;
QTest::newRow( "testAverageAngle9" ) << 315.0 << 270.0 << 292.5;
QTest::newRow( "testAverageAngle10" ) << 45.0 << 135.0 << 90.0;
QTest::newRow( "testAverageAngle11" ) << 315.0 << 45.0 << 0.0;
QTest::newRow( "testAverageAngle12" ) << 45.0 << 315.0 << 0.0;
QTest::newRow( "testAverageAngle13" ) << 315.0 << 270.0 << 292.5;
QTest::newRow( "testAverageAngle14" ) << 140.0 << 240.0 << 190.0;
QTest::newRow( "testAverageAngle15" ) << 240.0 << 140.0 << 190.0;
}

void TestQgsGeometryUtils::testAverageAngle()

0 comments on commit 3910c45

Please sign in to comment.
You can’t perform that action at this time.