Skip to content

Commit 80d0c33

Browse files
committed
add QgsRectangle::scaled which returns the scaled rectangle
facilitates one-lines
1 parent edc0303 commit 80d0c33

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

python/core/auto_generated/geometry/qgsrectangle.sip.in

+7
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,13 @@ Scale the rectangle around its center point.
183183
void scale( double scaleFactor, double centerX, double centerY );
184184
%Docstring
185185
Scale the rectangle around its center point.
186+
%End
187+
188+
QgsRectangle scaled( double scaleFactor, const QgsPointXY *center = 0 );
189+
%Docstring
190+
Scale the rectangle around its ``center`` point.
191+
192+
.. versionadded:: 3.4
186193
%End
187194

188195
void grow( double delta );

src/core/geometry/qgsrectangle.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,13 @@ QgsRectangle QgsRectangle::fromCenterAndSize( QgsPointXY center, double width, d
5858
return QgsRectangle( xMin, yMin, xMax, yMax );
5959
}
6060

61+
QgsRectangle QgsRectangle::scaled( double scaleFactor, const QgsPointXY *center )
62+
{
63+
QgsRectangle scaledRect = QgsRectangle( *this );
64+
scaledRect.scale( scaleFactor, center );
65+
return scaledRect;
66+
}
67+
6168
QgsRectangle QgsRectangle::operator-( const QgsVector v ) const
6269
{
6370
double xmin = mXmin - v.x();

src/core/geometry/qgsrectangle.h

+6
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,12 @@ class CORE_EXPORT QgsRectangle
261261
mYmax = centerY + newHeight / 2.0;
262262
}
263263

264+
/**
265+
* Scale the rectangle around its \a center point.
266+
* \since QGIS 3.4
267+
*/
268+
QgsRectangle scaled( double scaleFactor, const QgsPointXY *center = nullptr );
269+
264270
/**
265271
* Grows the rectangle in place by the specified amount.
266272
* \see buffered()

0 commit comments

Comments
 (0)