Branch data Line data Source code
1 : : /*************************************************************************** 2 : : qgsrasterrange.h 3 : : -------------------------------------- 4 : : Date : Oct 9, 2012 5 : : Copyright : (C) 2012 by Radim Blazek 6 : : email : radim dot blazek at gmail dot com 7 : : ***************************************************************************/ 8 : : 9 : : /*************************************************************************** 10 : : * * 11 : : * This program is free software; you can redistribute it and/or modify * 12 : : * it under the terms of the GNU General Public License as published by * 13 : : * the Free Software Foundation; either version 2 of the License, or * 14 : : * (at your option) any later version. * 15 : : * * 16 : : ***************************************************************************/ 17 : : 18 : : #include "qgsrasterrange.h" 19 : : 20 : 0 : QgsRasterRange::QgsRasterRange( double min, double max, BoundsType bounds ) 21 : 0 : : mMin( min ) 22 : 0 : , mMax( max ) 23 : 0 : , mType( bounds ) 24 : : { 25 : 0 : } 26 : : 27 : 0 : bool QgsRasterRange::overlaps( const QgsRasterRange &other ) const 28 : : { 29 : 0 : bool thisIncludesLower = mType == IncludeMinAndMax || mType == IncludeMin; 30 : 0 : bool thisIncludesUpper = mType == IncludeMinAndMax || mType == IncludeMax; 31 : 0 : bool thisLowerInfinite = !std::isfinite( mMin ); 32 : 0 : bool thisUpperInfinite = !std::isfinite( mMax ); 33 : 0 : bool otherIncludesLower = other.mType == IncludeMinAndMax || other.mType == IncludeMin; 34 : 0 : bool otherIncludesUpper = other.mType == IncludeMinAndMax || other.mType == IncludeMax; 35 : 0 : bool otherLowerInfinite = !std::isfinite( other.mMin ); 36 : 0 : bool otherUpperInfinite = !std::isfinite( other.mMax ); 37 : : 38 : 0 : if ( ( ( thisIncludesLower && otherIncludesLower && ( mMin <= other.mMin || thisLowerInfinite ) ) || 39 : 0 : ( ( !thisIncludesLower || !otherIncludesLower ) && ( mMin < other.mMin || thisLowerInfinite ) ) ) 40 : 0 : && ( ( thisIncludesUpper && otherIncludesUpper && ( mMax >= other.mMax || thisUpperInfinite ) ) || 41 : 0 : ( ( !thisIncludesUpper || !otherIncludesUpper ) && ( mMax > other.mMax || thisUpperInfinite ) ) ) ) 42 : 0 : return true; 43 : : 44 : 0 : if ( ( ( otherIncludesLower && ( mMin <= other.mMin || thisLowerInfinite ) ) || 45 : 0 : ( !otherIncludesLower && ( mMin < other.mMin || thisLowerInfinite ) ) ) 46 : 0 : && ( ( thisIncludesUpper && otherIncludesLower && ( mMax >= other.mMin || thisUpperInfinite ) ) || 47 : 0 : ( ( !thisIncludesUpper || !otherIncludesLower ) && ( mMax > other.mMin || thisUpperInfinite ) ) ) ) 48 : 0 : return true; 49 : : 50 : 0 : if ( ( ( thisIncludesLower && otherIncludesUpper && ( mMin <= other.mMax || thisLowerInfinite ) ) || 51 : 0 : ( ( !thisIncludesLower || !otherIncludesUpper ) && ( mMin < other.mMax || thisLowerInfinite ) ) ) 52 : 0 : && ( ( thisIncludesUpper && otherIncludesUpper && ( mMax >= other.mMax || thisUpperInfinite ) ) || 53 : 0 : ( ( !thisIncludesUpper || !otherIncludesUpper ) && ( mMax > other.mMax || thisUpperInfinite ) ) ) ) 54 : 0 : return true; 55 : : 56 : 0 : if ( ( ( thisIncludesLower && otherIncludesLower && ( mMin >= other.mMin || otherLowerInfinite ) ) || 57 : 0 : ( ( !thisIncludesLower || !otherIncludesLower ) && ( mMin > other.mMin || otherLowerInfinite ) ) ) 58 : 0 : && ( ( thisIncludesLower && otherIncludesUpper && ( mMin <= other.mMax || thisLowerInfinite || otherUpperInfinite ) ) || 59 : 0 : ( ( !thisIncludesLower || !otherIncludesUpper ) && ( mMin < other.mMax || thisLowerInfinite || otherUpperInfinite ) ) ) ) 60 : 0 : return true; 61 : : 62 : 0 : if ( qgsDoubleNear( mMin, other.mMin ) && qgsDoubleNear( mMax, other.mMax ) ) 63 : 0 : return true; 64 : : 65 : 0 : return false; 66 : 0 : } 67 : : 68 : 0 : QString QgsRasterRange::asText() const 69 : : { 70 : 0 : const QString minText = std::isnan( mMin ) ? QStringLiteral( "-%1" ).arg( QChar( 0x221e ) ) : QString::number( mMin ); 71 : 0 : const QString maxText = std::isnan( mMax ) ? QChar( 0x221e ) : QString::number( mMax ); 72 : 0 : const QString operator1 = ( mType == IncludeMinAndMax || mType == IncludeMin ) ? QChar( 0x2264 ) : '<'; 73 : 0 : const QString operator2 = ( mType == IncludeMinAndMax || mType == IncludeMax ) ? QChar( 0x2264 ) : '<'; 74 : : 75 : 0 : return QStringLiteral( "%1 %2 x %3 %4" ).arg( minText, operator1, operator2, maxText ); 76 : 0 : } 77 : : 78 : : 79 : : 80 : : 81 : :