Skip to content
Permalink
Browse files

Correct test comparisons

Previously QCOMPARE( QgsGeometry, QgsGeometry ) was actually only
testing for QCOMPARE( bool(QgsGeometry), bool(QgsGeometry) )...!

(cherry picked from commit 18d4059)
  • Loading branch information
nyalldawson committed Nov 4, 2018
1 parent 0b7416f commit 34eb99dde5c88272c6f39abead2c76b8f0d855eb
Showing with 13 additions and 16 deletions.
  1. +13 −16 tests/src/core/testqgsgeometry.cpp
QCOMPARE( radius, 0.0 );
QVERIFY( result.isNull() );

// caase 1
// case 1
geomTest = QgsGeometry::fromPointXY( QgsPointXY( 5, 5 ) );
result = geomTest.minimalEnclosingCircle( center, radius );
QCOMPARE( center, QgsPointXY( 5, 5 ) );

// case 2
geomTest = QgsGeometry::fromWkt( QStringLiteral( "MULTIPOINT( 3 8, 7 4 )" ) );
result = geomTest.minimalEnclosingCircle( center, radius );
result = geomTest.minimalEnclosingCircle( center, radius, 6 );
QGSCOMPARENEARPOINT( center, QgsPointXY( 5, 6 ), 0.0001 );
QGSCOMPARENEAR( radius, sqrt( 2 ) * 2, 0.0001 );
resultTest.set( QgsCircle( QgsPoint( center ), radius ).toPolygon( 36 ) );
QCOMPARE( result.asWkt(), resultTest.asWkt() );
QCOMPARE( result.asWkt( 1 ), QStringLiteral( "Polygon ((7 4, 4.3 3.3, 2.3 5.3, 3 8, 5.7 8.7, 7.7 6.7, 7 4))" ) );

geomTest = QgsGeometry::fromWkt( QStringLiteral( "LINESTRING( 0 5, 2 2, 0 -5, -1 -1 )" ) );
result = geomTest.minimalEnclosingCircle( center, radius );
result = geomTest.minimalEnclosingCircle( center, radius, 6 );
QGSCOMPARENEARPOINT( center, QgsPointXY( 0, 0 ), 0.0001 );
QGSCOMPARENEAR( radius, 5, 0.0001 );
resultTest.set( QgsCircle( QgsPoint( center ), radius ).toPolygon( 36 ) );
QCOMPARE( result.asWkt(), resultTest.asWkt() );
QCOMPARE( result.asWkt( 1 ), QStringLiteral( "Polygon ((0 5, 4.3 2.5, 4.3 -2.5, -0 -5, -4.3 -2.5, -4.3 2.5, 0 5))" ) );

geomTest = QgsGeometry::fromWkt( QStringLiteral( "MULTIPOINT( 0 5, 2 2, 0 -5, -1 -1 )" ) );
result = geomTest.minimalEnclosingCircle( center, radius );
result = geomTest.minimalEnclosingCircle( center, radius, 6 );
QGSCOMPARENEARPOINT( center, QgsPointXY( 0, 0 ), 0.0001 );
QGSCOMPARENEAR( radius, 5, 0.0001 );
resultTest.set( QgsCircle( QgsPoint( center ), radius ).toPolygon( 36 ) );
QCOMPARE( result.asWkt(), resultTest.asWkt() );
QCOMPARE( result.asWkt( 1 ), QStringLiteral( "Polygon ((0 5, 4.3 2.5, 4.3 -2.5, -0 -5, -4.3 -2.5, -4.3 2.5, 0 5))" ) );

geomTest = QgsGeometry::fromWkt( QStringLiteral( "POLYGON(( 0 5, 2 2, 0 -5, -1 -1 ))" ) );
result = geomTest.minimalEnclosingCircle( center, radius );
result = geomTest.minimalEnclosingCircle( center, radius, 6 );
QGSCOMPARENEARPOINT( center, QgsPointXY( 0, 0 ), 0.0001 );
QGSCOMPARENEAR( radius, 5, 0.0001 );
resultTest.set( QgsCircle( QgsPoint( center ), radius ).toPolygon( 36 ) );
QCOMPARE( result.asWkt(), resultTest.asWkt() );
QCOMPARE( result.asWkt( 1 ), QStringLiteral( "Polygon ((0 5, 4.3 2.5, 4.3 -2.5, -0 -5, -4.3 -2.5, -4.3 2.5, 0 5))" ) );

geomTest = QgsGeometry::fromWkt( QStringLiteral( "MULTIPOINT( 0 5, 0 -5, 0 0 )" ) );
result = geomTest.minimalEnclosingCircle( center, radius );
result = geomTest.minimalEnclosingCircle( center, radius, 6 );
QGSCOMPARENEARPOINT( center, QgsPointXY( 0, 0 ), 0.0001 );
QGSCOMPARENEAR( radius, 5, 0.0001 );
resultTest.set( QgsCircle( QgsPoint( center ), radius ).toPolygon( 36 ) );
QCOMPARE( result.asWkt(), resultTest.asWkt() );
QCOMPARE( result.asWkt( 1 ), QStringLiteral( "Polygon ((0 5, 4.3 2.5, 4.3 -2.5, -0 -5, -4.3 -2.5, -4.3 2.5, 0 5))" ) );

// case 3
geomTest = QgsGeometry::fromWkt( QStringLiteral( "MULTIPOINT((0 0), (5 5), (0 -5), (0 5), (-5 0))" ) );
result = geomTest.minimalEnclosingCircle( center, radius );
result = geomTest.minimalEnclosingCircle( center, radius, 6 );
QGSCOMPARENEARPOINT( center, QgsPointXY( 0.8333, 0.8333 ), 0.0001 );
QGSCOMPARENEAR( radius, 5.8926, 0.0001 );
resultTest.set( QgsCircle( QgsPoint( center ), radius ).toPolygon( 36 ) );
QCOMPARE( result.asWkt(), resultTest.asWkt() );
QCOMPARE( result.asWkt( 1 ), QStringLiteral( "Polygon ((0.8 6.7, 5.9 3.8, 5.9 -2.1, 0.8 -5.1, -4.3 -2.1, -4.3 3.8, 0.8 6.7))" ) );

}

0 comments on commit 34eb99d

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