Skip to content
Permalink
Browse files
deprecate and replace setZValueFromPoints by transferFirstZValuteToPoint
  • Loading branch information
lbartoletti authored and nyalldawson committed Apr 29, 2021
1 parent 95cff79 commit e837b6f5b54411c0d47acc70f9198d7fe009f903
@@ -761,6 +761,29 @@ A Z dimension is added to ``point`` if one of the point in the list


.. versionadded:: 3.0


.. deprecated:: QGIS 3.20
use transferFirstZValueToPoint( const :py:class:`QgsPointSequence` &points, :py:class:`QgsPoint` &point ) instead
%End

static bool transferFirstZValueToPoint( const QgsPointSequence &points, QgsPoint &point );
%Docstring
A Z dimension is added to ``point`` if one of the point in the list
``points`` is in 3D. Moreover, the Z value of ``point`` is updated with.

:param points: List of points in which a 3D point is searched.
:param point: The point to update with Z dimension and value.

:return: ``True`` if the point is updated, ``False`` otherwise

.. warning::

This method does not copy the z value of the coordinate from the
points whose z value is closest to the original x/y point, but only the first one found.


.. versionadded:: 3.20
%End

static bool transferFirstMValueToPoint( const QgsPointSequence &points, QgsPoint &point );
@@ -40,7 +40,7 @@ QgsCircle QgsCircle::from2Points( const QgsPoint &pt1, const QgsPoint &pt2 )
double azimuth = QgsGeometryUtils::lineAngle( pt1.x(), pt1.y(), pt2.x(), pt2.y() ) * 180.0 / M_PI;
double radius = pt1.distance( pt2 ) / 2.0;

QgsGeometryUtils::setZValueFromPoints( QgsPointSequence() << pt1 << pt2, center );
QgsGeometryUtils::transferFirstZValueToPoint( QgsPointSequence() << pt1 << pt2, center );

return QgsCircle( center, radius, azimuth );
}
@@ -141,7 +141,7 @@ QgsCircle QgsCircle::from3Points( const QgsPoint &pt1, const QgsPoint &pt2, cons
double bSlope = yDelta_b / xDelta_b;

// set z coordinate for center
QgsGeometryUtils::setZValueFromPoints( QgsPointSequence() << p1 << p2 << p3, center );
QgsGeometryUtils::transferFirstZValueToPoint( QgsPointSequence() << p1 << p2 << p3, center );

if ( ( std::fabs( xDelta_a ) <= epsilon ) && ( std::fabs( yDelta_b ) <= epsilon ) )
{
@@ -183,7 +183,7 @@ QgsCircle QgsCircle::fromCenterPoint( const QgsPoint &center, const QgsPoint &pt
double azimuth = QgsGeometryUtils::lineAngle( center.x(), center.y(), pt1.x(), pt1.y() ) * 180.0 / M_PI;

QgsPoint centerPt( center );
QgsGeometryUtils::setZValueFromPoints( QgsPointSequence() << center << pt1, centerPt );
QgsGeometryUtils::transferFirstZValueToPoint( QgsPointSequence() << center << pt1, centerPt );

return QgsCircle( centerPt, centerPt.distance( pt1 ), azimuth );
}
@@ -388,7 +388,7 @@ QgsCircle QgsCircle::fromExtent( const QgsPoint &pt1, const QgsPoint &pt2 )
}

QgsPoint center = QgsGeometryUtils::midpoint( pt1, pt2 );
QgsGeometryUtils::setZValueFromPoints( QgsPointSequence() << pt1 << pt2, center );
QgsGeometryUtils::transferFirstZValueToPoint( QgsPointSequence() << pt1 << pt2, center );

return QgsCircle( center, delta_x / 2.0, 0 );
}
@@ -57,7 +57,7 @@ QgsEllipse QgsEllipse::fromFoci( const QgsPoint &pt1, const QgsPoint &pt2, const
double axis_a = dist / 2.0;
double axis_b = std::sqrt( std::pow( axis_a, 2.0 ) - std::pow( dist_p1p2 / 2.0, 2.0 ) );

QgsGeometryUtils::setZValueFromPoints( QgsPointSequence() << pt1 << pt2 << pt3, center );
QgsGeometryUtils::transferFirstZValueToPoint( QgsPointSequence() << pt1 << pt2 << pt3, center );

return QgsEllipse( center, axis_a, axis_b, azimuth );
}
@@ -69,7 +69,7 @@ QgsEllipse QgsEllipse::fromExtent( const QgsPoint &pt1, const QgsPoint &pt2 )
double axis_b = std::fabs( pt2.y() - pt1.y() ) / 2.0;
double azimuth = 90.0;

QgsGeometryUtils::setZValueFromPoints( QgsPointSequence() << pt1 << pt2, center );
QgsGeometryUtils::transferFirstZValueToPoint( QgsPointSequence() << pt1 << pt2, center );

return QgsEllipse( center, axis_a, axis_b, azimuth );
}
@@ -81,7 +81,7 @@ QgsEllipse QgsEllipse::fromCenterPoint( const QgsPoint &center, const QgsPoint &
double azimuth = 90.0;

QgsPoint centerPt( center );
QgsGeometryUtils::setZValueFromPoints( QgsPointSequence() << center << pt1, centerPt );
QgsGeometryUtils::transferFirstZValueToPoint( QgsPointSequence() << center << pt1, centerPt );

return QgsEllipse( centerPt, axis_a, axis_b, azimuth );
}
@@ -96,7 +96,7 @@ QgsEllipse QgsEllipse::fromCenter2Points( const QgsPoint &center, const QgsPoint
double axis_b = center.distance( pp );

QgsPoint centerPt( center );
QgsGeometryUtils::setZValueFromPoints( QgsPointSequence() << center << pt1 << pt2, centerPt );
QgsGeometryUtils::transferFirstZValueToPoint( QgsPointSequence() << center << pt1 << pt2, centerPt );

return QgsEllipse( centerPt, axis_a, axis_b, azimuth );
}
@@ -253,7 +253,7 @@ bool QgsGeometryUtils::lineIntersection( const QgsPoint &p1, QgsVector v1, const
intersection = QgsPoint( p1.x() + v1.x() * k, p1.y() + v1.y() * k );

// z support for intersection point
QgsGeometryUtils::setZValueFromPoints( QgsPointSequence() << p1 << p2, intersection );
QgsGeometryUtils::transferFirstZValueToPoint( QgsPointSequence() << p1 << p2, intersection );
// m support for intersection point
QgsGeometryUtils::transferFirstMValueToPoint( QgsPointSequence() << p1 << p2, intersection );

@@ -855,7 +855,7 @@ bool QgsGeometryUtils::segmentMidPoint( const QgsPoint &p1, const QgsPoint &p2,
result = possibleMidPoints.at( minDistIndex );

// add z support if necessary
QgsGeometryUtils::setZValueFromPoints( QgsPointSequence() << p1 << p2, result );
QgsGeometryUtils::transferFirstZValueToPoint( QgsPointSequence() << p1 << p2, result );
// add m support if necessary
QgsGeometryUtils::transferFirstMValueToPoint( QgsPointSequence() << p1 << p2, result );

@@ -1828,7 +1828,7 @@ bool QgsGeometryUtils::transferFirstMValueToPoint( const QgsPointSequence &point
return rc;
}

bool QgsGeometryUtils::setZValueFromPoints( const QgsPointSequence &points, QgsPoint &point )
bool QgsGeometryUtils::transferFirstZValueToPoint( const QgsPointSequence &points, QgsPoint &point )
{
bool rc = false;

@@ -780,8 +780,28 @@ class CORE_EXPORT QgsGeometryUtils
* points whose z value is closest to the original x/y point, but only the first one found.
*
* \since QGIS 3.0
*
* \deprecated since QGIS 3.20 use transferFirstZValueToPoint( const QgsPointSequence &points, QgsPoint &point ) instead
*/
static bool setZValueFromPoints( const QgsPointSequence &points, QgsPoint &point )
{
return transferFirstZValueToPoint( points, point );
}

/**
* A Z dimension is added to \a point if one of the point in the list
* \a points is in 3D. Moreover, the Z value of \a point is updated with.
*
* \param points List of points in which a 3D point is searched.
* \param point The point to update with Z dimension and value.
* \returns TRUE if the point is updated, FALSE otherwise
*
* \warning This method does not copy the z value of the coordinate from the
* points whose z value is closest to the original x/y point, but only the first one found.
*
* \since QGIS 3.20
*/
static bool setZValueFromPoints( const QgsPointSequence &points, QgsPoint &point );
static bool transferFirstZValueToPoint( const QgsPointSequence &points, QgsPoint &point );

/**
* A M dimension is added to \a point if one of the points in the list
@@ -588,7 +588,7 @@ QgsPoint QgsTriangle::inscribedCenter() const

QgsPointSequence points;
points << vertexAt( 0 ) << vertexAt( 1 ) << vertexAt( 2 );
QgsGeometryUtils::setZValueFromPoints( points, center );
QgsGeometryUtils::transferFirstZValueToPoint( points, center );

return center;
}
@@ -85,7 +85,7 @@ class TestQgsGeometryUtils: public QObject
void testAngleBisector();
void testPerpendicularOffsetPoint();
void testClosestSideOfRectangle();
void setZValueFromPoints();
void transferFirstZValueToPoint();
void transferFirstMValueToPoint();
};

@@ -1604,34 +1604,34 @@ void TestQgsGeometryUtils::testClosestSideOfRectangle()
QCOMPARE( QgsGeometryUtils::closestSideOfRectangle( 16, -20, 10, -18, 14, -19.5 ), 5 );
}

void TestQgsGeometryUtils::setZValueFromPoints()
void TestQgsGeometryUtils::transferFirstZValueToPoint()
{
QgsPoint point( 1, 2 );

// Type: Point
bool ret = QgsGeometryUtils::setZValueFromPoints( QgsPointSequence() << QgsPoint( 0, 2 ), point );
bool ret = QgsGeometryUtils::transferFirstZValueToPoint( QgsPointSequence() << QgsPoint( 0, 2 ), point );
QCOMPARE( ret, false );

// Type: PointM
ret = QgsGeometryUtils::setZValueFromPoints( QgsPointSequence() << QgsPoint( QgsWkbTypes::PointM, 0, 2, 0, 4 ), point );
ret = QgsGeometryUtils::transferFirstZValueToPoint( QgsPointSequence() << QgsPoint( QgsWkbTypes::PointM, 0, 2, 0, 4 ), point );
QCOMPARE( ret, false );

// Type: PointZ
ret = QgsGeometryUtils::setZValueFromPoints( QgsPointSequence() << QgsPoint( 0, 2, 4 ), point );
ret = QgsGeometryUtils::transferFirstZValueToPoint( QgsPointSequence() << QgsPoint( 0, 2, 4 ), point );
QCOMPARE( ret, true );
QCOMPARE( point.wkbType(), QgsWkbTypes::PointZ );
QCOMPARE( point.z(), 4.0 );

// Type: PointZ
ret = QgsGeometryUtils::setZValueFromPoints( QgsPointSequence() << QgsPoint( 0, 2, 5 ), point );
ret = QgsGeometryUtils::transferFirstZValueToPoint( QgsPointSequence() << QgsPoint( 0, 2, 5 ), point );
QCOMPARE( ret, true );
QCOMPARE( point.wkbType(), QgsWkbTypes::PointZ );
QCOMPARE( point.z(), 5.0 ); // now point.z == 5. Shouldn't the current Z be left if the point is already of type PointZ?

// Add Z to a PointM
QgsPoint pointM( QgsWkbTypes::PointM, 1, 2, 0, 3 );
// Type: PointZ
ret = QgsGeometryUtils::setZValueFromPoints( QgsPointSequence() << QgsPoint( 0, 2, 4 ), pointM );
ret = QgsGeometryUtils::transferFirstZValueToPoint( QgsPointSequence() << QgsPoint( 0, 2, 4 ), pointM );
QCOMPARE( ret, true );
QCOMPARE( pointM.wkbType(), QgsWkbTypes::PointZM );
QCOMPARE( pointM.z(), 4.0 );

0 comments on commit e837b6f

Please sign in to comment.