Skip to content
Permalink
Browse files

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 65827adc7d399321dd736da06232e7dda503a3ad
@@ -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
@@ -32,6 +32,7 @@
#include "qgspolygon.h"
#include "qgslinestring.h"


QgsRectangle::QgsRectangle( double xMin, double yMin, double xMax, double yMax )
: mXmin( xMin )
, mYmin( yMin )
@@ -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.
@@ -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;

};

@@ -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();

0 comments on commit 65827ad

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