Skip to content

Commit 21b8ef0

Browse files
authoredJun 27, 2016
Merge pull request #3242 from mhugent/full_circle
Change full circle interpretation, fixes #15116
2 parents e02661c + 663333d commit 21b8ef0

File tree

3 files changed

+41
-4
lines changed

3 files changed

+41
-4
lines changed
 

‎src/core/geometry/qgscircularstringv2.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -879,7 +879,7 @@ void QgsCircularStringV2::sumUpArea( double& sum ) const
879879
//segment is a full circle, p2 is the center point
880880
if ( p1 == p3 )
881881
{
882-
double r2 = QgsGeometryUtils::sqrDistance2D( p1, p2 );
882+
double r2 = QgsGeometryUtils::sqrDistance2D( p1, p2 ) / 4.0;
883883
sum += M_PI * r2;
884884
continue;
885885
}

‎src/core/geometry/qgsgeometryutils.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -359,9 +359,9 @@ void QgsGeometryUtils::circleCenterRadius( const QgsPointV2& pt1, const QgsPoint
359359
//closed circle
360360
if ( qgsDoubleNear( pt1.x(), pt3.x() ) && qgsDoubleNear( pt1.y(), pt3.y() ) )
361361
{
362-
centerX = pt2.x();
363-
centerY = pt2.y();
364-
radius = sqrt( pow( pt2.x() - pt1.x(), 2.0 ) + pow( pt2.y() - pt1.y(), 2.0 ) );
362+
centerX = ( pt1.x() + pt2.x() ) / 2.0;
363+
centerY = ( pt1.y() + pt2.y() ) / 2.0;
364+
radius = sqrt( pow( centerX - pt1.x(), 2.0 ) + pow( centerY - pt1.y(), 2.0 ) );
365365
return;
366366
}
367367

‎tests/src/core/testqgsgeometryutils.cpp

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ class TestQgsGeometryUtils: public QObject
4444
void testAverageAngle_data();
4545
void testAverageAngle();
4646
void testDistanceToVertex();
47+
void testCircleCenterRadius_data();
48+
void testCircleCenterRadius();
4749
};
4850

4951

@@ -361,6 +363,41 @@ void TestQgsGeometryUtils::testDistanceToVertex()
361363
QCOMPARE( QgsGeometryUtils::distanceToVertex( point, QgsVertexId( 0, 0, 1 ) ), -1.0 );
362364
}
363365

366+
void TestQgsGeometryUtils::testCircleCenterRadius_data()
367+
{
368+
QTest::addColumn<double>( "x1" );
369+
QTest::addColumn<double>( "y1" );
370+
QTest::addColumn<double>( "x2" );
371+
QTest::addColumn<double>( "y2" );
372+
QTest::addColumn<double>( "x3" );
373+
QTest::addColumn<double>( "y3" );
374+
QTest::addColumn<double>( "expectedRadius" );
375+
QTest::addColumn<double>( "expectedCenterX" );
376+
QTest::addColumn<double>( "expectedCenterY" );
377+
378+
QTest::newRow( "circleCenterRadius1" ) << 1.0 << 1.0 << 5.0 << 7.0 << 1.0 << 1.0 << sqrt( 13.0 ) << 3.0 << 4.0;
379+
QTest::newRow( "circleCenterRadius1" ) << 0.0 << 2.0 << 2.0 << 2.0 << 0.0 << 2.0 << 1.0 << 1.0 << 2.0;
380+
}
381+
382+
void TestQgsGeometryUtils::testCircleCenterRadius()
383+
{
384+
QFETCH( double, x1 );
385+
QFETCH( double, y1 );
386+
QFETCH( double, x2 );
387+
QFETCH( double, y2 );
388+
QFETCH( double, x3 );
389+
QFETCH( double, y3 );
390+
QFETCH( double, expectedRadius );
391+
QFETCH( double, expectedCenterX );
392+
QFETCH( double, expectedCenterY );
393+
394+
double radius, centerX, centerY;
395+
QgsGeometryUtils::circleCenterRadius( QgsPointV2( x1, y1 ), QgsPointV2( x2, y2 ), QgsPointV2( x3, y3 ), radius, centerX, centerY );
396+
QVERIFY( qgsDoubleNear( expectedRadius, radius ) );
397+
QVERIFY( qgsDoubleNear( expectedCenterX, centerX ) );
398+
QVERIFY( qgsDoubleNear( expectedCenterY, centerY ) );
399+
}
400+
364401

365402
QTEST_MAIN( TestQgsGeometryUtils )
366403
#include "testqgsgeometryutils.moc"

0 commit comments

Comments
 (0)
Please sign in to comment.