Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Adds setMValueFromPoints
  • Loading branch information
lbartoletti authored and nyalldawson committed Apr 29, 2021
1 parent 62a09aa commit 9e81011
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 0 deletions.
13 changes: 13 additions & 0 deletions python/core/auto_generated/geometry/qgsgeometryutils.sip.in
Expand Up @@ -757,6 +757,19 @@ A Z dimension is added to ``point`` if one of the point in the list
.. versionadded:: 3.0
%End

static bool setMValueFromPoints( const QgsPointSequence &points, QgsPoint &point );
%Docstring
A M dimension is added to ``point`` if one of the point in the list
``points`` is in 3D. Moreover, the M 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 M dimension and value.

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

.. versionadded:: 3.20
%End


static bool angleBisector( double aX, double aY, double bX, double bY, double cX, double cY, double dX, double dY,
double &pointX /Out/, double &pointY /Out/, double &angle /Out/ ) /HoldGIL/;
Expand Down
22 changes: 22 additions & 0 deletions src/core/geometry/qgsgeometryutils.cpp
Expand Up @@ -254,6 +254,8 @@ bool QgsGeometryUtils::lineIntersection( const QgsPoint &p1, QgsVector v1, const

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

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

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

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

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

for ( const QgsPoint &pt : points )
{
if ( pt.isMeasure() )
{
point.convertTo( QgsWkbTypes::addM( point.wkbType() ) );
point.setM( pt.m() );
rc = true;
break;
}
}

return rc;
}

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

/**
* A M dimension is added to \a point if one of the point in the list
* \a points is in 3D. Moreover, the M 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 M dimension and value.
* \returns TRUE if the point is updated, FALSE otherwise
*
* \since QGIS 3.20
*/
static bool setMValueFromPoints( 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 9e81011

Please sign in to comment.