· · ·
range.h
1 /***************************************************************************
2 ** **
3 ** QCustomPlot, an easy to use, modern plotting widget for Qt **
4 ** Copyright (C) 2011, 2012, 2013, 2014 Emanuel Eichhammer **
5 ** **
6 ** This program is free software: you can redistribute it and/or modify **
7 ** it under the terms of the GNU General Public License as published by **
8 ** the Free Software Foundation, either version 3 of the License, or **
9 ** (at your option) any later version. **
10 ** **
11 ** This program is distributed in the hope that it will be useful, **
12 ** but WITHOUT ANY WARRANTY; without even the implied warranty of **
13 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the **
14 ** GNU General Public License for more details. **
15 ** **
16 ** You should have received a copy of the GNU General Public License **
17 ** along with this program. If not, see http://www.gnu.org/licenses/. **
18 ** **
19 ****************************************************************************
20 ** Author: Emanuel Eichhammer **
21 ** Website/Contact: http://www.qcustomplot.com/ **
22 ** Date: 07.04.14 **
23 ** Version: 1.2.1 **
24 ****************************************************************************/
25
26 #ifndef QCP_RANGE_H
27 #define QCP_RANGE_H
28
29 #include "global.h"
30
31 class QCP_LIB_DECL QCPRange
32 {
33 public:
34 double lower, upper;
35
36 QCPRange();
37 QCPRange(double lower, double upper);
38
39 bool operator==(const QCPRange& other) { return lower == other.lower && upper == other.upper; }
40 bool operator!=(const QCPRange& other) { return !(*this == other); }
41
42 QCPRange &operator+=(const double& value) { lower+=value; upper+=value; return *this; }
43 QCPRange &operator-=(const double& value) { lower-=value; upper-=value; return *this; }
44 QCPRange &operator*=(const double& value) { lower*=value; upper*=value; return *this; }
45 QCPRange &operator/=(const double& value) { lower/=value; upper/=value; return *this; }
46 friend inline const QCPRange operator+(const QCPRange&, double);
47 friend inline const QCPRange operator+(double, const QCPRange&);
48 friend inline const QCPRange operator-(const QCPRange& range, double value);
49 friend inline const QCPRange operator*(const QCPRange& range, double value);
50 friend inline const QCPRange operator*(double value, const QCPRange& range);
51 friend inline const QCPRange operator/(const QCPRange& range, double value);
52
53 double size() const;
54 double center() const;
55 void normalize();
56 void expand(const QCPRange &otherRange);
57 QCPRange expanded(const QCPRange &otherRange) const;
58 QCPRange sanitizedForLogScale() const;
59 QCPRange sanitizedForLinScale() const;
60 bool contains(double value) const;
61
62 static bool validRange(double lower, double upper);
63 static bool validRange(const QCPRange &range);
64 static const double minRange; //1e-280;
65 static const double maxRange; //1e280;
66
67 };
68 Q_DECLARE_TYPEINFO(QCPRange, Q_MOVABLE_TYPE);
69
70 /* documentation of inline functions */
71
92 /* end documentation of inline functions */
93
97 inline const QCPRange operator+(const QCPRange& range, double value)
98 {
99 QCPRange result(range);
100 result += value;
101 return result;
102 }
103
107 inline const QCPRange operator+(double value, const QCPRange& range)
108 {
109 QCPRange result(range);
110 result += value;
111 return result;
112 }
113
117 inline const QCPRange operator-(const QCPRange& range, double value)
118 {
119 QCPRange result(range);
120 result -= value;
121 return result;
122 }
123
127 inline const QCPRange operator*(const QCPRange& range, double value)
128 {
129 QCPRange result(range);
130 result *= value;
131 return result;
132 }
133
137 inline const QCPRange operator*(double value, const QCPRange& range)
138 {
139 QCPRange result(range);
140 result *= value;
141 return result;
142 }
143
147 inline const QCPRange operator/(const QCPRange& range, double value)
148 {
149 QCPRange result(range);
150 result /= value;
151 return result;
152 }
153
154 #endif // QCP_RANGE_H
Generated with Doxygen 1.8.1.2