Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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
  • Loading branch information
nyalldawson committed Feb 11, 2018
1 parent 2cbcf74 commit 65827ad
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 7 deletions.
5 changes: 4 additions & 1 deletion python/core/geometry/qgsrectangle.sip.in
Expand Up @@ -26,7 +26,10 @@ Examples are storing a layer extent or the current view extent of a map
#include "qgsrectangle.h"
%End
public:
QgsRectangle( double xMin = 0, double yMin = 0, double xMax = 0, double yMax = 0 );

QgsRectangle(); // optimised constructor for null rectangle - no need to call normalize here

explicit QgsRectangle( double xMin, double yMin = 0, double xMax = 0, double yMax = 0 );
%Docstring
Constructor
%End
Expand Down
1 change: 1 addition & 0 deletions src/core/geometry/qgsrectangle.cpp
Expand Up @@ -32,6 +32,7 @@
#include "qgspolygon.h"
#include "qgslinestring.h"


QgsRectangle::QgsRectangle( double xMin, double yMin, double xMax, double yMax )
: mXmin( xMin )
, mYmin( yMin )
Expand Down
14 changes: 9 additions & 5 deletions src/core/geometry/qgsrectangle.h
Expand Up @@ -39,8 +39,12 @@ class QgsBox3d;
class CORE_EXPORT QgsRectangle
{
public:

//! Constructor for a null rectangle
QgsRectangle() = default; // optimised constructor for null rectangle - no need to call normalize here

//! Constructor
QgsRectangle( double xMin = 0, double yMin = 0, double xMax = 0, double yMax = 0 );
explicit QgsRectangle( double xMin, double yMin = 0, double xMax = 0, double yMax = 0 );
//! Construct a rectangle from two points. The rectangle is normalized after construction.
QgsRectangle( const QgsPointXY &p1, const QgsPointXY &p2 );
//! Construct a rectangle from a QRectF. The rectangle is normalized after construction.
Expand Down Expand Up @@ -332,10 +336,10 @@ class CORE_EXPORT QgsRectangle

private:

double mXmin;
double mYmin;
double mXmax;
double mYmax;
double mXmin = 0.0;
double mYmin = 0.0;
double mXmax = 0.0;
double mYmax = 0.0;

};

Expand Down
2 changes: 1 addition & 1 deletion src/providers/wfs/qgswfsshareddata.cpp
Expand Up @@ -1251,7 +1251,7 @@ QgsRectangle QgsWFSSingleFeatureRequest::getExtent()
getFeatureUrl.addQueryItem( QStringLiteral( "MAXFEATURES" ), QString::number( 1 ) );

if ( !sendGET( getFeatureUrl, true ) )
return -1;
return QgsRectangle();

const QByteArray &buffer = response();

Expand Down

0 comments on commit 65827ad

Please sign in to comment.