Skip to content

Commit d435a7a

Browse files
committed
Add bounds type handling to QgsRasterRange
1 parent efb44ad commit d435a7a

File tree

4 files changed

+77
-4
lines changed

4 files changed

+77
-4
lines changed

python/core/auto_generated/raster/qgsrasterrange.sip.in

+34-1
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,25 @@ including min and max value.
2424
%End
2525
public:
2626

27+
enum BoundsType
28+
{
29+
IncludeMinAndMax,
30+
IncludeMax,
31+
IncludeMin,
32+
Exclusive,
33+
};
34+
2735
QgsRasterRange();
2836
%Docstring
2937
Default constructor, both min and max value for the range will be set to NaN.
3038
%End
3139

32-
QgsRasterRange( double min, double max );
40+
QgsRasterRange( double min, double max, BoundsType bounds = IncludeMinAndMax );
3341
%Docstring
3442
Constructor for a range with the given ``min`` and ``max`` values.
43+
44+
The ``bounds`` argument dictates how the min and max value themselves
45+
will be handled by the range.
3546
%End
3647

3748
double min() const;
@@ -46,6 +57,17 @@ Returns the minimum value for the range.
4657
Returns the maximum value for the range.
4758

4859
.. seealso:: :py:func:`setMax`
60+
%End
61+
62+
BoundsType bounds() const;
63+
%Docstring
64+
Returns the bounds type for the range, which specifies
65+
whether or not the min and max values themselves are included
66+
in the range.
67+
68+
.. seealso:: :py:func:`setBounds`
69+
70+
.. versionadded:: 3.4
4971
%End
5072

5173
double setMin( double min );
@@ -60,6 +82,17 @@ Sets the minimum value for the range.
6082
Sets the maximum value for the range.
6183

6284
.. seealso:: :py:func:`max`
85+
%End
86+
87+
void setBounds( BoundsType type );
88+
%Docstring
89+
Setss the bounds ``type`` for the range, which specifies
90+
whether or not the min and max values themselves are included
91+
in the range.
92+
93+
.. seealso:: :py:func:`bounds`
94+
95+
.. versionadded:: 3.4
6396
%End
6497

6598
bool operator==( QgsRasterRange o ) const;

src/core/raster/qgsrasterrange.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@
1717

1818
#include "qgsrasterrange.h"
1919

20-
QgsRasterRange::QgsRasterRange( double min, double max )
20+
QgsRasterRange::QgsRasterRange( double min, double max, BoundsType bounds )
2121
: mMin( min )
2222
, mMax( max )
23+
, mType( bounds )
2324
{
2425
}
2526

src/core/raster/qgsrasterrange.h

+34-2
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,27 @@ class CORE_EXPORT QgsRasterRange
3636
{
3737
public:
3838

39+
//! Handling for min and max bounds
40+
enum BoundsType
41+
{
42+
IncludeMinAndMax = 0, //!< Min and max values are inclusive
43+
IncludeMax, //!< Include the max value, but not the min value, e.g. min < value <= max
44+
IncludeMin, //!< Include the min value, but not the max value, e.g. min <= value < max
45+
Exclusive, //!< Don't include either the min or max value, e.g. min < value < max
46+
};
47+
3948
/**
4049
* Default constructor, both min and max value for the range will be set to NaN.
4150
*/
4251
QgsRasterRange() = default;
4352

4453
/**
4554
* Constructor for a range with the given \a min and \a max values.
55+
*
56+
* The \a bounds argument dictates how the min and max value themselves
57+
* will be handled by the range.
4658
*/
47-
QgsRasterRange( double min, double max );
59+
QgsRasterRange( double min, double max, BoundsType bounds = IncludeMinAndMax );
4860

4961
/**
5062
* Returns the minimum value for the range.
@@ -58,6 +70,15 @@ class CORE_EXPORT QgsRasterRange
5870
*/
5971
double max() const { return mMax; }
6072

73+
/**
74+
* Returns the bounds type for the range, which specifies
75+
* whether or not the min and max values themselves are included
76+
* in the range.
77+
* \see setBounds()
78+
* \since QGIS 3.4
79+
*/
80+
BoundsType bounds() const { return mType; }
81+
6182
/**
6283
* Sets the minimum value for the range.
6384
* \see min()
@@ -70,10 +91,20 @@ class CORE_EXPORT QgsRasterRange
7091
*/
7192
double setMax( double max ) { return mMax = max; }
7293

94+
/**
95+
* Setss the bounds \a type for the range, which specifies
96+
* whether or not the min and max values themselves are included
97+
* in the range.
98+
* \see bounds()
99+
* \since QGIS 3.4
100+
*/
101+
void setBounds( BoundsType type ) { mType = type; }
102+
73103
inline bool operator==( QgsRasterRange o ) const
74104
{
75105
return ( ( std::isnan( mMin ) && std::isnan( o.mMin ) ) || qgsDoubleNear( mMin, o.mMin ) )
76-
&& ( ( std::isnan( mMax ) && std::isnan( o.mMax ) ) || qgsDoubleNear( mMax, o.mMax ) );
106+
&& ( ( std::isnan( mMax ) && std::isnan( o.mMax ) ) || qgsDoubleNear( mMax, o.mMax ) )
107+
&& mType == o.mType;
77108
}
78109

79110
/**
@@ -87,6 +118,7 @@ class CORE_EXPORT QgsRasterRange
87118
private:
88119
double mMin = std::numeric_limits<double>::quiet_NaN();
89120
double mMax = std::numeric_limits<double>::quiet_NaN();
121+
BoundsType mType = IncludeMinAndMax;
90122
};
91123

92124
#endif

tests/src/python/test_qgsrasterrange.py

+7
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ def testBasic(self):
2929
range.setMax(10.4)
3030
self.assertEqual(range.min(), 2.2)
3131
self.assertEqual(range.max(), 10.4)
32+
self.assertEqual(range.bounds(), QgsRasterRange.IncludeMinAndMax)
33+
range.setBounds(QgsRasterRange.IncludeMin)
34+
self.assertEqual(range.bounds(), QgsRasterRange.IncludeMin)
3235

3336
def testEquality(self):
3437
range = QgsRasterRange(1, 5)
@@ -41,6 +44,10 @@ def testEquality(self):
4144
self.assertNotEqual(range, range2)
4245
range2.setMax(5)
4346
self.assertEqual(range, range2)
47+
range.setBounds(QgsRasterRange.IncludeMax)
48+
self.assertNotEqual(range, range2)
49+
range2.setBounds(QgsRasterRange.IncludeMax)
50+
self.assertEqual(range, range2)
4451
range = QgsRasterRange()
4552
range2 = QgsRasterRange()
4653
self.assertEqual(range, range2)

0 commit comments

Comments
 (0)