Skip to content

Commit

Permalink
Have QgsRectangle::asPolygon return "EMPTY" for null rects
Browse files Browse the repository at this point in the history
Update python test accordingly
  • Loading branch information
strk committed Oct 2, 2023
1 parent ee22625 commit 8b19439
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
7 changes: 5 additions & 2 deletions src/core/geometry/qgsrectangle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,11 @@ QString QgsRectangle::toString( int precision ) const

QString QgsRectangle::asPolygon() const
{
// QString rep = tmp.sprintf("%16f %16f,%16f %16f,%16f %16f,%16f %16f,%16f %16f",
// xmin, ymin, xmin, ymax, xmax, ymax, xmax, ymin, xmin, ymin);
if ( isNull() )
{
return "EMPTY";
}

QString rep;

QTextStream foo( &rep );
Expand Down
2 changes: 1 addition & 1 deletion tests/src/python/test_qgsrectangle.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def testToString(self):

def testAsPolygon(self):
"""Test string representation as polygon"""
self.assertEqual(QgsRectangle().asPolygon(), '0.00000000 0.00000000, 0.00000000 0.00000000, 0.00000000 0.00000000, 0.00000000 0.00000000, 0.00000000 0.00000000')
self.assertEqual(QgsRectangle().asPolygon(), 'EMPTY')
self.assertEqual(QgsRectangle(0, 0.1, 0.2, 0.3).asPolygon(), '0.00000000 0.10000000, 0.00000000 0.30000000, 0.20000000 0.30000000, 0.20000000 0.10000000, 0.00000000 0.10000000')

def testToBox3d(self):
Expand Down

0 comments on commit 8b19439

Please sign in to comment.