mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-14 00:07:35 -04:00
Add equality operators to QgsLineStringV2
This commit is contained in:
parent
6dfffc5f12
commit
d2bf8d8923
@ -14,6 +14,9 @@ class QgsLineStringV2: public QgsCurveV2
|
||||
QgsLineStringV2();
|
||||
~QgsLineStringV2();
|
||||
|
||||
bool operator==( const QgsLineStringV2& other ) const;
|
||||
bool operator!=( const QgsLineStringV2& other ) const;
|
||||
|
||||
/** Returns the specified point from inside the line string.
|
||||
* @param i index of point, starting at 0 for the first point
|
||||
*/
|
||||
|
@ -41,6 +41,35 @@ QgsLineStringV2::QgsLineStringV2(): QgsCurveV2()
|
||||
QgsLineStringV2::~QgsLineStringV2()
|
||||
{}
|
||||
|
||||
bool QgsLineStringV2::operator==( const QgsLineStringV2& other ) const
|
||||
{
|
||||
if ( mWkbType != other.mWkbType )
|
||||
return false;
|
||||
|
||||
if ( mX.count() != other.mX.count() )
|
||||
return false;
|
||||
|
||||
for ( int i = 0; i < mX.count(); ++i )
|
||||
{
|
||||
if ( !qgsDoubleNear( mX.at( i ), other.mX.at( i ) )
|
||||
|| !qgsDoubleNear( mY.at( i ), other.mY.at( i ) ) )
|
||||
return false;
|
||||
|
||||
if ( is3D() && !qgsDoubleNear( mZ.at( i ), other.mZ.at( i ) ) )
|
||||
return false;
|
||||
|
||||
if ( isMeasure() && !qgsDoubleNear( mM.at( i ), other.mM.at( i ) ) )
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool QgsLineStringV2::operator!=( const QgsLineStringV2& other ) const
|
||||
{
|
||||
return !operator==( other );
|
||||
}
|
||||
|
||||
QgsLineStringV2 *QgsLineStringV2::clone() const
|
||||
{
|
||||
return new QgsLineStringV2( *this );
|
||||
|
@ -39,6 +39,9 @@ class CORE_EXPORT QgsLineStringV2: public QgsCurveV2
|
||||
QgsLineStringV2();
|
||||
~QgsLineStringV2();
|
||||
|
||||
bool operator==( const QgsLineStringV2& other ) const;
|
||||
bool operator!=( const QgsLineStringV2& other ) const;
|
||||
|
||||
/** Returns the specified point from inside the line string.
|
||||
* @param i index of point, starting at 0 for the first point
|
||||
*/
|
||||
|
@ -1075,6 +1075,47 @@ void TestQgsGeometry::lineStringV2()
|
||||
QCOMPARE( l10.pointN( 1 ), QgsPointV2( QgsWKBTypes::Point25D, 31, 32, 33 ) );
|
||||
QCOMPARE( l10.pointN( 2 ), QgsPointV2( QgsWKBTypes::Point25D, 41, 42, 43 ) );
|
||||
|
||||
//equality
|
||||
QgsLineStringV2 e1;
|
||||
QgsLineStringV2 e2;
|
||||
QVERIFY( e1 == e2 );
|
||||
QVERIFY( !( e1 != e2 ) );
|
||||
e1.addVertex( QgsPointV2( 1, 2 ) );
|
||||
QVERIFY( !( e1 == e2 ) ); //different number of vertices
|
||||
QVERIFY( e1 != e2 );
|
||||
e2.addVertex( QgsPointV2( 1, 2 ) );
|
||||
QVERIFY( e1 == e2 );
|
||||
QVERIFY( !( e1 != e2 ) );
|
||||
e1.addVertex( QgsPointV2( 1 / 3.0, 4 / 3.0 ) );
|
||||
e2.addVertex( QgsPointV2( 2 / 6.0, 8 / 6.0 ) );
|
||||
QVERIFY( e1 == e2 ); //check non-integer equality
|
||||
QVERIFY( !( e1 != e2 ) );
|
||||
e1.addVertex( QgsPointV2( 7, 8 ) );
|
||||
e2.addVertex( QgsPointV2( 6, 9 ) );
|
||||
QVERIFY( !( e1 == e2 ) ); //different coordinates
|
||||
QVERIFY( e1 != e2 );
|
||||
QgsLineStringV2 e3;
|
||||
e3.setPoints( QList< QgsPointV2 >() << QgsPointV2( QgsWKBTypes::PointZ, 1, 2, 0 )
|
||||
<< QgsPointV2( QgsWKBTypes::PointZ, 1 / 3.0, 4 / 3.0, 0 )
|
||||
<< QgsPointV2( QgsWKBTypes::PointZ, 7, 8, 0 ) );
|
||||
QVERIFY( !( e1 == e3 ) ); //different dimension
|
||||
QVERIFY( e1 != e3 );
|
||||
QgsLineStringV2 e4;
|
||||
e4.setPoints( QList< QgsPointV2 >() << QgsPointV2( QgsWKBTypes::PointZ, 1, 2, 2 )
|
||||
<< QgsPointV2( QgsWKBTypes::PointZ, 1 / 3.0, 4 / 3.0, 3 )
|
||||
<< QgsPointV2( QgsWKBTypes::PointZ, 7, 8, 4 ) );
|
||||
QVERIFY( !( e3 == e4 ) ); //different z coordinates
|
||||
QVERIFY( e3 != e4 );
|
||||
QgsLineStringV2 e5;
|
||||
e5.setPoints( QList< QgsPointV2 >() << QgsPointV2( QgsWKBTypes::PointM, 1, 2, 0, 1 )
|
||||
<< QgsPointV2( QgsWKBTypes::PointM, 1 / 3.0, 4 / 3.0, 0, 2 )
|
||||
<< QgsPointV2( QgsWKBTypes::PointM, 7, 8, 0, 3 ) );
|
||||
QgsLineStringV2 e6;
|
||||
e6.setPoints( QList< QgsPointV2 >() << QgsPointV2( QgsWKBTypes::PointM, 1, 2, 0, 11 )
|
||||
<< QgsPointV2( QgsWKBTypes::PointM, 1 / 3.0, 4 / 3.0, 0, 12 )
|
||||
<< QgsPointV2( QgsWKBTypes::PointM, 7, 8, 0, 13 ) );
|
||||
QVERIFY( !( e5 == e6 ) ); //different m values
|
||||
QVERIFY( e5 != e6 );
|
||||
|
||||
//close/isClosed
|
||||
QgsLineStringV2 l11;
|
||||
|
Loading…
x
Reference in New Issue
Block a user