QGIS API Documentation
4.3.0-Master (16eddb2670e)
Toggle main menu visibility
Loading...
Searching...
No Matches
src
core
raster
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
20
#include <QString>
21
22
using namespace
Qt::StringLiterals;
23
24
QgsRasterRange::QgsRasterRange
(
double
min
,
double
max
,
BoundsType
bounds
)
25
: mMin(
min
)
26
, mMax(
max
)
27
, mType(
bounds
)
28
{}
29
30
bool
QgsRasterRange::overlaps
(
const
QgsRasterRange
&other )
const
31
{
32
const
bool
thisIncludesLower = mType ==
IncludeMinAndMax
|| mType ==
IncludeMin
;
33
const
bool
thisIncludesUpper = mType ==
IncludeMinAndMax
|| mType ==
IncludeMax
;
34
const
bool
thisLowerInfinite = !std::isfinite( mMin );
35
const
bool
thisUpperInfinite = !std::isfinite( mMax );
36
const
bool
otherIncludesLower = other.mType ==
IncludeMinAndMax
|| other.mType ==
IncludeMin
;
37
const
bool
otherIncludesUpper = other.mType ==
IncludeMinAndMax
|| other.mType ==
IncludeMax
;
38
const
bool
otherLowerInfinite = !std::isfinite( other.mMin );
39
const
bool
otherUpperInfinite = !std::isfinite( other.mMax );
40
41
if
( ( ( thisIncludesLower && otherIncludesLower && ( mMin <= other.mMin || thisLowerInfinite ) ) || ( ( !thisIncludesLower || !otherIncludesLower ) && ( mMin < other.mMin || thisLowerInfinite ) ) )
42
&& ( ( thisIncludesUpper && otherIncludesUpper && ( mMax >= other.mMax || thisUpperInfinite ) ) || ( ( !thisIncludesUpper || !otherIncludesUpper ) && ( mMax > other.mMax || thisUpperInfinite ) ) ) )
43
return
true
;
44
45
if
( ( ( otherIncludesLower && ( mMin <= other.mMin || thisLowerInfinite ) ) || ( !otherIncludesLower && ( mMin < other.mMin || thisLowerInfinite ) ) )
46
&& ( ( thisIncludesUpper && otherIncludesLower && ( mMax >= other.mMin || thisUpperInfinite ) ) || ( ( !thisIncludesUpper || !otherIncludesLower ) && ( mMax > other.mMin || thisUpperInfinite ) ) ) )
47
return
true
;
48
49
if
( ( ( thisIncludesLower && otherIncludesUpper && ( mMin <= other.mMax || thisLowerInfinite ) ) || ( ( !thisIncludesLower || !otherIncludesUpper ) && ( mMin < other.mMax || thisLowerInfinite ) ) )
50
&& ( ( thisIncludesUpper && otherIncludesUpper && ( mMax >= other.mMax || thisUpperInfinite ) ) || ( ( !thisIncludesUpper || !otherIncludesUpper ) && ( mMax > other.mMax || thisUpperInfinite ) ) ) )
51
return
true
;
52
53
if
( ( ( thisIncludesLower && otherIncludesLower && ( mMin >= other.mMin || otherLowerInfinite ) ) || ( ( !thisIncludesLower || !otherIncludesLower ) && ( mMin > other.mMin || otherLowerInfinite ) ) )
54
&& ( ( thisIncludesLower && otherIncludesUpper && ( mMin <= other.mMax || thisLowerInfinite || otherUpperInfinite ) ) || ( ( !thisIncludesLower || !otherIncludesUpper ) && ( mMin < other.mMax || thisLowerInfinite || otherUpperInfinite ) ) ) )
55
return
true
;
56
57
if
(
qgsDoubleNear
( mMin, other.mMin ) &&
qgsDoubleNear
( mMax, other.mMax ) )
58
return
true
;
59
60
return
false
;
61
}
62
63
QString
QgsRasterRange::asText
()
const
64
{
65
const
QString minText = std::isnan( mMin ) ? u
"-%1"
_s.arg( QChar( 0x221e ) ) : QString::number( mMin );
66
const
QString maxText = std::isnan( mMax ) ? QChar( 0x221e ) : QString::number( mMax );
67
const
QString operator1 = ( mType ==
IncludeMinAndMax
|| mType ==
IncludeMin
) ? QChar( 0x2264 ) :
'<'
;
68
const
QString operator2 = ( mType ==
IncludeMinAndMax
|| mType ==
IncludeMax
) ? QChar( 0x2264 ) :
'<'
;
69
70
return
u
"%1 %2 x %3 %4"
_s.arg( minText, operator1, operator2, maxText );
71
}
QgsRasterRange::BoundsType
BoundsType
Handling for min and max bounds.
Definition
qgsrasterrange.h:41
QgsRasterRange::IncludeMin
@ IncludeMin
Include the min value, but not the max value, e.g. min <= value < max.
Definition
qgsrasterrange.h:44
QgsRasterRange::IncludeMinAndMax
@ IncludeMinAndMax
Min and max values are inclusive.
Definition
qgsrasterrange.h:42
QgsRasterRange::IncludeMax
@ IncludeMax
Include the max value, but not the min value, e.g. min < value <= max.
Definition
qgsrasterrange.h:43
QgsRasterRange::min
double min() const
Returns the minimum value for the range.
Definition
qgsrasterrange.h:65
QgsRasterRange::overlaps
bool overlaps(const QgsRasterRange &other) const
Returns true if this range overlaps another range.
Definition
qgsrasterrange.cpp:30
QgsRasterRange::asText
QString asText() const
Returns a text representation of the range.
Definition
qgsrasterrange.cpp:63
QgsRasterRange::max
double max() const
Returns the maximum value for the range.
Definition
qgsrasterrange.h:71
QgsRasterRange::QgsRasterRange
QgsRasterRange()=default
Default constructor, both min and max value for the range will be set to NaN.
QgsRasterRange::bounds
BoundsType bounds() const
Returns the bounds type for the range, which specifies whether or not the min and max values themselv...
Definition
qgsrasterrange.h:80
qgsDoubleNear
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference).
Definition
qgis.h:7743
qgsrasterrange.h
Generated on
for QGIS API Documentation by
1.17.0