Skip to content
Permalink
Browse files

Add tests for QgsGeometryUtils::closestPoint()

  • Loading branch information
m-kuhn committed Jun 26, 2017
1 parent 13775c2 commit 317fead516837826dfc7610c7459ddb2420f9a0c
Showing with 28 additions and 0 deletions.
  1. +28 −0 tests/src/core/testqgsgeometryutils.cpp
@@ -55,6 +55,7 @@ class TestQgsGeometryUtils: public QObject
void testGradient();
void testCoefficients();
void testPerpendicularSegment();
void testClosestPoint();
};


@@ -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.
You can’t perform that action at this time.