Skip to content

Commit

Permalink
use template for iterator
Browse files Browse the repository at this point in the history
  • Loading branch information
lbartoletti authored and nyalldawson committed Jun 9, 2021
1 parent 0845ae2 commit 36a3695
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 78 deletions.
57 changes: 0 additions & 57 deletions src/core/geometry/qgsgeometryutils.cpp
Expand Up @@ -1806,63 +1806,6 @@ void QgsGeometryUtils::weightedPointInTriangle( const double aX, const double aY
pointY = rBy + rCy + aY;
}

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

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

return zFound || mFound;
}

bool QgsGeometryUtils::transferFirstZOrMValueToPoint( const QgsGeometry &geom, QgsPoint &point )
{
return QgsGeometryUtils::transferFirstZOrMValueToPoint( geom.vertices_begin(), geom.vertices_end(), point );
}

bool QgsGeometryUtils::transferFirstZOrMValueToPoint( const QgsAbstractGeometry::vertex_iterator &verticesBegin, const QgsAbstractGeometry::vertex_iterator &verticesEnd, QgsPoint &point )
{
bool zFound = false;
bool mFound = false;

for ( QgsAbstractGeometry::vertex_iterator it = verticesBegin ; it != verticesEnd ; ++it )
{
if ( !mFound && ( *it ).isMeasure() )
{
point.convertTo( QgsWkbTypes::addM( point.wkbType() ) );
point.setM( ( *it ).m() );
mFound = true;
}
if ( !zFound && ( *it ).is3D() )
{
point.convertTo( QgsWkbTypes::addZ( point.wkbType() ) );
point.setZ( ( *it ).z() );
zFound = true;
}
if ( zFound && mFound )
break;
}

return zFound || mFound;
}

bool QgsGeometryUtils::transferFirstMValueToPoint( const QgsPointSequence &points, QgsPoint &point )
{
bool rc = false;
Expand Down
51 changes: 30 additions & 21 deletions src/core/geometry/qgsgeometryutils.h
Expand Up @@ -824,24 +824,6 @@ 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 );

/**
* 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.
Expand All @@ -860,7 +842,31 @@ class CORE_EXPORT QgsGeometryUtils
* \note Not available in Python bindings
* \since QGIS 3.20
*/
static bool transferFirstZOrMValueToPoint( const QgsAbstractGeometry::vertex_iterator &verticesBegin, const QgsAbstractGeometry::vertex_iterator &verticesEnd, QgsPoint &point ) SIP_SKIP;
template <class Iterator> static bool transferFirstZOrMValueToPoint( Iterator verticesBegin, Iterator verticesEnd, QgsPoint &point ) SIP_SKIP
{
bool zFound = false;
bool mFound = false;

for ( auto it = verticesBegin ; it != verticesEnd ; ++it )
{
if ( !mFound && ( *it ).isMeasure() )
{
point.convertTo( QgsWkbTypes::addM( point.wkbType() ) );
point.setM( ( *it ).m() );
mFound = true;
}
if ( !zFound && ( *it ).is3D() )
{
point.convertTo( QgsWkbTypes::addZ( point.wkbType() ) );
point.setZ( ( *it ).z() );
zFound = true;
}
if ( zFound && mFound )
break;
}

return zFound || mFound;
}

/**
* A Z or M dimension is added to \a point if one of the points in the list
Expand All @@ -869,7 +875,7 @@ class CORE_EXPORT QgsGeometryUtils
* This method is equivalent to successively calling Z and M but avoiding
* looping twice over the set of points.
*
* \param geom QgsGeometry in which a Z or M point is searched.
* \param points List of points in which a 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
*
Expand All @@ -878,7 +884,10 @@ class CORE_EXPORT QgsGeometryUtils
*
* \since QGIS 3.20
*/
static bool transferFirstZOrMValueToPoint( const QgsGeometry &geom, QgsPoint &point );
static bool transferFirstZOrMValueToPoint( const QgsPointSequence &points, QgsPoint &point )
{
return QgsGeometryUtils::transferFirstZOrMValueToPoint( points.constBegin(), points.constEnd(), point );
}

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

0 comments on commit 36a3695

Please sign in to comment.