Skip to content

Commit

Permalink
Add unit test that makes sure that the area of a closed compound curv…
Browse files Browse the repository at this point in the history
…e ring is the same as a closed linestring with the same number of vertices

(forward port from be71066)
  • Loading branch information
mhugent authored and nyalldawson committed Jan 9, 2017
1 parent abc0919 commit 7107c16
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions tests/src/core/testqgsgeometry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

//qgis includes...
#include <qgsapplication.h>
#include "qgscompoundcurve.h"
#include <qgsgeometry.h>
#include "qgsgeometryutils.h"
#include <qgspoint.h>
Expand Down Expand Up @@ -69,6 +70,7 @@ class TestQgsGeometry : public QObject
void point(); //test QgsPointV2
void lineString(); //test QgsLineString
void polygon(); //test QgsPolygonV2
void compoundCurve(); //test QgsCompoundCurve
void multiPoint();
void multiLineString();
void multiPolygon();
Expand Down Expand Up @@ -3092,6 +3094,31 @@ void TestQgsGeometry::polygon()

}

void TestQgsGeometry::compoundCurve()
{
//test that area of a compound curve ring is equal to a closed linestring with the same vertices
QgsCompoundCurve cc;
QgsLineString* l1 = new QgsLineString();
l1->setPoints( QgsPointSequence() << QgsPointV2( 1, 1 ) << QgsPointV2( 0, 2 ) );
cc.addCurve( l1 );
QgsLineString* l2 = new QgsLineString();
l2->setPoints( QgsPointSequence() << QgsPointV2( 0, 2 ) << QgsPointV2( -1, 0 ) << QgsPointV2( 0, -1 ) );
cc.addCurve( l2 );
QgsLineString* l3 = new QgsLineString();
l3->setPoints( QgsPointSequence() << QgsPointV2( 0, -1 ) << QgsPointV2( 1, 1 ) );
cc.addCurve( l3 );

double ccArea = 0.0;
cc.sumUpArea( ccArea );

QgsLineString ls;
ls.setPoints( QgsPointSequence() << QgsPointV2( 1, 1 ) << QgsPointV2( 0, 2 ) << QgsPointV2( -1, 0 ) << QgsPointV2( 0, -1 )
<< QgsPointV2( 1, 1 ) );
double lsArea = 0.0;
ls.sumUpArea( lsArea );
QVERIFY( qgsDoubleNear( ccArea, lsArea ) );
}

void TestQgsGeometry::multiPoint()
{
//boundary
Expand Down

0 comments on commit 7107c16

Please sign in to comment.