Skip to content

Commit

Permalink
Move QgsPolygonV2 equality operators up to QgsCurvePolygon
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Sep 19, 2017
1 parent bb425e4 commit f387210
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 54 deletions.
15 changes: 13 additions & 2 deletions python/core/geometry/qgscurvepolygon.sip
Expand Up @@ -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();
Expand Down Expand Up @@ -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;


Expand Down
6 changes: 0 additions & 6 deletions python/core/geometry/qgspolygon.sip
Expand Up @@ -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/;
Expand Down
58 changes: 58 additions & 0 deletions src/core/geometry/qgscurvepolygon.cpp
Expand Up @@ -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 )

Expand Down Expand Up @@ -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 );
Expand Down Expand Up @@ -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 );
Expand Down
14 changes: 9 additions & 5 deletions src/core/geometry/qgscurvepolygon.h
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down
38 changes: 0 additions & 38 deletions src/core/geometry/qgspolygon.cpp
Expand Up @@ -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" );
Expand Down
3 changes: 0 additions & 3 deletions src/core/geometry/qgspolygon.h
Expand Up @@ -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;
Expand Down

0 comments on commit f387210

Please sign in to comment.