Skip to content

Commit

Permalink
Update SIP file for QgsRectangle
Browse files Browse the repository at this point in the history
  • Loading branch information
Zverik authored and 3nids committed Jun 26, 2017
1 parent 7941759 commit 80bc6d2
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
28 changes: 28 additions & 0 deletions python/core/geometry/qgsrectangle.sip
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,34 @@ Copy constructor
Expand the rectangle so that covers both the original rectangle and the given point.
%End

QgsRectangle operator-( const QgsVector v ) const;
%Docstring
Returns a rectangle offset from this one in the direction of the reversed vector.
.. versionadded:: 3.0
:rtype: QgsRectangle
%End

QgsRectangle operator+( const QgsVector v ) const;
%Docstring
Returns a rectangle offset from this one in the direction of the vector.
.. versionadded:: 3.0
:rtype: QgsRectangle
%End

QgsRectangle &operator-=( const QgsVector v );
%Docstring
Moves this rectangle in the direction of the reversed vector.
.. versionadded:: 3.0
:rtype: QgsRectangle
%End

QgsRectangle &operator+=( const QgsVector v );
%Docstring
Moves this rectangle in the direction of the vector.
.. versionadded:: 3.0
:rtype: QgsRectangle
%End

bool isEmpty() const;
%Docstring
Returns true if the rectangle is empty.
Expand Down
11 changes: 10 additions & 1 deletion tests/src/python/test_qgsrectangle.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

import qgis # NOQA

from qgis.core import QgsRectangle, QgsPointXY
from qgis.core import QgsRectangle, QgsPointXY, QgsVector

from qgis.testing import start_app, unittest
from utilities import compareWkt
Expand Down Expand Up @@ -252,6 +252,15 @@ def testToBox3d(self):
self.assertEqual(box.yMaximum(), 0.3)
self.assertEqual(box.zMaximum(), 0.5)

def testOperators(self):
rect1 = QgsRectangle(10, 20, 40, 40)
rect2 = rect1 + QgsVector(3, 5.5)
assert rect2 == QgsRectangle(13, 25.5, 43, 45.5), "QgsRectangle + operator does no work"

# Subtracting the center point, so it becomes zero.
rect1 -= rect1.center() - QgsPointXY(0, 0)
assert rect1.center() == QgsPointXY(0, 0)


if __name__ == '__main__':
unittest.main()

0 comments on commit 80bc6d2

Please sign in to comment.