Skip to content

Commit

Permalink
Have QgsGeometry::boundingBox return null rect for null geom
Browse files Browse the repository at this point in the history
Includes unit test
  • Loading branch information
strk authored and nyalldawson committed Oct 22, 2023
1 parent f3e3e0d commit 3d21718
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/core/geometry/qgsgeometry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1201,7 +1201,7 @@ QgsRectangle QgsGeometry::boundingBox() const
{
return d->geometry->boundingBox();
}
return QgsRectangle();
return QgsRectangle::createNull();
}

QgsBox3D QgsGeometry::boundingBox3D() const
Expand Down
11 changes: 11 additions & 0 deletions tests/src/core/geometry/testqgsgeometry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ class TestQgsGeometry : public QgsTest
void createCollectionOfType();

void orientedMinimumBoundingBox( );
void boundingBox();
void boundingBox3D();
void minimalEnclosingCircle( );
void splitGeometry();
Expand Down Expand Up @@ -2167,6 +2168,16 @@ void TestQgsGeometry::orientedMinimumBoundingBox()

}

void TestQgsGeometry::boundingBox()
{
QgsGeometry geomTest;
QgsRectangle nullRect = QgsRectangle::createNull();
QCOMPARE( geomTest.boundingBox(), nullRect );

geomTest = QgsGeometry::fromWkt( QStringLiteral( "LINESTRING(-1 -2, 4 5)" ) );
QCOMPARE( geomTest.boundingBox3D(), QgsRectangle( -1, -2, 4, 5 ) );
}

void TestQgsGeometry::boundingBox3D()
{
QgsGeometry geomTest;
Expand Down

0 comments on commit 3d21718

Please sign in to comment.