Skip to content
Permalink
Browse files

Move QgsPolygonV2 equality operators up to QgsCurvePolygon

  • Loading branch information
nyalldawson committed Sep 19, 2017
1 parent bb425e4 commit f387210e4a6efcbf575ef80c560eac97895cbddc
@@ -23,10 +23,19 @@ class QgsCurvePolygon: QgsSurface
public:
QgsCurvePolygon();
QgsCurvePolygon( const QgsCurvePolygon &p );

bool operator==( const QgsCurvePolygon &other ) const;
bool operator!=( const QgsCurvePolygon &other ) const;
%Docstring
:rtype: bool
%End

~QgsCurvePolygon();

virtual QString geometryType() const;

virtual int dimension() const;

virtual QgsCurvePolygon *clone() const /Factory/;

virtual void clear();
@@ -163,10 +172,12 @@ Adds an interior ring to the geometry (takes ownership)
:rtype: float
%End

virtual int vertexCount( int /*part*/ = 0, int ring = 0 ) const;
virtual int vertexCount( int part = 0, int ring = 0 ) const;

virtual int ringCount( int part = 0 ) const;

virtual int ringCount( int /*part*/ = 0 ) const;
virtual int partCount() const;

virtual QgsPoint vertexAt( QgsVertexId id ) const;


@@ -22,12 +22,6 @@ class QgsPolygonV2: QgsCurvePolygon
public:
QgsPolygonV2();

bool operator==( const QgsPolygonV2 &other ) const;
bool operator!=( const QgsPolygonV2 &other ) const;
%Docstring
:rtype: bool
%End

virtual QString geometryType() const;

virtual QgsPolygonV2 *clone() const /Factory/;
@@ -37,6 +37,16 @@ QgsCurvePolygon::~QgsCurvePolygon()
clear();
}

QString QgsCurvePolygon::geometryType() const
{
return QStringLiteral( "CurvePolygon" );
}

int QgsCurvePolygon::dimension() const
{
return 2;
}

QgsCurvePolygon::QgsCurvePolygon( const QgsCurvePolygon &p )
: QgsSurface( p )

@@ -72,6 +82,44 @@ QgsCurvePolygon &QgsCurvePolygon::operator=( const QgsCurvePolygon &p )
return *this;
}

bool QgsCurvePolygon::operator==( const QgsCurvePolygon &other ) const
{
//run cheap checks first
if ( mWkbType != other.mWkbType )
return false;

if ( ( !mExteriorRing && other.mExteriorRing ) || ( mExteriorRing && !other.mExteriorRing ) )
return false;

if ( mInteriorRings.count() != other.mInteriorRings.count() )
return false;

// compare rings
if ( mExteriorRing && other.mExteriorRing )
{
if ( *mExteriorRing != *other.mExteriorRing )
return false;
}

for ( int i = 0; i < mInteriorRings.count(); ++i )
{
if ( ( !mInteriorRings.at( i ) && other.mInteriorRings.at( i ) ) ||
( mInteriorRings.at( i ) && !other.mInteriorRings.at( i ) ) )
return false;

if ( mInteriorRings.at( i ) && other.mInteriorRings.at( i ) &&
*mInteriorRings.at( i ) != *other.mInteriorRings.at( i ) )
return false;
}

return true;
}

bool QgsCurvePolygon::operator!=( const QgsCurvePolygon &other ) const
{
return !operator==( other );
}

QgsCurvePolygon *QgsCurvePolygon::clone() const
{
return new QgsCurvePolygon( *this );
@@ -855,6 +903,16 @@ int QgsCurvePolygon::vertexCount( int /*part*/, int ring ) const
return ring == 0 ? mExteriorRing->vertexCount() : mInteriorRings[ring - 1]->vertexCount();
}

int QgsCurvePolygon::ringCount( int ) const
{
return ( nullptr != mExteriorRing ) + mInteriorRings.size();
}

int QgsCurvePolygon::partCount() const
{
return ringCount() > 0 ? 1 : 0;
}

QgsPoint QgsCurvePolygon::vertexAt( QgsVertexId id ) const
{
return id.ring == 0 ? mExteriorRing->vertexAt( id ) : mInteriorRings[id.ring - 1]->vertexAt( id );
@@ -35,10 +35,14 @@ class CORE_EXPORT QgsCurvePolygon: public QgsSurface
QgsCurvePolygon();
QgsCurvePolygon( const QgsCurvePolygon &p );
QgsCurvePolygon &operator=( const QgsCurvePolygon &p );

bool operator==( const QgsCurvePolygon &other ) const;
bool operator!=( const QgsCurvePolygon &other ) const;

~QgsCurvePolygon();

QString geometryType() const override { return QStringLiteral( "CurvePolygon" ); }
int dimension() const override { return 2; }
QString geometryType() const override;
int dimension() const override;
QgsCurvePolygon *clone() const override SIP_FACTORY;
void clear() override;

@@ -128,9 +132,9 @@ class CORE_EXPORT QgsCurvePolygon: public QgsSurface
*/
double vertexAngle( QgsVertexId vertex ) const override;

int vertexCount( int /*part*/ = 0, int ring = 0 ) const override;
int ringCount( int /*part*/ = 0 ) const override { return ( nullptr != mExteriorRing ) + mInteriorRings.size(); }
int partCount() const override { return ringCount() > 0 ? 1 : 0; }
int vertexCount( int part = 0, int ring = 0 ) const override;
int ringCount( int part = 0 ) const override;
int partCount() const override;
QgsPoint vertexAt( QgsVertexId id ) const override;

bool addZValue( double zValue = 0 ) override;
@@ -28,44 +28,6 @@ QgsPolygonV2::QgsPolygonV2()
mWkbType = QgsWkbTypes::Polygon;
}

bool QgsPolygonV2::operator==( const QgsPolygonV2 &other ) const
{
//run cheap checks first
if ( mWkbType != other.mWkbType )
return false;

if ( ( !mExteriorRing && other.mExteriorRing ) || ( mExteriorRing && !other.mExteriorRing ) )
return false;

if ( mInteriorRings.count() != other.mInteriorRings.count() )
return false;

// compare rings
if ( mExteriorRing && other.mExteriorRing )
{
if ( *mExteriorRing != *other.mExteriorRing )
return false;
}

for ( int i = 0; i < mInteriorRings.count(); ++i )
{
if ( ( !mInteriorRings.at( i ) && other.mInteriorRings.at( i ) ) ||
( mInteriorRings.at( i ) && !other.mInteriorRings.at( i ) ) )
return false;

if ( mInteriorRings.at( i ) && other.mInteriorRings.at( i ) &&
*mInteriorRings.at( i ) != *other.mInteriorRings.at( i ) )
return false;
}

return true;
}

bool QgsPolygonV2::operator!=( const QgsPolygonV2 &other ) const
{
return !operator==( other );
}

QString QgsPolygonV2::geometryType() const
{
return QStringLiteral( "Polygon" );
@@ -32,9 +32,6 @@ class CORE_EXPORT QgsPolygonV2: public QgsCurvePolygon
public:
QgsPolygonV2();

bool operator==( const QgsPolygonV2 &other ) const;
bool operator!=( const QgsPolygonV2 &other ) const;

QString geometryType() const override;
QgsPolygonV2 *clone() const override SIP_FACTORY;
void clear() override;

0 comments on commit f387210

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