Skip to content

Commit 5fb63c0

Browse files
committedApr 11, 2017
Make QgsRectangle protected members private
This class is not designed to be subclassed
1 parent a45e570 commit 5fb63c0

File tree

3 files changed

+114
-112
lines changed

3 files changed

+114
-112
lines changed
 

‎doc/api_break.dox

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1727,6 +1727,11 @@ QgsRasterRenderer
17271727

17281728
- MinMaxOrigin enum, minMaxOriginName(), minMaxOriginLabel(), minMaxOriginFromName() removed. Use minMaxOrigin() instead
17291729

1730+
QgsRectangle {#qgis_api_break_3_0_QgsRectangle}
1731+
------------
1732+
1733+
- The protected members were removed - QgsRectangle is not intended to be subclassed.
1734+
17301735
QgsRelation {#qgis_api_break_3_0_QgsRelation}
17311736
-----------
17321737

‎src/core/qgsrectangle.cpp

Lines changed: 91 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@
3030
#include "qgslogger.h"
3131

3232
QgsRectangle::QgsRectangle( double newxmin, double newymin, double newxmax, double newymax )
33-
: xmin( newxmin )
34-
, ymin( newymin )
35-
, xmax( newxmax )
36-
, ymax( newymax )
33+
: mXmin( newxmin )
34+
, mYmin( newymin )
35+
, mXmax( newxmax )
36+
, mYmax( newymax )
3737
{
3838
normalize();
3939
}
@@ -45,36 +45,36 @@ QgsRectangle::QgsRectangle( const QgsPoint &p1, const QgsPoint &p2 )
4545

4646
QgsRectangle::QgsRectangle( QRectF const &qRectF )
4747
{
48-
xmin = qRectF.topLeft().x();
49-
ymin = qRectF.topLeft().y();
50-
xmax = qRectF.bottomRight().x();
51-
ymax = qRectF.bottomRight().y();
48+
mXmin = qRectF.topLeft().x();
49+
mYmin = qRectF.topLeft().y();
50+
mXmax = qRectF.bottomRight().x();
51+
mYmax = qRectF.bottomRight().y();
5252
}
5353

5454
QgsRectangle::QgsRectangle( const QgsRectangle &r )
5555
{
56-
xmin = r.xMinimum();
57-
ymin = r.yMinimum();
58-
xmax = r.xMaximum();
59-
ymax = r.yMaximum();
56+
mXmin = r.xMinimum();
57+
mYmin = r.yMinimum();
58+
mXmax = r.xMaximum();
59+
mYmax = r.yMaximum();
6060
}
6161

6262

6363
void QgsRectangle::set( const QgsPoint &p1, const QgsPoint &p2 )
6464
{
65-
xmin = p1.x();
66-
xmax = p2.x();
67-
ymin = p1.y();
68-
ymax = p2.y();
65+
mXmin = p1.x();
66+
mXmax = p2.x();
67+
mYmin = p1.y();
68+
mYmax = p2.y();
6969
normalize();
7070
}
7171

7272
void QgsRectangle::set( double xmin_, double ymin_, double xmax_, double ymax_ )
7373
{
74-
xmin = xmin_;
75-
ymin = ymin_;
76-
xmax = xmax_;
77-
ymax = ymax_;
74+
mXmin = xmin_;
75+
mYmin = ymin_;
76+
mXmax = xmax_;
77+
mYmax = ymax_;
7878
normalize();
7979
}
8080

@@ -83,23 +83,23 @@ void QgsRectangle::normalize()
8383
if ( isNull() )
8484
return;
8585

86-
if ( xmin > xmax )
86+
if ( mXmin > mXmax )
8787
{
88-
std::swap( xmin, xmax );
88+
std::swap( mXmin, mXmax );
8989
}
90-
if ( ymin > ymax )
90+
if ( mYmin > mYmax )
9191
{
92-
std::swap( ymin, ymax );
92+
std::swap( mYmin, mYmax );
9393
}
9494
} // QgsRectangle::normalize()
9595

9696

9797
void QgsRectangle::setMinimal()
9898
{
99-
xmin = std::numeric_limits<double>::max();
100-
ymin = std::numeric_limits<double>::max();
101-
xmax = -std::numeric_limits<double>::max();
102-
ymax = -std::numeric_limits<double>::max();
99+
mXmin = std::numeric_limits<double>::max();
100+
mYmin = std::numeric_limits<double>::max();
101+
mXmax = -std::numeric_limits<double>::max();
102+
mYmax = -std::numeric_limits<double>::max();
103103
}
104104

105105
void QgsRectangle::scale( double scaleFactor, const QgsPoint *cp )
@@ -113,8 +113,8 @@ void QgsRectangle::scale( double scaleFactor, const QgsPoint *cp )
113113
}
114114
else
115115
{
116-
centerX = xmin + width() / 2;
117-
centerY = ymin + height() / 2;
116+
centerX = mXmin + width() / 2;
117+
centerY = mYmin + height() / 2;
118118
}
119119
scale( scaleFactor, centerX, centerY );
120120
}
@@ -123,18 +123,18 @@ void QgsRectangle::scale( double scaleFactor, double centerX, double centerY )
123123
{
124124
double newWidth = width() * scaleFactor;
125125
double newHeight = height() * scaleFactor;
126-
xmin = centerX - newWidth / 2.0;
127-
xmax = centerX + newWidth / 2.0;
128-
ymin = centerY - newHeight / 2.0;
129-
ymax = centerY + newHeight / 2.0;
126+
mXmin = centerX - newWidth / 2.0;
127+
mXmax = centerX + newWidth / 2.0;
128+
mYmin = centerY - newHeight / 2.0;
129+
mYmax = centerY + newHeight / 2.0;
130130
}
131131

132132
void QgsRectangle::grow( double delta )
133133
{
134-
xmin -= delta;
135-
xmax += delta;
136-
ymin -= delta;
137-
ymax += delta;
134+
mXmin -= delta;
135+
mXmax += delta;
136+
mYmin -= delta;
137+
mYmax += delta;
138138
}
139139

140140
void QgsRectangle::include( const QgsPoint &p )
@@ -151,7 +151,7 @@ void QgsRectangle::include( const QgsPoint &p )
151151

152152
QgsRectangle QgsRectangle::buffer( double width )
153153
{
154-
return QgsRectangle( xmin - width, ymin - width, xmax + width, ymax + width );
154+
return QgsRectangle( mXmin - width, mYmin - width, mXmax + width, mYmax + width );
155155
}
156156

157157
QgsRectangle QgsRectangle::intersect( const QgsRectangle *rect ) const
@@ -163,35 +163,35 @@ QgsRectangle QgsRectangle::intersect( const QgsRectangle *rect ) const
163163
return intersection;
164164
}
165165

166-
intersection.setXMinimum( xmin > rect->xMinimum() ? xmin : rect->xMinimum() );
167-
intersection.setXMaximum( xmax < rect->xMaximum() ? xmax : rect->xMaximum() );
168-
intersection.setYMinimum( ymin > rect->yMinimum() ? ymin : rect->yMinimum() );
169-
intersection.setYMaximum( ymax < rect->yMaximum() ? ymax : rect->yMaximum() );
166+
intersection.setXMinimum( mXmin > rect->xMinimum() ? mXmin : rect->xMinimum() );
167+
intersection.setXMaximum( mXmax < rect->xMaximum() ? mXmax : rect->xMaximum() );
168+
intersection.setYMinimum( mYmin > rect->yMinimum() ? mYmin : rect->yMinimum() );
169+
intersection.setYMaximum( mYmax < rect->yMaximum() ? mYmax : rect->yMaximum() );
170170
return intersection;
171171
}
172172

173173
bool QgsRectangle::intersects( const QgsRectangle &rect ) const
174174
{
175-
double x1 = ( xmin > rect.xmin ? xmin : rect.xmin );
176-
double x2 = ( xmax < rect.xmax ? xmax : rect.xmax );
175+
double x1 = ( mXmin > rect.mXmin ? mXmin : rect.mXmin );
176+
double x2 = ( mXmax < rect.mXmax ? mXmax : rect.mXmax );
177177
if ( x1 > x2 )
178178
return false;
179-
double y1 = ( ymin > rect.ymin ? ymin : rect.ymin );
180-
double y2 = ( ymax < rect.ymax ? ymax : rect.ymax );
179+
double y1 = ( mYmin > rect.mYmin ? mYmin : rect.mYmin );
180+
double y2 = ( mYmax < rect.mYmax ? mYmax : rect.mYmax );
181181
if ( y1 > y2 )
182182
return false;
183183
return true;
184184
}
185185

186186
bool QgsRectangle::contains( const QgsRectangle &rect ) const
187187
{
188-
return ( rect.xmin >= xmin && rect.xmax <= xmax && rect.ymin >= ymin && rect.ymax <= ymax );
188+
return ( rect.mXmin >= mXmin && rect.mXmax <= mXmax && rect.mYmin >= mYmin && rect.mYmax <= mYmax );
189189
}
190190

191191
bool QgsRectangle::contains( const QgsPoint &p ) const
192192
{
193-
return xmin <= p.x() && p.x() <= xmax &&
194-
ymin <= p.y() && p.y() <= ymax;
193+
return mXmin <= p.x() && p.x() <= mXmax &&
194+
mYmin <= p.y() && p.y() <= mYmax;
195195
}
196196

197197
void QgsRectangle::combineExtentWith( const QgsRectangle &rect )
@@ -200,11 +200,11 @@ void QgsRectangle::combineExtentWith( const QgsRectangle &rect )
200200
*this = rect;
201201
else
202202
{
203-
xmin = ( ( xmin < rect.xMinimum() ) ? xmin : rect.xMinimum() );
204-
xmax = ( ( xmax > rect.xMaximum() ) ? xmax : rect.xMaximum() );
203+
mXmin = ( ( mXmin < rect.xMinimum() ) ? mXmin : rect.xMinimum() );
204+
mXmax = ( ( mXmax > rect.xMaximum() ) ? mXmax : rect.xMaximum() );
205205

206-
ymin = ( ( ymin < rect.yMinimum() ) ? ymin : rect.yMinimum() );
207-
ymax = ( ( ymax > rect.yMaximum() ) ? ymax : rect.yMaximum() );
206+
mYmin = ( ( mYmin < rect.yMinimum() ) ? mYmin : rect.yMinimum() );
207+
mYmax = ( ( mYmax > rect.yMaximum() ) ? mYmax : rect.yMaximum() );
208208
}
209209

210210
}
@@ -215,32 +215,32 @@ void QgsRectangle::combineExtentWith( double x, double y )
215215
*this = QgsRectangle( x, y, x, y );
216216
else
217217
{
218-
xmin = ( ( xmin < x ) ? xmin : x );
219-
xmax = ( ( xmax > x ) ? xmax : x );
218+
mXmin = ( ( mXmin < x ) ? mXmin : x );
219+
mXmax = ( ( mXmax > x ) ? mXmax : x );
220220

221-
ymin = ( ( ymin < y ) ? ymin : y );
222-
ymax = ( ( ymax > y ) ? ymax : y );
221+
mYmin = ( ( mYmin < y ) ? mYmin : y );
222+
mYmax = ( ( mYmax > y ) ? mYmax : y );
223223
}
224224
}
225225

226226
bool QgsRectangle::isEmpty() const
227227
{
228-
return xmax <= xmin || ymax <= ymin;
228+
return mXmax <= mXmin || mYmax <= mYmin;
229229
}
230230

231231
bool QgsRectangle::isNull() const
232232
{
233233
// rectangle created QgsRectangle() or with rect.setMinimal() ?
234-
return ( qgsDoubleNear( xmin, 0.0 ) && qgsDoubleNear( xmax, 0.0 ) && qgsDoubleNear( ymin, 0.0 ) && qgsDoubleNear( ymax, 0.0 ) ) ||
235-
( qgsDoubleNear( xmin, std::numeric_limits<double>::max() ) && qgsDoubleNear( ymin, std::numeric_limits<double>::max() ) &&
236-
qgsDoubleNear( xmax, -std::numeric_limits<double>::max() ) && qgsDoubleNear( ymax, -std::numeric_limits<double>::max() ) );
234+
return ( qgsDoubleNear( mXmin, 0.0 ) && qgsDoubleNear( mXmax, 0.0 ) && qgsDoubleNear( mYmin, 0.0 ) && qgsDoubleNear( mYmax, 0.0 ) ) ||
235+
( qgsDoubleNear( mXmin, std::numeric_limits<double>::max() ) && qgsDoubleNear( mYmin, std::numeric_limits<double>::max() ) &&
236+
qgsDoubleNear( mXmax, -std::numeric_limits<double>::max() ) && qgsDoubleNear( mYmax, -std::numeric_limits<double>::max() ) );
237237
}
238238

239239
QString QgsRectangle::asWktCoordinates() const
240240
{
241241
QString rep =
242-
qgsDoubleToString( xmin ) + ' ' + qgsDoubleToString( ymin ) + ", " +
243-
qgsDoubleToString( xmax ) + ' ' + qgsDoubleToString( ymax );
242+
qgsDoubleToString( mXmin ) + ' ' + qgsDoubleToString( mYmin ) + ", " +
243+
qgsDoubleToString( mXmax ) + ' ' + qgsDoubleToString( mYmax );
244244

245245
return rep;
246246
}
@@ -249,19 +249,19 @@ QString QgsRectangle::asWktPolygon() const
249249
{
250250
QString rep =
251251
QStringLiteral( "POLYGON((" ) +
252-
qgsDoubleToString( xmin ) + ' ' + qgsDoubleToString( ymin ) + ", " +
253-
qgsDoubleToString( xmax ) + ' ' + qgsDoubleToString( ymin ) + ", " +
254-
qgsDoubleToString( xmax ) + ' ' + qgsDoubleToString( ymax ) + ", " +
255-
qgsDoubleToString( xmin ) + ' ' + qgsDoubleToString( ymax ) + ", " +
256-
qgsDoubleToString( xmin ) + ' ' + qgsDoubleToString( ymin ) +
252+
qgsDoubleToString( mXmin ) + ' ' + qgsDoubleToString( mYmin ) + ", " +
253+
qgsDoubleToString( mXmax ) + ' ' + qgsDoubleToString( mYmin ) + ", " +
254+
qgsDoubleToString( mXmax ) + ' ' + qgsDoubleToString( mYmax ) + ", " +
255+
qgsDoubleToString( mXmin ) + ' ' + qgsDoubleToString( mYmax ) + ", " +
256+
qgsDoubleToString( mXmin ) + ' ' + qgsDoubleToString( mYmin ) +
257257
QStringLiteral( "))" );
258258

259259
return rep;
260260
}
261261

262262
QRectF QgsRectangle::toRectF() const
263263
{
264-
return QRectF( static_cast< qreal >( xmin ), static_cast< qreal >( ymin ), static_cast< qreal >( xmax - xmin ), static_cast< qreal >( ymax - ymin ) );
264+
return QRectF( static_cast< qreal >( mXmin ), static_cast< qreal >( mYmin ), static_cast< qreal >( mXmax - mXmin ), static_cast< qreal >( mYmax - mYmin ) );
265265
}
266266

267267
// Returns a string representation of form xmin,ymin : xmax,ymax. Coordinates will be truncated
@@ -287,10 +287,10 @@ QString QgsRectangle::toString( int precision ) const
287287
rep = QStringLiteral( "Empty" );
288288
else
289289
rep = QStringLiteral( "%1,%2 : %3,%4" )
290-
.arg( xmin, 0, 'f', precision )
291-
.arg( ymin, 0, 'f', precision )
292-
.arg( xmax, 0, 'f', precision )
293-
.arg( ymax, 0, 'f', precision );
290+
.arg( mXmin, 0, 'f', precision )
291+
.arg( mYmin, 0, 'f', precision )
292+
.arg( mXmax, 0, 'f', precision )
293+
.arg( mYmax, 0, 'f', precision );
294294

295295
QgsDebugMsgLevel( QString( "Extents : %1" ).arg( rep ), 4 );
296296

@@ -312,11 +312,11 @@ QString QgsRectangle::asPolygon() const
312312
// NOTE: a polygon isn't a polygon unless its closed. In the case of
313313
// a rectangle, that means 5 points (last == first)
314314
foo
315-
<< xmin << ' ' << ymin << ", "
316-
<< xmin << ' ' << ymax << ", "
317-
<< xmax << ' ' << ymax << ", "
318-
<< xmax << ' ' << ymin << ", "
319-
<< xmin << ' ' << ymin;
315+
<< mXmin << ' ' << mYmin << ", "
316+
<< mXmin << ' ' << mYmax << ", "
317+
<< mXmax << ' ' << mYmax << ", "
318+
<< mXmax << ' ' << mYmin << ", "
319+
<< mXmin << ' ' << mYmin;
320320

321321
return rep;
322322

@@ -342,10 +342,10 @@ QgsRectangle &QgsRectangle::operator=( const QgsRectangle &r )
342342
{
343343
if ( &r != this )
344344
{
345-
xmax = r.xMaximum();
346-
xmin = r.xMinimum();
347-
ymax = r.yMaximum();
348-
ymin = r.yMinimum();
345+
mXmax = r.xMaximum();
346+
mXmin = r.xMinimum();
347+
mYmax = r.yMaximum();
348+
mYmin = r.yMinimum();
349349
}
350350

351351
return *this;
@@ -366,11 +366,11 @@ void QgsRectangle::unionRect( const QgsRectangle &r )
366366

367367
bool QgsRectangle::isFinite() const
368368
{
369-
if ( qIsInf( xmin ) || qIsInf( ymin ) || qIsInf( xmax ) || qIsInf( ymax ) )
369+
if ( qIsInf( mXmin ) || qIsInf( mYmin ) || qIsInf( mXmax ) || qIsInf( mYmax ) )
370370
{
371371
return false;
372372
}
373-
if ( qIsNaN( xmin ) || qIsNaN( ymin ) || qIsNaN( xmax ) || qIsNaN( ymax ) )
373+
if ( qIsNaN( mXmin ) || qIsNaN( mYmin ) || qIsNaN( mXmax ) || qIsNaN( mYmax ) )
374374
{
375375
return false;
376376
}
@@ -380,12 +380,12 @@ bool QgsRectangle::isFinite() const
380380
void QgsRectangle::invert()
381381
{
382382
double tmp;
383-
tmp = xmin;
384-
xmin = ymin;
385-
ymin = tmp;
386-
tmp = xmax;
387-
xmax = ymax;
388-
ymax = tmp;
383+
tmp = mXmin;
384+
mXmin = mYmin;
385+
mYmin = tmp;
386+
tmp = mXmax;
387+
mXmax = mYmax;
388+
mYmax = tmp;
389389
}
390390

391391
QDataStream &operator<<( QDataStream &out, const QgsRectangle &rectangle )

‎src/core/qgsrectangle.h

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class CORE_EXPORT QgsRectangle
3737
{
3838
public:
3939
//! Constructor
40-
QgsRectangle( double xmin = 0, double ymin = 0, double xmax = 0, double ymax = 0 );
40+
QgsRectangle( double mXmin = 0, double mYmin = 0, double mXmax = 0, double mYmax = 0 );
4141
//! Construct a rectangle from two points. The rectangle is normalized after construction.
4242
QgsRectangle( const QgsPoint &p1, const QgsPoint &p2 );
4343
//! Construct a rectangle from a QRectF. The rectangle is normalized after construction.
@@ -51,7 +51,7 @@ class CORE_EXPORT QgsRectangle
5151
void set( const QgsPoint &p1, const QgsPoint &p2 );
5252
//! Set the rectangle from four points. The rectangle is
5353
//! normalised after construction.
54-
void set( double xmin, double ymin, double xmax, double ymax );
54+
void set( double mXmin, double mYmin, double mXmax, double mYmax );
5555
//! Set the minimum x value
5656
void setXMinimum( double x );
5757
//! Set the maximum x value
@@ -151,15 +151,12 @@ class CORE_EXPORT QgsRectangle
151151
//! swap x/y
152152
void invert();
153153

154-
protected:
154+
private:
155155

156-
// These are protected instead of private so that things like
157-
// the QgsPostGisBox3d can get at them.
158-
159-
double xmin;
160-
double ymin;
161-
double xmax;
162-
double ymax;
156+
double mXmin;
157+
double mYmin;
158+
double mXmax;
159+
double mYmax;
163160

164161
};
165162

@@ -174,57 +171,57 @@ inline QgsRectangle::~QgsRectangle()
174171

175172
inline void QgsRectangle::setXMinimum( double x )
176173
{
177-
xmin = x;
174+
mXmin = x;
178175
}
179176

180177
inline void QgsRectangle::setXMaximum( double x )
181178
{
182-
xmax = x;
179+
mXmax = x;
183180
}
184181

185182
inline void QgsRectangle::setYMinimum( double y )
186183
{
187-
ymin = y;
184+
mYmin = y;
188185
}
189186

190187
inline void QgsRectangle::setYMaximum( double y )
191188
{
192-
ymax = y;
189+
mYmax = y;
193190
}
194191

195192
inline double QgsRectangle::xMaximum() const
196193
{
197-
return xmax;
194+
return mXmax;
198195
}
199196

200197
inline double QgsRectangle::xMinimum() const
201198
{
202-
return xmin;
199+
return mXmin;
203200
}
204201

205202
inline double QgsRectangle::yMaximum() const
206203
{
207-
return ymax;
204+
return mYmax;
208205
}
209206

210207
inline double QgsRectangle::yMinimum() const
211208
{
212-
return ymin;
209+
return mYmin;
213210
}
214211

215212
inline double QgsRectangle::width() const
216213
{
217-
return xmax - xmin;
214+
return mXmax - mXmin;
218215
}
219216

220217
inline double QgsRectangle::height() const
221218
{
222-
return ymax - ymin;
219+
return mYmax - mYmin;
223220
}
224221

225222
inline QgsPoint QgsRectangle::center() const
226223
{
227-
return QgsPoint( xmin + width() / 2, ymin + height() / 2 );
224+
return QgsPoint( mXmin + width() / 2, mYmin + height() / 2 );
228225
}
229226
inline std::ostream &operator << ( std::ostream &os, const QgsRectangle &r )
230227
{

0 commit comments

Comments
 (0)
Please sign in to comment.