Skip to content
Permalink
Browse files

Make QgsLineString Z and M values NaN if unspecified

  • Loading branch information
m-kuhn committed Jun 26, 2017
1 parent 8e7e573 commit e7f50524b8a23f3b0537f75ccf0360abed0993d5
@@ -31,9 +31,12 @@ bool QgsCurve::isClosed() const
//don't consider M-coordinates when testing closedness
QgsPoint start = startPoint();
QgsPoint end = endPoint();
return ( qgsDoubleNear( start.x(), end.x(), 1E-8 ) &&
qgsDoubleNear( start.y(), end.y(), 1E-8 ) &&
qgsDoubleNear( start.z(), end.z(), 1E-8 ) );

bool closed = qgsDoubleNear( start.x(), end.x(), 1E-8 ) &&
qgsDoubleNear( start.y(), end.y(), 1E-8 );
if ( is3D() )
closed &= qgsDoubleNear( start.z(), end.z(), 1E-8 ) || ( qIsNaN( start.z() ) && qIsNaN( end.z() ) );
return closed;
}

bool QgsCurve::isRing() const
@@ -380,8 +380,8 @@ QgsPoint QgsLineString::pointN( int i ) const

double x = mX.at( i );
double y = mY.at( i );
double z = 0;
double m = 0;
double z = std::numeric_limits<double>::quiet_NaN();
double m = std::numeric_limits<double>::quiet_NaN();

bool hasZ = is3D();
if ( hasZ )
@@ -441,15 +441,15 @@ double QgsLineString::zAt( int index ) const
if ( index >= 0 && index < mZ.size() )
return mZ.at( index );
else
return 0.0;
return std::numeric_limits<double>::quiet_NaN();
}

double QgsLineString::mAt( int index ) const
{
if ( index >= 0 && index < mM.size() )
return mM.at( index );
else
return 0.0;
return std::numeric_limits<double>::quiet_NaN();
}

void QgsLineString::setXAt( int index, double x )
@@ -1317,8 +1317,8 @@ void TestQgsGeometry::lineString()
QCOMPARE( l9.zAt( 0 ), 3.0 );
QCOMPARE( l9.zAt( 1 ), 13.0 );
QCOMPARE( l9.zAt( 2 ), 23.0 );
QCOMPARE( l9.zAt( -1 ), 0.0 ); //out of range
QCOMPARE( l9.zAt( 11 ), 0.0 ); //out of range
QVERIFY( qIsNaN( l9.zAt( -1 ) ) ); //out of range
QVERIFY( qIsNaN( l9.zAt( 11 ) ) ); //out of range

l9.setZAt( 0, 53.0 );
QCOMPARE( l9.zAt( 0 ), 53.0 );
@@ -1330,8 +1330,8 @@ void TestQgsGeometry::lineString()
QCOMPARE( l9.mAt( 0 ), 4.0 );
QCOMPARE( l9.mAt( 1 ), 14.0 );
QCOMPARE( l9.mAt( 2 ), 24.0 );
QCOMPARE( l9.mAt( -1 ), 0.0 ); //out of range
QCOMPARE( l9.mAt( 11 ), 0.0 ); //out of range
QVERIFY( qIsNaN( l9.mAt( -1 ) ) ); //out of range
QVERIFY( qIsNaN( l9.mAt( 11 ) ) ); //out of range

l9.setMAt( 0, 54.0 );
QCOMPARE( l9.mAt( 0 ), 54.0 );
@@ -1346,8 +1346,8 @@ void TestQgsGeometry::lineString()
<< QgsPoint( QgsWkbTypes::PointM, 21, 22, 0, 24 ) );

//basically we just don't want these to crash
QCOMPARE( l9.zAt( 0 ), 0.0 );
QCOMPARE( l9.zAt( 1 ), 0.0 );
QVERIFY( qIsNaN( l9.zAt( 0 ) ) );
QVERIFY( qIsNaN( l9.zAt( 1 ) ) );
l9.setZAt( 0, 53.0 );
l9.setZAt( 1, 63.0 );

@@ -1357,8 +1357,8 @@ void TestQgsGeometry::lineString()
<< QgsPoint( 21, 22 ) );

//basically we just don't want these to crash
QCOMPARE( l9.mAt( 0 ), 0.0 );
QCOMPARE( l9.mAt( 1 ), 0.0 );
QVERIFY( qIsNaN( l9.mAt( 0 ) ) );
QVERIFY( qIsNaN( l9.mAt( 1 ) ) );
l9.setMAt( 0, 53.0 );
l9.setMAt( 1, 63.0 );

@@ -642,14 +642,14 @@ void TestQgsGeometryUtils::testClosestPoint()

QgsPoint pt1 = QgsGeometryUtils::closestPoint( linestringZ, QgsPoint( 1, 0 ) );
QGSCOMPARENEAR( pt1.z(), 1, 0.0001 );
// QVERIFY( qIsNaN( pt1.m() ) );
QVERIFY( qIsNaN( pt1.m() ) );

QgsLineString linestringM( QVector<QgsPoint>()
<< QgsPoint( 1, 1, std::numeric_limits<double>::quiet_NaN(), 1 )
<< QgsPoint( 1, 3, std::numeric_limits<double>::quiet_NaN(), 2 ) );

QgsPoint pt2 = QgsGeometryUtils::closestPoint( linestringM, QgsPoint( 1, 4 ) );
// QVERIFY( qIsNaN( pt2.z() ) );
QVERIFY( qIsNaN( pt2.z() ) );
QGSCOMPARENEAR( pt2.m(), 2, 0.0001 );

QgsLineString linestringZM( QVector<QgsPoint>()

0 comments on commit e7f5052

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