Skip to content
Permalink
Browse files

compare wcs extent using significant digits

  • Loading branch information
blazek committed Sep 27, 2012
1 parent 4d93a92 commit a49975acfc888e042e7c043a611b73ec89ba364f
Showing with 28 additions and 9 deletions.
  1. +18 −0 src/core/qgis.h
  2. +10 −8 src/providers/wcs/qgswcsprovider.cpp
  3. +0 −1 tests/src/providers/testqgswcspublicservers.cpp
@@ -154,6 +154,24 @@ inline bool doubleNear( double a, double b, double epsilon = 4 * DBL_EPSILON )
return diff > -epsilon && diff <= epsilon;
}

//
// compare two doubles using specified number of significant digits
//
inline bool doubleNearSig( double a, double b, int significantDigits = 10 )
{
// The most simple would be to print numbers as %.xe and compare as strings
// but that is probably too costly
// Then the fastest would be to set some bits directly, but little/big endian
// has to be considered (maybe TODO)
// Is there a better way?
int aexp, bexp;
double ar = frexp( a, &aexp );
double br = frexp( b, &bexp );

return aexp == bexp &&
round( ar * pow( 10, significantDigits ) ) == round( br * pow( 10, significantDigits ) ) ;

This comment has been minimized.

Copy link
@sdikiy

sdikiy Sep 27, 2012

Contributor

3>D:\git\qgis\src\core\qgis.h(172) : error C2668: 'pow' : ambiguous call to overloaded function
3> C:\Program Files\Microsoft Visual Studio 9.0\VC\include\math.h(575): could be 'long double pow(long double,int)'
3> C:\Program Files\Microsoft Visual Studio 9.0\VC\include\math.h(527): or 'float pow(float,int)'
3> C:\Program Files\Microsoft Visual Studio 9.0\VC\include\math.h(489): or 'double pow(double,int)'
3> while trying to match the argument list '(int, int)'
3>D:\git\qgis\src\core\qgis.h(172) : error C3861: 'round': identifier not found

}

/** Wkt string that represents a geographic coord sys
* @note added in 1.8 to replace GEOWkt
*/
@@ -534,10 +534,12 @@ void QgsWcsProvider::readBlock( int bandNo, QgsRectangle const & viewExtent, in
QgsRectangle cacheExtent = QgsGdalProviderBase::extent( mCachedGdalDataset );
QgsDebugMsg( "viewExtent = " + viewExtent.toString() );
QgsDebugMsg( "cacheExtent = " + cacheExtent.toString() );
if ( !doubleNear( cacheExtent.xMinimum(), viewExtent.xMinimum() ) ||
!doubleNear( cacheExtent.yMinimum(), viewExtent.yMinimum() ) ||
!doubleNear( cacheExtent.xMaximum(), viewExtent.xMaximum() ) ||
!doubleNear( cacheExtent.yMaximum(), viewExtent.yMaximum() ) )
// using doubleNear is too precise, example accetable difference:
// 179.9999999306699863 x 179.9999999306700431
if ( !doubleNearSig( cacheExtent.xMinimum(), viewExtent.xMinimum(), 10 ) ||
!doubleNearSig( cacheExtent.yMinimum(), viewExtent.yMinimum(), 10 ) ||
!doubleNearSig( cacheExtent.xMaximum(), viewExtent.xMaximum(), 10 ) ||
!doubleNearSig( cacheExtent.yMaximum(), viewExtent.yMaximum(), 10 ) )
{
QgsDebugMsg( "cacheExtent and viewExtent differ" );
QgsMessageLog::logMessage( tr( "Received coverage has wrong extent %1 (expected %2)" ).arg( cacheExtent.toString() ).arg( viewExtent.toString() ), tr( "WCS" ) );
@@ -1380,10 +1382,10 @@ bool QgsWcsProvider::calculateExtent()
QgsRectangle cacheExtent = QgsGdalProviderBase::extent( mCachedGdalDataset );
QgsDebugMsg( "mCoverageExtent = " + mCoverageExtent.toString() );
QgsDebugMsg( "cacheExtent = " + cacheExtent.toString() );
if ( !doubleNear( cacheExtent.xMinimum(), mCoverageExtent.xMinimum() ) ||
!doubleNear( cacheExtent.yMinimum(), mCoverageExtent.yMinimum() ) ||
!doubleNear( cacheExtent.xMaximum(), mCoverageExtent.xMaximum() ) ||
!doubleNear( cacheExtent.yMaximum(), mCoverageExtent.yMaximum() ) )
if ( !doubleNearSig( cacheExtent.xMinimum(), mCoverageExtent.xMinimum(), 10 ) ||
!doubleNearSig( cacheExtent.yMinimum(), mCoverageExtent.yMinimum(), 10 ) ||
!doubleNearSig( cacheExtent.xMaximum(), mCoverageExtent.xMaximum(), 10 ) ||
!doubleNearSig( cacheExtent.yMaximum(), mCoverageExtent.yMaximum(), 10 ) )
{
QgsDebugMsg( "cacheExtent and mCoverageExtent differ, mCoverageExtent cut to cacheExtent" );
mCoverageExtent = cacheExtent;
@@ -779,7 +779,6 @@ void TestQgsWcsPublicServers::report()
myRep += ".errmsg { color: #ff0000; }";
myRep += "</style>";

myRep += QString( "<p>Tested first %1 coverages for each server/version</p>" ).arg( mMaxCoverages );
myRep += QString( "<b>Servers: %1</b><br>\n" ).arg( myServerCount );
myRep += QString( "<b>Servers with error: %1</b><br>\n" ).arg( myServerErrCount );
myRep += QString( "<b>Servers with warning: %1</b><br>\n" ).arg( myServerWarnCount );

0 comments on commit a49975a

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