Skip to content

Commit 0c7df17

Browse files
committedMay 29, 2018
Optimise QgsCurve::asQPolygonF for linestring geometries
1 parent 3ba7c0b commit 0c7df17

File tree

5 files changed

+19
-2
lines changed

5 files changed

+19
-2
lines changed
 

‎python/core/auto_generated/geometry/qgscurve.sip.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ Returns the y-coordinate of the specified node in the line string.
177177
:return: y-coordinate of node, or 0.0 if index is out of bounds
178178
%End
179179

180-
QPolygonF asQPolygonF() const;
180+
virtual QPolygonF asQPolygonF() const;
181181
%Docstring
182182
Returns a QPolygonF representing the points.
183183
%End

‎python/core/auto_generated/geometry/qgslinestring.sip.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ segment in the line.
216216

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

219+
virtual QPolygonF asQPolygonF() const;
219220

220221
virtual bool fromWkb( QgsConstWkbPtr &wkb );
221222

‎src/core/geometry/qgscurve.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ class CORE_EXPORT QgsCurve: public QgsAbstractGeometry
164164
/**
165165
* Returns a QPolygonF representing the points.
166166
*/
167-
QPolygonF asQPolygonF() const;
167+
virtual QPolygonF asQPolygonF() const;
168168

169169
/**
170170
* Returns the straight distance of the curve, i.e. the direct/euclidean distance

‎src/core/geometry/qgslinestring.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,21 @@ bool QgsLineString::removeDuplicateNodes( double epsilon, bool useZValues )
274274
return result;
275275
}
276276

277+
QPolygonF QgsLineString::asQPolygonF() const
278+
{
279+
const int nb = mX.size();
280+
QPolygonF points( nb );
281+
282+
const double *x = mX.constData();
283+
const double *y = mY.constData();
284+
QPointF *dest = points.data();
285+
for ( int i = 0; i < nb; ++i )
286+
{
287+
*dest++ = QPointF( *x++, *y++ );
288+
}
289+
return points;
290+
}
291+
277292
bool QgsLineString::fromWkb( QgsConstWkbPtr &wkbPtr )
278293
{
279294
if ( !wkbPtr )

‎src/core/geometry/qgslinestring.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ class CORE_EXPORT QgsLineString: public QgsCurve
210210
bool isEmpty() const override;
211211
QgsLineString *snappedToGrid( double hSpacing, double vSpacing, double dSpacing = 0, double mSpacing = 0 ) const override SIP_FACTORY;
212212
bool removeDuplicateNodes( double epsilon = 4 * DBL_EPSILON, bool useZValues = false ) override;
213+
virtual QPolygonF asQPolygonF() const override;
213214

214215
bool fromWkb( QgsConstWkbPtr &wkb ) override;
215216
bool fromWkt( const QString &wkt ) override;

0 commit comments

Comments
 (0)
Please sign in to comment.