Skip to content

Commit

Permalink
Fix crash on empty polygon conversion to curve
Browse files Browse the repository at this point in the history
Closes GH-50466 in 3.22 branch

Includes unit test
  • Loading branch information
strk authored and nyalldawson committed Oct 18, 2022
1 parent 1b406f6 commit dbfa13b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
11 changes: 7 additions & 4 deletions src/core/geometry/qgspolygon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -316,11 +316,14 @@ QgsPolygon *QgsPolygon::surfaceToPolygon() const
QgsCurvePolygon *QgsPolygon::toCurveType() const
{
QgsCurvePolygon *curvePolygon = new QgsCurvePolygon();
curvePolygon->setExteriorRing( mExteriorRing->clone() );
int nInteriorRings = mInteriorRings.size();
for ( int i = 0; i < nInteriorRings; ++i )
if ( mExteriorRing )
{
curvePolygon->addInteriorRing( mInteriorRings.at( i )->clone() );
curvePolygon->setExteriorRing( mExteriorRing->clone() );
int nInteriorRings = mInteriorRings.size();
for ( int i = 0; i < nInteriorRings; ++i )
{
curvePolygon->addInteriorRing( mInteriorRings.at( i )->clone() );
}
}
return curvePolygon;
}
5 changes: 4 additions & 1 deletion tests/src/core/geometry/testqgspolygon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,10 @@ void TestQgsPolygon::polygon()
QCOMPARE( *toP, p12 );

//toCurveType
std::unique_ptr< QgsCurvePolygon > curveType( p12.toCurveType() );
std::unique_ptr< QgsCurvePolygon > curveType( QgsPolygon().toCurveType() );
QCOMPARE( curveType->wkbType(), QgsWkbTypes::CurvePolygon );

curveType.reset( p12.toCurveType() );
QCOMPARE( curveType->wkbType(), QgsWkbTypes::CurvePolygonZM );
QCOMPARE( curveType->exteriorRing()->numPoints(), 5 );
QCOMPARE( curveType->exteriorRing()->vertexAt( QgsVertexId( 0, 0, 0 ) ), QgsPoint( QgsWkbTypes::PointZM, 0, 0, 1, 5 ) );
Expand Down

0 comments on commit dbfa13b

Please sign in to comment.