Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add tests for QgsGeometryUtils::closestPoint()
  • Loading branch information
m-kuhn committed Jun 26, 2017
1 parent 13775c2 commit 317fead
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions tests/src/core/testqgsgeometryutils.cpp
Expand Up @@ -55,6 +55,7 @@ class TestQgsGeometryUtils: public QObject
void testGradient();
void testCoefficients();
void testPerpendicularSegment();
void testClosestPoint();
};


Expand Down Expand Up @@ -633,5 +634,32 @@ void TestQgsGeometryUtils::testPerpendicularSegment()
QCOMPARE( line.pointN( 1 ), line_r.pointN( 1 ) );
}

void TestQgsGeometryUtils::testClosestPoint()
{
QgsLineString linestringZ( QVector<QgsPoint>()
<< QgsPoint( 1, 1, 1 )
<< QgsPoint( 1, 3, 2 ) );

QgsPoint pt1 = QgsGeometryUtils::closestPoint( linestringZ, QgsPoint( 1, 0 ) );
QGSCOMPARENEAR( pt1.z(), 1, 0.0001 );
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() ) );
QGSCOMPARENEAR( pt2.m(), 2, 0.0001 );

QgsLineString linestringZM( QVector<QgsPoint>()
<< QgsPoint( 1, 1, 1, 1 )
<< QgsPoint( 1, 3, 2, 2 ) );

QgsPoint pt3 = QgsGeometryUtils::closestPoint( linestringZM, QgsPoint( 2, 2 ) );
QGSCOMPARENEAR( pt3.z(), 1.5, 0.0001 );
QGSCOMPARENEAR( pt3.m(), 1.5, 0.0001 );
}

QGSTEST_MAIN( TestQgsGeometryUtils )
#include "testqgsgeometryutils.moc"

0 comments on commit 317fead

Please sign in to comment.