Skip to content

Commit

Permalink
Merge pull request #3242 from mhugent/full_circle
Browse files Browse the repository at this point in the history
Change full circle interpretation, fixes #15116
  • Loading branch information
mhugent committed Jun 27, 2016
2 parents e02661c + 663333d commit 21b8ef0
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/core/geometry/qgscircularstringv2.cpp
Expand Up @@ -879,7 +879,7 @@ void QgsCircularStringV2::sumUpArea( double& sum ) const
//segment is a full circle, p2 is the center point
if ( p1 == p3 )
{
double r2 = QgsGeometryUtils::sqrDistance2D( p1, p2 );
double r2 = QgsGeometryUtils::sqrDistance2D( p1, p2 ) / 4.0;
sum += M_PI * r2;
continue;
}
Expand Down
6 changes: 3 additions & 3 deletions src/core/geometry/qgsgeometryutils.cpp
Expand Up @@ -359,9 +359,9 @@ void QgsGeometryUtils::circleCenterRadius( const QgsPointV2& pt1, const QgsPoint
//closed circle
if ( qgsDoubleNear( pt1.x(), pt3.x() ) && qgsDoubleNear( pt1.y(), pt3.y() ) )
{
centerX = pt2.x();
centerY = pt2.y();
radius = sqrt( pow( pt2.x() - pt1.x(), 2.0 ) + pow( pt2.y() - pt1.y(), 2.0 ) );
centerX = ( pt1.x() + pt2.x() ) / 2.0;
centerY = ( pt1.y() + pt2.y() ) / 2.0;
radius = sqrt( pow( centerX - pt1.x(), 2.0 ) + pow( centerY - pt1.y(), 2.0 ) );
return;
}

Expand Down
37 changes: 37 additions & 0 deletions tests/src/core/testqgsgeometryutils.cpp
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 21b8ef0

Please sign in to comment.