Fix combining extent of valid rectangle with invalid rectangle results

in invalid rectangle
This commit is contained in:
Nyall Dawson 2017-11-16 12:41:02 +10:00
parent 8f1021c5b8
commit 8cf9f8fb6f
2 changed files with 25 additions and 7 deletions

View File

@ -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 )

View File

@ -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 );