Skip to content

Commit

Permalink
Merge pull request #5238 from nyalldawson/geometry_coverage
Browse files Browse the repository at this point in the history
Geometry unit test coverage + fixes
  • Loading branch information
nyalldawson committed Sep 22, 2017
2 parents a6b1c3e + cbca7c9 commit 22eddfd
Show file tree
Hide file tree
Showing 10 changed files with 2,962 additions and 47 deletions.
4 changes: 0 additions & 4 deletions python/core/geometry/qgspolygon.sip
Expand Up @@ -28,14 +28,10 @@ class QgsPolygonV2: QgsCurvePolygon

virtual void clear();


virtual bool fromWkb( QgsConstWkbPtr &wkb );



virtual QByteArray asWkb() const;


virtual QgsPolygonV2 *surfaceToPolygon() const /Factory/;


Expand Down
27 changes: 17 additions & 10 deletions src/core/geometry/qgscompoundcurve.cpp
Expand Up @@ -73,7 +73,7 @@ int QgsCompoundCurve::dimension() const

QgsCompoundCurve::QgsCompoundCurve( const QgsCompoundCurve &curve ): QgsCurve( curve )
{
mWkbType = QgsWkbTypes::CompoundCurve;
mWkbType = curve.wkbType();
for ( const QgsCurve *c : curve.mCurves )
{
mCurves.append( static_cast<QgsCurve *>( c->clone() ) );
Expand Down Expand Up @@ -385,7 +385,7 @@ QgsLineString *QgsCompoundCurve::curveToLine( double tolerance, SegmentationTole

const QgsCurve *QgsCompoundCurve::curveAt( int i ) const
{
if ( i >= mCurves.size() )
if ( i < 0 || i >= mCurves.size() )
{
return nullptr;
}
Expand All @@ -396,34 +396,41 @@ void QgsCompoundCurve::addCurve( QgsCurve *c )
{
if ( c )
{
mCurves.append( c );

if ( mWkbType == QgsWkbTypes::Unknown )
if ( mCurves.empty() )
{
setZMTypeFromSubGeometry( c, QgsWkbTypes::CompoundCurve );
}

mCurves.append( c );

if ( QgsWkbTypes::hasZ( mWkbType ) && !QgsWkbTypes::hasZ( c->wkbType() ) )
{
c->addZValue();
}
else if ( !QgsWkbTypes::hasZ( mWkbType ) && QgsWkbTypes::hasZ( c->wkbType() ) )
{
c->dropZValue();
}
if ( QgsWkbTypes::hasM( mWkbType ) && !QgsWkbTypes::hasM( c->wkbType() ) )
{
c->addMValue();
}
else if ( !QgsWkbTypes::hasM( mWkbType ) && QgsWkbTypes::hasM( c->wkbType() ) )
{
c->dropMValue();
}
clearCache();
}
}

void QgsCompoundCurve::removeCurve( int i )
{
if ( mCurves.size() - 1 < i )
if ( i < 0 || i >= mCurves.size() )
{
return;
}

delete ( mCurves.at( i ) );
mCurves.removeAt( i );
delete mCurves.takeAt( i );
clearCache();
}

Expand Down Expand Up @@ -776,9 +783,9 @@ double QgsCompoundCurve::vertexAngle( QgsVertexId vertex ) const
QgsCompoundCurve *QgsCompoundCurve::reversed() const
{
QgsCompoundCurve *clone = new QgsCompoundCurve();
for ( QgsCurve *curve : mCurves )
for ( int i = mCurves.count() - 1; i >= 0; --i )
{
QgsCurve *reversedCurve = curve->reversed();
QgsCurve *reversedCurve = mCurves.at( i )->reversed();
clone->addCurve( reversedCurve );
}
return clone;
Expand Down
8 changes: 4 additions & 4 deletions src/core/geometry/qgscurvepolygon.cpp
Expand Up @@ -626,12 +626,12 @@ void QgsCurvePolygon::removeInteriorRings( double minimumAllowedArea )

void QgsCurvePolygon::draw( QPainter &p ) const
{
if ( !mExteriorRing )
return;

if ( mInteriorRings.empty() )
{
if ( mExteriorRing )
{
mExteriorRing->drawAsPolygon( p );
}
mExteriorRing->drawAsPolygon( p );
}
else
{
Expand Down
9 changes: 0 additions & 9 deletions src/core/geometry/qgspolygon.h
Expand Up @@ -35,17 +35,8 @@ class CORE_EXPORT QgsPolygonV2: public QgsCurvePolygon
QString geometryType() const override;
QgsPolygonV2 *clone() const override SIP_FACTORY;
void clear() override;

bool fromWkb( QgsConstWkbPtr &wkb ) override;

// inherited: bool fromWkt( const QString &wkt );

QByteArray asWkb() const override;
// inherited: QString asWkt( int precision = 17 ) const;
// inherited: QDomElement asGML2( QDomDocument& doc, int precision = 17, const QString& ns = "gml" ) const;
// inherited: QDomElement asGML3( QDomDocument& doc, int precision = 17, const QString& ns = "gml" ) const;
// inherited: QString asJSON( int precision = 17 ) const;

QgsPolygonV2 *surfaceToPolygon() const override SIP_FACTORY;

/** Returns the geometry converted to the more generic curve type QgsCurvePolygon
Expand Down

0 comments on commit 22eddfd

Please sign in to comment.