Skip to content
Permalink
Browse files

Add QgsClipper::clippedLine variant which accepts a QPolygonF line

input
  • Loading branch information
nyalldawson committed Sep 21, 2020
1 parent 1c1febc commit 9990b84bdbfdb85f28031127063b6c50cfc459c1
Showing with 27 additions and 6 deletions.
  1. +7 −0 python/core/auto_generated/qgsclipper.sip.in
  2. +13 −6 src/core/qgsclipper.cpp
  3. +7 −0 src/core/qgsclipper.h
@@ -75,6 +75,13 @@ Takes a linestring and clips it to clipExtent
:param clipExtent: clipping bounds

:return: clipped line coordinates
%End

static QPolygonF clippedLine( const QPolygonF &curve, const QgsRectangle &clipExtent );
%Docstring
Takes a ``curve`` and clips it to clipExtent.

.. versionadded:: 3.16
%End

};
@@ -40,7 +40,12 @@ const double QgsClipper::SMALL_NUM = 1e-12;

QPolygonF QgsClipper::clippedLine( const QgsCurve &curve, const QgsRectangle &clipExtent )
{
const int nPoints = curve.numPoints();
return clippedLine( curve.asQPolygonF(), clipExtent );
}

QPolygonF QgsClipper::clippedLine( const QPolygonF &curve, const QgsRectangle &clipExtent )
{
const int nPoints = curve.size();

double p0x, p0y, p1x = 0.0, p1y = 0.0; //original coordinates
double p1x_c, p1y_c; //clipped end coordinates
@@ -49,21 +54,22 @@ QPolygonF QgsClipper::clippedLine( const QgsCurve &curve, const QgsRectangle &cl
QPolygonF line;
line.reserve( nPoints + 1 );

const QPointF *curveData = curve.data();

for ( int i = 0; i < nPoints; ++i )
{
if ( i == 0 )
{
p1x = curve.xAt( i );
p1y = curve.yAt( i );
continue;
p1x = curveData->x();
p1y = curveData->y();
}
else
{
p0x = p1x;
p0y = p1y;

p1x = curve.xAt( i );
p1y = curve.yAt( i );
p1x = curveData->x();
p1y = curveData->y();

p1x_c = p1x;
p1y_c = p1y;
@@ -88,6 +94,7 @@ QPolygonF QgsClipper::clippedLine( const QgsCurve &curve, const QgsRectangle &cl
line << QPointF( p1x_c, p1y_c );
}
}
curveData++;
}
return line;
}
@@ -108,6 +108,13 @@ class CORE_EXPORT QgsClipper
*/
static QPolygonF clippedLine( const QgsCurve &curve, const QgsRectangle &clipExtent );

/**
* Takes a \a curve and clips it to clipExtent.
*
* \since QGIS 3.16
*/
static QPolygonF clippedLine( const QPolygonF &curve, const QgsRectangle &clipExtent );

private:

// Used when testing for equivalence to 0.0

0 comments on commit 9990b84

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