Skip to content

Commit

Permalink
Have QGsGeometry::fromRect(nullRect) return null geometry
Browse files Browse the repository at this point in the history
Includes testcase
  • Loading branch information
strk committed Oct 22, 2023
1 parent f3c1ba7 commit e366095
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/core/geometry/qgsgeometry.cpp
Expand Up @@ -233,6 +233,9 @@ QgsGeometry QgsGeometry::fromMultiPolygonXY( const QgsMultiPolygonXY &multipoly

QgsGeometry QgsGeometry::fromRect( const QgsRectangle &rect )
{
if ( rect.isNull() )
return QgsGeometry();

std::unique_ptr< QgsLineString > ext = std::make_unique< QgsLineString >(
QVector< double >() << rect.xMinimum()
<< rect.xMaximum()
Expand Down
12 changes: 12 additions & 0 deletions tests/src/core/geometry/testqgsgeometry.cpp
Expand Up @@ -96,6 +96,7 @@ class TestQgsGeometry : public QgsTest
void fromQPoint();
void fromQPolygonF();
void fromPolyline();
void fromRect();
void asQPointF();
void asQPolygonF();

Expand Down Expand Up @@ -834,6 +835,17 @@ void TestQgsGeometry::fromPolyline()
QCOMPARE( fromPolyline.asWkt(), QStringLiteral( "LineStringZM (10 20 4 100, 30 40 5 200)" ) );
}

void TestQgsGeometry::fromRect()
{
QgsRectangle rectNull = QgsRectangle::createNull();

QgsGeometry fromRect = QgsGeometry::fromRect( rectNull );
QVERIFY( fromRect.isNull() );

fromRect = QgsGeometry::fromRect( QgsRectangle( 1, 2, 3, 4 ) );
QCOMPARE( fromRect.asWkt(), QStringLiteral( "Polygon ((1 2, 3 2, 3 4, 1 4, 1 2))" ) );
}

void TestQgsGeometry::asQPointF()
{
QPointF point( 1.0, 2.0 );
Expand Down

0 comments on commit e366095

Please sign in to comment.