Skip to content

Commit 22eddfd

Browse files
authoredSep 22, 2017
Merge pull request #5238 from nyalldawson/geometry_coverage
Geometry unit test coverage + fixes
2 parents a6b1c3e + cbca7c9 commit 22eddfd

File tree

10 files changed

+2962
-47
lines changed

10 files changed

+2962
-47
lines changed
 

‎python/core/geometry/qgspolygon.sip

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,10 @@ class QgsPolygonV2: QgsCurvePolygon
2828

2929
virtual void clear();
3030

31-
3231
virtual bool fromWkb( QgsConstWkbPtr &wkb );
3332

34-
35-
3633
virtual QByteArray asWkb() const;
3734

38-
3935
virtual QgsPolygonV2 *surfaceToPolygon() const /Factory/;
4036

4137

‎src/core/geometry/qgscompoundcurve.cpp

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ int QgsCompoundCurve::dimension() const
7373

7474
QgsCompoundCurve::QgsCompoundCurve( const QgsCompoundCurve &curve ): QgsCurve( curve )
7575
{
76-
mWkbType = QgsWkbTypes::CompoundCurve;
76+
mWkbType = curve.wkbType();
7777
for ( const QgsCurve *c : curve.mCurves )
7878
{
7979
mCurves.append( static_cast<QgsCurve *>( c->clone() ) );
@@ -385,7 +385,7 @@ QgsLineString *QgsCompoundCurve::curveToLine( double tolerance, SegmentationTole
385385

386386
const QgsCurve *QgsCompoundCurve::curveAt( int i ) const
387387
{
388-
if ( i >= mCurves.size() )
388+
if ( i < 0 || i >= mCurves.size() )
389389
{
390390
return nullptr;
391391
}
@@ -396,34 +396,41 @@ void QgsCompoundCurve::addCurve( QgsCurve *c )
396396
{
397397
if ( c )
398398
{
399-
mCurves.append( c );
400-
401-
if ( mWkbType == QgsWkbTypes::Unknown )
399+
if ( mCurves.empty() )
402400
{
403401
setZMTypeFromSubGeometry( c, QgsWkbTypes::CompoundCurve );
404402
}
405403

404+
mCurves.append( c );
405+
406406
if ( QgsWkbTypes::hasZ( mWkbType ) && !QgsWkbTypes::hasZ( c->wkbType() ) )
407407
{
408408
c->addZValue();
409409
}
410+
else if ( !QgsWkbTypes::hasZ( mWkbType ) && QgsWkbTypes::hasZ( c->wkbType() ) )
411+
{
412+
c->dropZValue();
413+
}
410414
if ( QgsWkbTypes::hasM( mWkbType ) && !QgsWkbTypes::hasM( c->wkbType() ) )
411415
{
412416
c->addMValue();
413417
}
418+
else if ( !QgsWkbTypes::hasM( mWkbType ) && QgsWkbTypes::hasM( c->wkbType() ) )
419+
{
420+
c->dropMValue();
421+
}
414422
clearCache();
415423
}
416424
}
417425

418426
void QgsCompoundCurve::removeCurve( int i )
419427
{
420-
if ( mCurves.size() - 1 < i )
428+
if ( i < 0 || i >= mCurves.size() )
421429
{
422430
return;
423431
}
424432

425-
delete ( mCurves.at( i ) );
426-
mCurves.removeAt( i );
433+
delete mCurves.takeAt( i );
427434
clearCache();
428435
}
429436

@@ -776,9 +783,9 @@ double QgsCompoundCurve::vertexAngle( QgsVertexId vertex ) const
776783
QgsCompoundCurve *QgsCompoundCurve::reversed() const
777784
{
778785
QgsCompoundCurve *clone = new QgsCompoundCurve();
779-
for ( QgsCurve *curve : mCurves )
786+
for ( int i = mCurves.count() - 1; i >= 0; --i )
780787
{
781-
QgsCurve *reversedCurve = curve->reversed();
788+
QgsCurve *reversedCurve = mCurves.at( i )->reversed();
782789
clone->addCurve( reversedCurve );
783790
}
784791
return clone;

‎src/core/geometry/qgscurvepolygon.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -626,12 +626,12 @@ void QgsCurvePolygon::removeInteriorRings( double minimumAllowedArea )
626626

627627
void QgsCurvePolygon::draw( QPainter &p ) const
628628
{
629+
if ( !mExteriorRing )
630+
return;
631+
629632
if ( mInteriorRings.empty() )
630633
{
631-
if ( mExteriorRing )
632-
{
633-
mExteriorRing->drawAsPolygon( p );
634-
}
634+
mExteriorRing->drawAsPolygon( p );
635635
}
636636
else
637637
{

‎src/core/geometry/qgspolygon.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,8 @@ class CORE_EXPORT QgsPolygonV2: public QgsCurvePolygon
3535
QString geometryType() const override;
3636
QgsPolygonV2 *clone() const override SIP_FACTORY;
3737
void clear() override;
38-
3938
bool fromWkb( QgsConstWkbPtr &wkb ) override;
40-
41-
// inherited: bool fromWkt( const QString &wkt );
42-
4339
QByteArray asWkb() const override;
44-
// inherited: QString asWkt( int precision = 17 ) const;
45-
// inherited: QDomElement asGML2( QDomDocument& doc, int precision = 17, const QString& ns = "gml" ) const;
46-
// inherited: QDomElement asGML3( QDomDocument& doc, int precision = 17, const QString& ns = "gml" ) const;
47-
// inherited: QString asJSON( int precision = 17 ) const;
48-
4940
QgsPolygonV2 *surfaceToPolygon() const override SIP_FACTORY;
5041

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

‎tests/src/core/testqgsgeometry.cpp

Lines changed: 2927 additions & 19 deletions
Large diffs are not rendered by default.

‎tests/src/python/test_qgsgeometry.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4304,7 +4304,20 @@ def testGeometryDraw(self):
43044304
'wkt': 'CircularString (20 30, 50 30, 50 90)',
43054305
'reference_image': 'circularstring',
43064306
'as_polygon_reference_image': 'circularstring_aspolygon',
4307-
'use_pen': True}
4307+
'use_pen': True},
4308+
{'name': 'CurvePolygon',
4309+
'wkt': 'CurvePolygon(CircularString (20 30, 50 30, 50 90, 10 50, 20 30))',
4310+
'reference_image': 'curvepolygon_circularstring',
4311+
'use_pen': False},
4312+
{'name': 'CurvePolygonInteriorRings',
4313+
'wkt': 'CurvePolygon(CircularString (20 30, 50 30, 50 90, 10 50, 20 30),LineString(30 45, 55 45, 30 75, 30 45))',
4314+
'reference_image': 'curvepolygon_circularstring_interiorrings',
4315+
'use_pen': False},
4316+
{'name': 'CompoundCurve',
4317+
'wkt': 'CompoundCurve(CircularString (20 30, 50 30, 50 90),LineString(50 90, 10 90))',
4318+
'reference_image': 'compoundcurve',
4319+
'use_pen': True,
4320+
'as_polygon_reference_image': 'compoundcurve_aspolygon', }
43084321
]
43094322

43104323
for test in tests:
Loading

0 commit comments

Comments
 (0)
Please sign in to comment.