Skip to content

Commit

Permalink
qgscurvepolygon: Remove uneeded clearCache call in operator=
Browse files Browse the repository at this point in the history
Indeed `QgsSurface::operator=()` is already called. As,
`QgsSurface` does not override `operator=`,
`QgsAbstractGeometry::operator=()` is called. This operator calls the
`clear()` method which clears the exterior ring, the interior rings
and the cache.

(cherry picked from commit e450947)
  • Loading branch information
ptitjano authored and nyalldawson committed Oct 16, 2024
1 parent 4e4a3e4 commit 423f9d0
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/core/geometry/qgscurvepolygon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,11 @@ QgsCurvePolygon::QgsCurvePolygon( const QgsCurvePolygon &p )
mValidityFailureReason = p.mValidityFailureReason;
}

// cppcheck-suppress operatorEqVarError
QgsCurvePolygon &QgsCurvePolygon::operator=( const QgsCurvePolygon &p )
{
if ( &p != this )
{
clearCache();
QgsSurface::operator=( p );
if ( p.mExteriorRing )
{
Expand Down
37 changes: 26 additions & 11 deletions tests/src/core/geometry/testqgscurvepolygon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,22 +150,37 @@ void TestQgsCurvePolygon::testCopyConstructor()
QgsCurvePolygon poly2( poly1 );
QCOMPARE( poly1, poly2 );

QgsCircularString *ext = new QgsCircularString();
ext->setPoints( QgsPointSequence() << QgsPoint( Qgis::WkbType::PointZM, 0, 0, 1, 5 )
<< QgsPoint( Qgis::WkbType::PointZM, 0, 10, 2, 6 ) << QgsPoint( Qgis::WkbType::PointZM, 10, 10, 3, 7 )
<< QgsPoint( Qgis::WkbType::PointZM, 10, 0, 4, 8 ) << QgsPoint( Qgis::WkbType::PointZM, 0, 0, 1, 9 ) );
poly1.setExteriorRing( ext );

QgsCircularString *ring = new QgsCircularString();
ring->setPoints( QgsPointSequence() << QgsPoint( Qgis::WkbType::PointZM, 1, 1, 1, 2 )
<< QgsPoint( Qgis::WkbType::PointZM, 1, 9, 2, 3 ) << QgsPoint( Qgis::WkbType::PointZM, 9, 9, 3, 6 )
<< QgsPoint( Qgis::WkbType::PointZM, 9, 1, 4, 4 ) << QgsPoint( Qgis::WkbType::PointZM, 1, 1, 1, 7 ) );
poly1.addInteriorRing( ring );
QgsCircularString *ext1 = new QgsCircularString();
ext1->setPoints( QgsPointSequence() << QgsPoint( Qgis::WkbType::PointZM, 0, 0, 1, 5 )
<< QgsPoint( Qgis::WkbType::PointZM, 0, 10, 2, 6 ) << QgsPoint( Qgis::WkbType::PointZM, 10, 10, 3, 7 )
<< QgsPoint( Qgis::WkbType::PointZM, 10, 0, 4, 8 ) << QgsPoint( Qgis::WkbType::PointZM, 0, 0, 1, 9 ) );
poly1.setExteriorRing( ext1 );

QgsCircularString *ring1 = new QgsCircularString();
ring1->setPoints( QgsPointSequence() << QgsPoint( Qgis::WkbType::PointZM, 1, 1, 1, 2 )
<< QgsPoint( Qgis::WkbType::PointZM, 1, 9, 2, 3 ) << QgsPoint( Qgis::WkbType::PointZM, 9, 9, 3, 6 )
<< QgsPoint( Qgis::WkbType::PointZM, 9, 1, 4, 4 ) << QgsPoint( Qgis::WkbType::PointZM, 1, 1, 1, 7 ) );
poly1.addInteriorRing( ring1 );

QgsCurvePolygon poly3( poly1 );
QCOMPARE( poly1, poly3 );

QgsCurvePolygon poly4;
QgsCircularString *ext2 = new QgsCircularString();
ext2->setPoints( QgsPointSequence() << QgsPoint( Qgis::WkbType::PointZ, 0, 0, 1 )
<< QgsPoint( Qgis::WkbType::PointZ, 0, 10, 2 ) << QgsPoint( Qgis::WkbType::PointZ, 10, 10, 3 )
<< QgsPoint( Qgis::WkbType::PointZ, 10, 0, 4 ) << QgsPoint( Qgis::WkbType::PointZ, 0, 0, 1 ) );
poly4.setExteriorRing( ext2 );
QgsCircularString *ring2 = new QgsCircularString();
ring2->setPoints( QgsPointSequence() << QgsPoint( Qgis::WkbType::PointZ, 1, 1, 1 )
<< QgsPoint( Qgis::WkbType::PointZ, 1, 9, 2 ) << QgsPoint( Qgis::WkbType::PointZ, 9, 9, 3 )
<< QgsPoint( Qgis::WkbType::PointZ, 9, 1, 4 ) << QgsPoint( Qgis::WkbType::PointZ, 1, 1, 1 ) );
poly4.addInteriorRing( ring2 );
QVERIFY( poly4.exteriorRing() );
QCOMPARE( poly4.numInteriorRings(), 1 );
QVERIFY( poly4.interiorRing( 0 ) );
QVERIFY( poly2 != poly4 );

poly4 = poly2;
QCOMPARE( poly2, poly4 );
poly4 = poly1;
Expand Down

0 comments on commit 423f9d0

Please sign in to comment.