2016-03-27 13:23:00 +02:00
|
|
|
#ifndef RANGE_H
|
|
|
|
#define RANGE_H
|
|
|
|
|
|
|
|
#include <QtGlobal>
|
|
|
|
#include <QDebug>
|
|
|
|
|
2017-09-09 12:33:43 +02:00
|
|
|
class Range
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
Range() {_min = 0; _max = 0;}
|
2018-10-06 21:31:12 +02:00
|
|
|
Range(int min, int max) : _min(min), _max(max) {}
|
2017-09-09 12:33:43 +02:00
|
|
|
|
|
|
|
int min() const {return _min;}
|
|
|
|
int max() const {return _max;}
|
|
|
|
int size() const {return (_max - _min);}
|
|
|
|
|
2018-02-27 01:02:22 +01:00
|
|
|
bool isValid() const {return size() >= 0;}
|
|
|
|
|
2018-03-30 10:25:05 +02:00
|
|
|
void setMin(int min) {_min = min;}
|
|
|
|
void setMax(int max) {_max = max;}
|
|
|
|
|
2018-09-22 14:17:24 +02:00
|
|
|
bool contains(int val) const {return (val >= _min && val <= _max);}
|
|
|
|
|
2017-09-09 12:33:43 +02:00
|
|
|
private:
|
|
|
|
int _min, _max;
|
|
|
|
};
|
|
|
|
|
2016-03-27 13:23:00 +02:00
|
|
|
class RangeF
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
RangeF() {_min = 0; _max = 0;}
|
2018-10-06 21:31:12 +02:00
|
|
|
RangeF(qreal min, qreal max) : _min(min), _max(max) {}
|
2016-03-27 13:23:00 +02:00
|
|
|
|
2018-04-02 23:27:42 +02:00
|
|
|
RangeF operator&(const RangeF &r) const;
|
|
|
|
RangeF &operator&=(const RangeF &r) {*this = *this & r; return *this;}
|
2018-04-02 19:59:52 +02:00
|
|
|
|
2016-03-27 13:23:00 +02:00
|
|
|
qreal min() const {return _min;}
|
|
|
|
qreal max() const {return _max;}
|
|
|
|
qreal size() const {return (_max - _min);}
|
|
|
|
|
2018-04-02 19:59:52 +02:00
|
|
|
bool isNull() const {return _min == 0 && _max == 0;}
|
2018-02-27 01:02:22 +01:00
|
|
|
bool isValid() const {return size() >= 0;}
|
|
|
|
|
2018-03-30 10:25:05 +02:00
|
|
|
void setMin(qreal min) {_min = min;}
|
|
|
|
void setMax(qreal max) {_max = max;}
|
|
|
|
|
2016-03-27 13:23:00 +02:00
|
|
|
void resize(qreal size);
|
|
|
|
|
|
|
|
private:
|
|
|
|
qreal _min, _max;
|
|
|
|
};
|
|
|
|
|
2018-02-13 23:03:18 +01:00
|
|
|
#ifndef QT_NO_DEBUG
|
2017-09-09 12:33:43 +02:00
|
|
|
QDebug operator<<(QDebug dbg, const Range &range);
|
2016-03-27 13:23:00 +02:00
|
|
|
QDebug operator<<(QDebug dbg, const RangeF &range);
|
2018-02-13 23:03:18 +01:00
|
|
|
#endif // QT_NO_DEBUG
|
2016-03-27 13:23:00 +02:00
|
|
|
|
|
|
|
#endif // RANGE_H
|