Skip to content
Permalink
Browse files

Add utility function to detect sharp corners

  • Loading branch information
nyalldawson committed Jul 24, 2020
1 parent ca5901b commit 0641f3f8b8a2464d35d43b00d8581ced7d54d8a5
@@ -734,6 +734,13 @@ from the end of the line.

May return an empty linestring if the substring is zero length.

.. versionadded:: 3.16
%End

static bool isSharpCorner( QPointF p1, QPointF p2, QPointF p3 );
%Docstring
Returns ``True`` if the angle formed by the line ``p1`` - ``p2`` - ``p3`` forms a "sharp" corner.

.. versionadded:: 3.16
%End

@@ -4156,6 +4156,15 @@ QPolygonF QgsSymbolLayerUtils::polylineSubstring( const QPolygonF &polyline, dou
return substringPoints;
}

bool QgsSymbolLayerUtils::isSharpCorner( QPointF p1, QPointF p2, QPointF p3 )
{
double vertexAngle = M_PI - ( std::atan2( p3.y() - p2.y(), p3.x() - p2.x() ) - std::atan2( p2.y() - p1.y(), p2.x() - p1.x() ) );
vertexAngle = QgsGeometryUtils::normalizedAngle( vertexAngle );

// extreme angles form more than 45 degree angle at a node
return vertexAngle < M_PI * 135.0 / 180.0 || vertexAngle > M_PI * 225.0 / 180.0;
}

QgsExpression *QgsSymbolLayerUtils::fieldOrExpressionToExpression( const QString &fieldOrExpression )
{
if ( fieldOrExpression.isEmpty() )
@@ -662,6 +662,13 @@ class CORE_EXPORT QgsSymbolLayerUtils
*/
static QPolygonF polylineSubstring( const QPolygonF &polyline, double startOffset, double endOffset );

/**
* Returns TRUE if the angle formed by the line \a p1 - \a p2 - \a p3 forms a "sharp" corner.
*
* \since QGIS 3.16
*/
static bool isSharpCorner( QPointF p1, QPointF p2, QPointF p3 );

/**
* Returns a new valid expression instance for given field or expression string.
* If the input is not a valid expression, it is assumed that it is a field name and gets properly quoted.

0 comments on commit 0641f3f

Please sign in to comment.
You can’t perform that action at this time.