Skip to content
Permalink
Browse files
rewrite test
  • Loading branch information
lbartoletti authored and nyalldawson committed Jun 9, 2021
1 parent ba409e0 commit 85345ee12b2ef8cc093e6dea5dcfb3834fd03b28
Showing with 65 additions and 10 deletions.
  1. +65 −10 tests/src/core/testqgsgeometryutils.cpp
@@ -88,8 +88,8 @@ class TestQgsGeometryUtils: public QObject
void testClosestSideOfRectangle();
void transferFirstZValueToPoint();
void transferFirstMValueToPoint();
void transferFirstZOrMValueToPoint();
void transferFirstZOrMValueToPoint_iterator();
void transferFirstZOrMValueToPoint_qgspointsequence();
void transferFirstZOrMValueToPoint_qgsgeometry();
};


@@ -1673,52 +1673,107 @@ void TestQgsGeometryUtils::transferFirstMValueToPoint()
QCOMPARE( pointZ.m(), 5.0 );
}

void TestQgsGeometryUtils::transferFirstZOrMValueToPoint()
void TestQgsGeometryUtils::transferFirstZOrMValueToPoint_qgspointsequence()
{
QgsPoint point( 1, 2 );
QgsPointSequence points;

// Type: Point
bool ret = QgsGeometryUtils::transferFirstZOrMValueToPoint( QgsPointSequence() << QgsPoint( 0, 2 ), point );
points.clear();
points << QgsPoint( 0, 2 );
// iterator
bool ret = QgsGeometryUtils::transferFirstZOrMValueToPoint( points, point );
QCOMPARE( ret, false );
// QgsPointSequence
point = QgsPoint( 1, 2 );
ret = QgsGeometryUtils::transferFirstZOrMValueToPoint( points.constBegin(), points.constEnd(), point );
QCOMPARE( ret, false );

// Type: PointZ
point = QgsPoint( 1, 2 );
ret = QgsGeometryUtils::transferFirstZOrMValueToPoint( QgsPointSequence() << QgsPoint( 0, 2, 4 ), point );
points.clear();
points << QgsPoint( 0, 2, 4 );
// iterator
ret = QgsGeometryUtils::transferFirstZOrMValueToPoint( points, point );
QCOMPARE( ret, true );
QCOMPARE( point.wkbType(), QgsWkbTypes::PointZ );
QCOMPARE( point.z(), 4.0 );
// QgsPointSequence
point = QgsPoint( 1, 2 );
ret = QgsGeometryUtils::transferFirstZOrMValueToPoint( points.constBegin(), points.constEnd(), point );
QCOMPARE( ret, true );
QCOMPARE( point.wkbType(), QgsWkbTypes::PointZ );
QCOMPARE( point.z(), 4.0 );

// Type: PointM
point = QgsPoint( 1, 2 );
ret = QgsGeometryUtils::transferFirstZOrMValueToPoint( QgsPointSequence() << QgsPoint( QgsWkbTypes::PointM, 0, 2, 0, 4 ), point );
points.clear();
points << QgsPoint( QgsWkbTypes::PointM, 0, 2, 0, 4 );
// iterator
ret = QgsGeometryUtils::transferFirstZOrMValueToPoint( points, point );
QCOMPARE( ret, true );
QCOMPARE( point.wkbType(), QgsWkbTypes::PointM );
QCOMPARE( point.m(), 4.0 );
// QgsPointSequence
point = QgsPoint( 1, 2 );
ret = QgsGeometryUtils::transferFirstZOrMValueToPoint( points.constBegin(), points.constEnd(), point );
QCOMPARE( ret, true );
QCOMPARE( point.wkbType(), QgsWkbTypes::PointM );
QCOMPARE( point.m(), 4.0 );

// Type: PointM
ret = QgsGeometryUtils::transferFirstZOrMValueToPoint( QgsPointSequence() << QgsPoint( QgsWkbTypes::PointM, 0, 2, 0, 5 ), point );
points.clear();
points << QgsPoint( QgsWkbTypes::PointM, 0, 2, 0, 5 );
// iterator
ret = QgsGeometryUtils::transferFirstZOrMValueToPoint( points, point );
QCOMPARE( ret, true );
QCOMPARE( point.wkbType(), QgsWkbTypes::PointM );
QCOMPARE( point.m(), 5.0 ); // now point.m == 5
// QgsPointSequence
point = QgsPoint( 1, 2 );
ret = QgsGeometryUtils::transferFirstZOrMValueToPoint( points.constBegin(), points.constEnd(), point );
QCOMPARE( ret, true );
QCOMPARE( point.wkbType(), QgsWkbTypes::PointM );
QCOMPARE( point.m(), 5.0 ); // now point.m == 5

// Add M to a PointZ
point = QgsPoint( 1, 2, 4 );
// Type: PointM
ret = QgsGeometryUtils::transferFirstZOrMValueToPoint( QgsPointSequence() << QgsPoint( QgsWkbTypes::PointM, 0, 2, 0, 5 ), point );
points.clear();
points << QgsPoint( QgsWkbTypes::PointM, 0, 2, 0, 5 );
// iterator
ret = QgsGeometryUtils::transferFirstZOrMValueToPoint( points, point );
QCOMPARE( ret, true );
QCOMPARE( point.wkbType(), QgsWkbTypes::PointZM );
QCOMPARE( point.m(), 5.0 );
// QgsPointSequence
point = QgsPoint( 1, 2, 4 );
ret = QgsGeometryUtils::transferFirstZOrMValueToPoint( points.constBegin(), points.constEnd(), point );
QCOMPARE( ret, true );
QCOMPARE( point.wkbType(), QgsWkbTypes::PointZM );
QCOMPARE( point.m(), 5.0 );

// Add Z from point1 and M from point2
point = QgsPoint( 1, 2 );
ret = QgsGeometryUtils::transferFirstZOrMValueToPoint( QgsPointSequence() << QgsPoint( 7, 8, 9 ) << QgsPoint( QgsWkbTypes::PointM, 0, 2, 0, 5 ), point );
points.clear();
points << QgsPoint( 7, 8, 9 ) << QgsPoint( QgsWkbTypes::PointM, 0, 2, 0, 5 );
// iterator
ret = QgsGeometryUtils::transferFirstZOrMValueToPoint( points, point );
QCOMPARE( ret, true );
QCOMPARE( point.wkbType(), QgsWkbTypes::PointZM );
QCOMPARE( point.z(), 9.0 );
QCOMPARE( point.m(), 5.0 );
// QgsPointSequence
point = QgsPoint( 1, 2 );
ret = QgsGeometryUtils::transferFirstZOrMValueToPoint( points.constBegin(), points.constEnd(), point );
QCOMPARE( ret, true );
QCOMPARE( point.wkbType(), QgsWkbTypes::PointZM );
QCOMPARE( point.z(), 9.0 );
QCOMPARE( point.m(), 5.0 );

}

void TestQgsGeometryUtils::transferFirstZOrMValueToPoint_iterator()
void TestQgsGeometryUtils::transferFirstZOrMValueToPoint_qgsgeometry()
{
QgsPoint point( 1, 2 );
QgsGeometry geom;

0 comments on commit 85345ee

Please sign in to comment.