Skip to content
Permalink
Browse files

Add unit test that makes sure that the area of a closed compound curv…

…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 7107c16ec06201dd5d529d1708383f31a2838200
Showing with 27 additions and 0 deletions.
  1. +27 −0 tests/src/core/testqgsgeometry.cpp
@@ -27,6 +27,7 @@

//qgis includes...
#include <qgsapplication.h>
#include "qgscompoundcurve.h"
#include <qgsgeometry.h>
#include "qgsgeometryutils.h"
#include <qgspoint.h>
@@ -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();
@@ -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

0 comments on commit 7107c16

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