Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[API] Adds transferFirstZOrMValueToPoint
  • Loading branch information
lbartoletti authored and nyalldawson committed Jun 9, 2021
1 parent a06e4ec commit ad0e897
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 8 deletions.
38 changes: 30 additions & 8 deletions src/core/geometry/qgsgeometryutils.cpp
Expand Up @@ -252,10 +252,8 @@ 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::transferFirstZValueToPoint( QgsPointSequence() << p1 << p2, intersection );
// m support for intersection point
QgsGeometryUtils::transferFirstMValueToPoint( QgsPointSequence() << p1 << p2, intersection );
// z and m support for intersection point
QgsGeometryUtils::transferFirstZOrMValueToPoint( QgsPointSequence() << p1 << p2, intersection );

return true;
}
Expand Down Expand Up @@ -854,10 +852,8 @@ bool QgsGeometryUtils::segmentMidPoint( const QgsPoint &p1, const QgsPoint &p2,

result = possibleMidPoints.at( minDistIndex );

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

return true;
}
Expand Down Expand Up @@ -1810,6 +1806,32 @@ void QgsGeometryUtils::weightedPointInTriangle( const double aX, const double aY
pointY = rBy + rCy + aY;
}

bool QgsGeometryUtils::transferFirstZOrMValueToPoint( const QgsPointSequence &points, QgsPoint &point )
{
bool z_passed = false;
bool m_passed = false;

for ( const QgsPoint &pt : points )
{
if ( !m_passed && pt.isMeasure() )
{
point.convertTo( QgsWkbTypes::addM( point.wkbType() ) );
point.setM( pt.m() );
m_passed = true;
}
if ( !z_passed && pt.is3D() )
{
point.convertTo( QgsWkbTypes::addZ( point.wkbType() ) );
point.setZ( pt.z() );
z_passed = true;
}
if ( z_passed && m_passed )
break;
}

return z_passed || m_passed;
}

bool QgsGeometryUtils::transferFirstMValueToPoint( const QgsPointSequence &points, QgsPoint &point )
{
bool rc = false;
Expand Down
18 changes: 18 additions & 0 deletions src/core/geometry/qgsgeometryutils.h
Expand Up @@ -823,6 +823,24 @@ class CORE_EXPORT QgsGeometryUtils
*/
static bool transferFirstMValueToPoint( const QgsPointSequence &points, QgsPoint &point );

/*
* A Z or M dimension is added to \a point if one of the points in the list
* \a points contains Z or M value.
*
* This method is equivalent to successively calling Z and M but avoiding
* looping twice over the set of points.
*
* \param points List of points in which a Z or M point is searched.
* \param point The point to update with Z or M dimension and value.
* \returns TRUE if the point is updated, FALSE otherwise
*
* \warning This method does not copy the z or m value of the coordinate from the
* points whose z or m value is closest to the original x/y point, but only the first one found.
*
* \since QGIS 3.20
*/
static bool transferFirstZOrMValueToPoint( const QgsPointSequence &points, QgsPoint &point );

/**
* Returns the point (\a pointX, \a pointY) forming the bisector from segment (\a aX \a aY) (\a bX \a bY)
* and segment (\a bX, \a bY) (\a dX, \a dY).
Expand Down

0 comments on commit ad0e897

Please sign in to comment.