Skip to content

Commit

Permalink
Optimise QgsCurve::asQPolygonF for linestring geometries
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed May 29, 2018
1 parent 3ba7c0b commit 0c7df17
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 2 deletions.
2 changes: 1 addition & 1 deletion python/core/auto_generated/geometry/qgscurve.sip.in
Expand Up @@ -177,7 +177,7 @@ Returns the y-coordinate of the specified node in the line string.
:return: y-coordinate of node, or 0.0 if index is out of bounds
%End

QPolygonF asQPolygonF() const;
virtual QPolygonF asQPolygonF() const;
%Docstring
Returns a QPolygonF representing the points.
%End
Expand Down
1 change: 1 addition & 0 deletions python/core/auto_generated/geometry/qgslinestring.sip.in
Expand Up @@ -216,6 +216,7 @@ segment in the line.

virtual bool removeDuplicateNodes( double epsilon = 4 * DBL_EPSILON, bool useZValues = false );

virtual QPolygonF asQPolygonF() const;

virtual bool fromWkb( QgsConstWkbPtr &wkb );

Expand Down
2 changes: 1 addition & 1 deletion src/core/geometry/qgscurve.h
Expand Up @@ -164,7 +164,7 @@ class CORE_EXPORT QgsCurve: public QgsAbstractGeometry
/**
* Returns a QPolygonF representing the points.
*/
QPolygonF asQPolygonF() const;
virtual QPolygonF asQPolygonF() const;

/**
* Returns the straight distance of the curve, i.e. the direct/euclidean distance
Expand Down
15 changes: 15 additions & 0 deletions src/core/geometry/qgslinestring.cpp
Expand Up @@ -274,6 +274,21 @@ bool QgsLineString::removeDuplicateNodes( double epsilon, bool useZValues )
return result;
}

QPolygonF QgsLineString::asQPolygonF() const
{
const int nb = mX.size();
QPolygonF points( nb );

const double *x = mX.constData();
const double *y = mY.constData();
QPointF *dest = points.data();
for ( int i = 0; i < nb; ++i )
{
*dest++ = QPointF( *x++, *y++ );
}
return points;
}

bool QgsLineString::fromWkb( QgsConstWkbPtr &wkbPtr )
{
if ( !wkbPtr )
Expand Down
1 change: 1 addition & 0 deletions src/core/geometry/qgslinestring.h
Expand Up @@ -210,6 +210,7 @@ class CORE_EXPORT QgsLineString: public QgsCurve
bool isEmpty() const override;
QgsLineString *snappedToGrid( double hSpacing, double vSpacing, double dSpacing = 0, double mSpacing = 0 ) const override SIP_FACTORY;
bool removeDuplicateNodes( double epsilon = 4 * DBL_EPSILON, bool useZValues = false ) override;
virtual QPolygonF asQPolygonF() const override;

bool fromWkb( QgsConstWkbPtr &wkb ) override;
bool fromWkt( const QString &wkt ) override;
Expand Down

0 comments on commit 0c7df17

Please sign in to comment.