QGIS API Documentation 3.37.0-Master (fdefdf9c27f)
qgsrasterrange.cpp
Go to the documentation of this file.
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
20QgsRasterRange::QgsRasterRange( double min, double max, BoundsType bounds )
21 : mMin( min )
22 , mMax( max )
23 , mType( bounds )
24{
25}
26
27bool QgsRasterRange::overlaps( const QgsRasterRange &other ) const
28{
29 const bool thisIncludesLower = mType == IncludeMinAndMax || mType == IncludeMin;
30 const bool thisIncludesUpper = mType == IncludeMinAndMax || mType == IncludeMax;
31 const bool thisLowerInfinite = !std::isfinite( mMin );
32 const bool thisUpperInfinite = !std::isfinite( mMax );
33 const bool otherIncludesLower = other.mType == IncludeMinAndMax || other.mType == IncludeMin;
34 const bool otherIncludesUpper = other.mType == IncludeMinAndMax || other.mType == IncludeMax;
35 const bool otherLowerInfinite = !std::isfinite( other.mMin );
36 const bool otherUpperInfinite = !std::isfinite( other.mMax );
37
38 if ( ( ( thisIncludesLower && otherIncludesLower && ( mMin <= other.mMin || thisLowerInfinite ) ) ||
39 ( ( !thisIncludesLower || !otherIncludesLower ) && ( mMin < other.mMin || thisLowerInfinite ) ) )
40 && ( ( thisIncludesUpper && otherIncludesUpper && ( mMax >= other.mMax || thisUpperInfinite ) ) ||
41 ( ( !thisIncludesUpper || !otherIncludesUpper ) && ( mMax > other.mMax || thisUpperInfinite ) ) ) )
42 return true;
43
44 if ( ( ( otherIncludesLower && ( mMin <= other.mMin || thisLowerInfinite ) ) ||
45 ( !otherIncludesLower && ( mMin < other.mMin || thisLowerInfinite ) ) )
46 && ( ( thisIncludesUpper && otherIncludesLower && ( mMax >= other.mMin || thisUpperInfinite ) ) ||
47 ( ( !thisIncludesUpper || !otherIncludesLower ) && ( mMax > other.mMin || thisUpperInfinite ) ) ) )
48 return true;
49
50 if ( ( ( thisIncludesLower && otherIncludesUpper && ( mMin <= other.mMax || thisLowerInfinite ) ) ||
51 ( ( !thisIncludesLower || !otherIncludesUpper ) && ( mMin < other.mMax || thisLowerInfinite ) ) )
52 && ( ( thisIncludesUpper && otherIncludesUpper && ( mMax >= other.mMax || thisUpperInfinite ) ) ||
53 ( ( !thisIncludesUpper || !otherIncludesUpper ) && ( mMax > other.mMax || thisUpperInfinite ) ) ) )
54 return true;
55
56 if ( ( ( thisIncludesLower && otherIncludesLower && ( mMin >= other.mMin || otherLowerInfinite ) ) ||
57 ( ( !thisIncludesLower || !otherIncludesLower ) && ( mMin > other.mMin || otherLowerInfinite ) ) )
58 && ( ( thisIncludesLower && otherIncludesUpper && ( mMin <= other.mMax || thisLowerInfinite || otherUpperInfinite ) ) ||
59 ( ( !thisIncludesLower || !otherIncludesUpper ) && ( mMin < other.mMax || thisLowerInfinite || otherUpperInfinite ) ) ) )
60 return true;
61
62 if ( qgsDoubleNear( mMin, other.mMin ) && qgsDoubleNear( mMax, other.mMax ) )
63 return true;
64
65 return false;
66}
67
69{
70 const QString minText = std::isnan( mMin ) ? QStringLiteral( "-%1" ).arg( QChar( 0x221e ) ) : QString::number( mMin );
71 const QString maxText = std::isnan( mMax ) ? QChar( 0x221e ) : QString::number( mMax );
72 const QString operator1 = ( mType == IncludeMinAndMax || mType == IncludeMin ) ? QChar( 0x2264 ) : '<';
73 const QString operator2 = ( mType == IncludeMinAndMax || mType == IncludeMax ) ? QChar( 0x2264 ) : '<';
74
75 return QStringLiteral( "%1 %2 x %3 %4" ).arg( minText, operator1, operator2, maxText );
76}
77
78
79
80
81
Raster values range container.
BoundsType
Handling for min and max bounds.
@ IncludeMin
Include the min value, but not the max value, e.g. min <= value < max.
@ IncludeMinAndMax
Min and max values are inclusive.
@ IncludeMax
Include the max value, but not the min value, e.g. min < value <= max.
bool overlaps(const QgsRasterRange &other) const
Returns true if this range overlaps another range.
QString asText() const
Returns a text representation of the range.
QgsRasterRange()=default
Default constructor, both min and max value for the range will be set to NaN.
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
Definition: qgis.h:5207