Skip to content

Commit

Permalink
Merge pull request #8913 from m-kuhn/fix_geometrycollection_equality
Browse files Browse the repository at this point in the history
Fix QgsGeometryCollection (and subclasses) `equal`
  • Loading branch information
m-kuhn committed Jan 21, 2019
2 parents 6584fb2 + 1be40f5 commit 69b199a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
15 changes: 13 additions & 2 deletions src/core/geometry/qgsgeometrycollection.cpp
Expand Up @@ -78,8 +78,19 @@ bool QgsGeometryCollection::operator==( const QgsAbstractGeometry &other ) const

for ( int i = 0; i < mGeometries.count(); ++i )
{
if ( mGeometries.at( i ) != otherCollection->mGeometries.at( i ) )
return false;
QgsAbstractGeometry *g1 = mGeometries.at( i );
QgsAbstractGeometry *g2 = otherCollection->mGeometries.at( i );

// Quick check if the geometries are exactly the same
if ( g1 != g2 )
{
if ( !g1 || !g2 )
return false;

// Slower check, compare the contents of the geometries
if ( *g1 != *g2 )
return false;
}
}

return true;
Expand Down
6 changes: 5 additions & 1 deletion tests/src/core/testqgsgeometry.cpp
Expand Up @@ -14798,18 +14798,22 @@ void TestQgsGeometry::geometryCollection()
QgsMultiPoint mp;
QgsMultiLineString ml;
QVERIFY( mp != ml );
QgsMultiLineString ml2;
part.setPoints( QgsPointSequence() << QgsPoint( QgsWkbTypes::PointZ, 0, 0, 1 )
<< QgsPoint( QgsWkbTypes::PointZ, 0, 10, 2 ) << QgsPoint( QgsWkbTypes::PointZ, 10, 10, 3 )
<< QgsPoint( QgsWkbTypes::PointZ, 10, 0, 4 ) << QgsPoint( QgsWkbTypes::PointZ, 0, 0, 1 ) );
ml.addGeometry( part.clone() );
QgsMultiLineString ml2;
QVERIFY( ml != ml2 );
part.setPoints( QgsPointSequence() << QgsPoint( QgsWkbTypes::PointZ, 1, 1, 1 )
<< QgsPoint( QgsWkbTypes::PointZ, 0, 10, 2 ) << QgsPoint( QgsWkbTypes::PointZ, 10, 10, 3 )
<< QgsPoint( QgsWkbTypes::PointZ, 10, 0, 4 ) << QgsPoint( QgsWkbTypes::PointZ, 0, 0, 1 ) );
ml2.addGeometry( part.clone() );
QVERIFY( ml != ml2 );

QgsMultiLineString ml3;
ml3.addGeometry( part.clone() );
QVERIFY( ml2 == ml3 );

//toCurveType
std::unique_ptr< QgsGeometryCollection > curveType( c12.toCurveType() );
QCOMPARE( curveType->wkbType(), QgsWkbTypes::GeometryCollection );
Expand Down

0 comments on commit 69b199a

Please sign in to comment.