Skip to content
Permalink
Browse files

Merge pull request #8913 from m-kuhn/fix_geometrycollection_equality

Fix QgsGeometryCollection (and subclasses) `equal`
  • Loading branch information
m-kuhn committed Jan 21, 2019
2 parents 6584fb2 + 1be40f5 commit 69b199a9b551d34568051ce900417e0a8d207b40
Showing with 18 additions and 3 deletions.
  1. +13 −2 src/core/geometry/qgsgeometrycollection.cpp
  2. +5 −1 tests/src/core/testqgsgeometry.cpp
@@ -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;
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 );

0 comments on commit 69b199a

Please sign in to comment.
You can’t perform that action at this time.