Skip to content

Commit 65827ad

Browse files
committed
Provide an optimised constructor for a null QgsRectangle
This is used a lot, yet the current constructor calls the normalize() method which does a bunch of operations for no result. So instead provide a simple optimised null QgsRectangle constructor and save a lot of cycles. Refs #17809
1 parent 2cbcf74 commit 65827ad

File tree

4 files changed

+15
-7
lines changed

4 files changed

+15
-7
lines changed

python/core/geometry/qgsrectangle.sip.in

+4-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,10 @@ Examples are storing a layer extent or the current view extent of a map
2626
#include "qgsrectangle.h"
2727
%End
2828
public:
29-
QgsRectangle( double xMin = 0, double yMin = 0, double xMax = 0, double yMax = 0 );
29+
30+
QgsRectangle(); // optimised constructor for null rectangle - no need to call normalize here
31+
32+
explicit QgsRectangle( double xMin, double yMin = 0, double xMax = 0, double yMax = 0 );
3033
%Docstring
3134
Constructor
3235
%End

src/core/geometry/qgsrectangle.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include "qgspolygon.h"
3333
#include "qgslinestring.h"
3434

35+
3536
QgsRectangle::QgsRectangle( double xMin, double yMin, double xMax, double yMax )
3637
: mXmin( xMin )
3738
, mYmin( yMin )

src/core/geometry/qgsrectangle.h

+9-5
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,12 @@ class QgsBox3d;
3939
class CORE_EXPORT QgsRectangle
4040
{
4141
public:
42+
43+
//! Constructor for a null rectangle
44+
QgsRectangle() = default; // optimised constructor for null rectangle - no need to call normalize here
45+
4246
//! Constructor
43-
QgsRectangle( double xMin = 0, double yMin = 0, double xMax = 0, double yMax = 0 );
47+
explicit QgsRectangle( double xMin, double yMin = 0, double xMax = 0, double yMax = 0 );
4448
//! Construct a rectangle from two points. The rectangle is normalized after construction.
4549
QgsRectangle( const QgsPointXY &p1, const QgsPointXY &p2 );
4650
//! Construct a rectangle from a QRectF. The rectangle is normalized after construction.
@@ -332,10 +336,10 @@ class CORE_EXPORT QgsRectangle
332336

333337
private:
334338

335-
double mXmin;
336-
double mYmin;
337-
double mXmax;
338-
double mYmax;
339+
double mXmin = 0.0;
340+
double mYmin = 0.0;
341+
double mXmax = 0.0;
342+
double mYmax = 0.0;
339343

340344
};
341345

src/providers/wfs/qgswfsshareddata.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1251,7 +1251,7 @@ QgsRectangle QgsWFSSingleFeatureRequest::getExtent()
12511251
getFeatureUrl.addQueryItem( QStringLiteral( "MAXFEATURES" ), QString::number( 1 ) );
12521252

12531253
if ( !sendGET( getFeatureUrl, true ) )
1254-
return -1;
1254+
return QgsRectangle();
12551255

12561256
const QByteArray &buffer = response();
12571257

0 commit comments

Comments
 (0)