Skip to content

Commit

Permalink
Fix QgsGeometryCollection (and subclasses) equal
Browse files Browse the repository at this point in the history
The previous behavior was to check if all parts of the collection are exactly the same.
The new check will check if all parts are equal (same vertice count, same vertice order, same vertice values).
  • Loading branch information
m-kuhn committed Jan 20, 2019
1 parent ab4b38c commit f4a25eb
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/core/geometry/qgsgeometrycollection.cpp
Expand Up @@ -78,7 +78,8 @@ bool QgsGeometryCollection::operator==( const QgsAbstractGeometry &other ) const

for ( int i = 0; i < mGeometries.count(); ++i )
{
if ( mGeometries.at( i ) != otherCollection->mGeometries.at( i ) )
if ( mGeometries.at( i ) != otherCollection->mGeometries.at( i )
&& mGeometries.at( i )->operator!=( *otherCollection->mGeometries.at( i ) ) )
return false;
}

Expand Down
6 changes: 5 additions & 1 deletion tests/src/core/testqgsgeometry.cpp
Expand Up @@ -15023,18 +15023,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 f4a25eb

Please sign in to comment.