Skip to content

Commit

Permalink
Make QgsLineString Z and M values NaN if unspecified
Browse files Browse the repository at this point in the history
  • Loading branch information
m-kuhn committed Jun 26, 2017
1 parent 8e7e573 commit e7f5052
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 17 deletions.
9 changes: 6 additions & 3 deletions src/core/geometry/qgscurve.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions src/core/geometry/qgslinestring.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand Down Expand Up @@ -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 )
Expand Down
16 changes: 8 additions & 8 deletions tests/src/core/testqgsgeometry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand All @@ -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 );
Expand All @@ -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 );

Expand All @@ -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 );

Expand Down
4 changes: 2 additions & 2 deletions tests/src/core/testqgsgeometryutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>()
Expand Down

0 comments on commit e7f5052

Please sign in to comment.