Skip to content
Permalink
Browse files

Fix combining extent of valid rectangle with invalid rectangle results

in invalid rectangle
  • Loading branch information
nyalldawson committed Nov 19, 2017
1 parent 8f1021c commit 8cf9f8fb6f8235c13008c5d591b5af7f61a972f7
Showing with 25 additions and 7 deletions.
  1. +5 −7 src/core/geometry/qgsrectangle.cpp
  2. +20 −0 tests/src/core/testqgsrectangle.cpp
@@ -221,15 +221,13 @@ void QgsRectangle::combineExtentWith( const QgsRectangle &rect )
{
if ( isNull() )
*this = rect;
else
else if ( !rect.isNull() )
{
mXmin = ( ( mXmin < rect.xMinimum() ) ? mXmin : rect.xMinimum() );
mXmax = ( ( mXmax > rect.xMaximum() ) ? mXmax : rect.xMaximum() );

mYmin = ( ( mYmin < rect.yMinimum() ) ? mYmin : rect.yMinimum() );
mYmax = ( ( mYmax > rect.yMaximum() ) ? mYmax : rect.yMaximum() );
mXmin = std::min( mXmin, rect.xMinimum() );
mXmax = std::max( mXmax, rect.xMaximum() );
mYmin = std::min( mYmin, rect.yMinimum() );
mYmax = std::max( mYmax, rect.yMaximum() );;
}

}

void QgsRectangle::combineExtentWith( double x, double y )
@@ -38,6 +38,7 @@ class TestQgsRectangle: public QObject
void include();
void buffered();
void isFinite();
void combine();
void dataStream();
};

@@ -313,6 +314,25 @@ void TestQgsRectangle::isFinite()
QVERIFY( !QgsRectangle( 1, 2, 3, std::numeric_limits<double>::quiet_NaN() ).isFinite() );
}

void TestQgsRectangle::combine()
{
QgsRectangle rect;
// combine extent of null rectangle with valid rectangle
rect.combineExtentWith( QgsRectangle( 1, 2, 3, 4 ) );
QCOMPARE( rect.xMinimum(), 1.0 );
QCOMPARE( rect.yMinimum(), 2.0 );
QCOMPARE( rect.xMaximum(), 3.0 );
QCOMPARE( rect.yMaximum(), 4.0 );

// combine extent of valid rectangle with null rectangle
rect = QgsRectangle( 1, 2, 3, 4 );
rect.combineExtentWith( QgsRectangle() );
QCOMPARE( rect.xMinimum(), 1.0 );
QCOMPARE( rect.yMinimum(), 2.0 );
QCOMPARE( rect.xMaximum(), 3.0 );
QCOMPARE( rect.yMaximum(), 4.0 );
}

void TestQgsRectangle::dataStream()
{
QgsRectangle original( 10.1, 20.2, 110.3, 220.4 );

0 comments on commit 8cf9f8f

Please sign in to comment.
You can’t perform that action at this time.