Qwt User's Guide  5.2.3
qwt_double_interval.h
1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
2  * Qwt Widget Library
3  * Copyright (C) 1997 Josef Wilgen
4  * Copyright (C) 2002 Uwe Rathmann
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the Qwt License, Version 1.0
8  *****************************************************************************/
9 
10 #ifndef QWT_DOUBLE_INTERVAL_H
11 #define QWT_DOUBLE_INTERVAL_H
12 
13 #include "qwt_global.h"
14 
21 class QWT_EXPORT QwtDoubleInterval
22 {
23 public:
39  {
40  IncludeBorders = 0,
41 
42  ExcludeMinimum = 1,
43  ExcludeMaximum = 2,
44 
45  ExcludeBorders = ExcludeMinimum | ExcludeMaximum
46  };
47 
49  QwtDoubleInterval(double minValue, double maxValue,
50  int borderFlags = IncludeBorders);
51 
52  void setInterval(double minValue, double maxValue,
53  int borderFlags = IncludeBorders);
54 
55  QwtDoubleInterval normalized() const;
56  QwtDoubleInterval inverted() const;
57  QwtDoubleInterval limited(double minValue, double maxValue) const;
58 
59  int operator==(const QwtDoubleInterval &) const;
60  int operator!=(const QwtDoubleInterval &) const;
61 
62  void setBorderFlags(int);
63  int borderFlags() const;
64 
65  double minValue() const;
66  double maxValue() const;
67 
68  double width() const;
69 
70  void setMinValue(double);
71  void setMaxValue(double);
72 
73  bool contains(double value) const;
74 
75  bool intersects(const QwtDoubleInterval &) const;
76  QwtDoubleInterval intersect(const QwtDoubleInterval &) const;
77  QwtDoubleInterval unite(const QwtDoubleInterval &) const;
78 
79  QwtDoubleInterval operator|(const QwtDoubleInterval &) const;
80  QwtDoubleInterval operator&(const QwtDoubleInterval &) const;
81 
82  QwtDoubleInterval &operator|=(const QwtDoubleInterval &);
83  QwtDoubleInterval &operator&=(const QwtDoubleInterval &);
84 
85  QwtDoubleInterval extend(double value) const;
86  QwtDoubleInterval operator|(double) const;
87  QwtDoubleInterval &operator|=(double);
88 
89  bool isValid() const;
90  bool isNull() const;
91  void invalidate();
92 
93  QwtDoubleInterval symmetrize(double value) const;
94 
95 private:
96  double d_minValue;
97  double d_maxValue;
98  int d_borderFlags;
99 };
100 
108  d_minValue(0.0),
109  d_maxValue(-1.0),
110  d_borderFlags(IncludeBorders)
111 {
112 }
113 
124  double minValue, double maxValue, int borderFlags):
125  d_minValue(minValue),
126  d_maxValue(maxValue),
127  d_borderFlags(borderFlags)
128 {
129 }
130 
139  double minValue, double maxValue, int borderFlags)
140 {
141  d_minValue = minValue;
142  d_maxValue = maxValue;
143  d_borderFlags = borderFlags;
144 }
145 
152 inline void QwtDoubleInterval::setBorderFlags(int borderFlags)
153 {
154  d_borderFlags = borderFlags;
155 }
156 
162 {
163  return d_borderFlags;
164 }
165 
171 inline void QwtDoubleInterval::setMinValue(double minValue)
172 {
173  d_minValue = minValue;
174 }
175 
181 inline void QwtDoubleInterval::setMaxValue(double maxValue)
182 {
183  d_maxValue = maxValue;
184 }
185 
187 inline double QwtDoubleInterval::minValue() const
188 {
189  return d_minValue;
190 }
191 
193 inline double QwtDoubleInterval::maxValue() const
194 {
195  return d_maxValue;
196 }
197 
205 inline double QwtDoubleInterval::width() const
206 {
207  return isValid() ? (d_maxValue - d_minValue) : 0.0;
208 }
209 
215  const QwtDoubleInterval &interval ) const
216 {
217  return intersect(interval);
218 }
219 
225  const QwtDoubleInterval &interval) const
226 {
227  return unite(interval);
228 }
229 
231 inline int QwtDoubleInterval::operator==(const QwtDoubleInterval &other) const
232 {
233  return (d_minValue == other.d_minValue) &&
234  (d_maxValue == other.d_maxValue) &&
235  (d_borderFlags == other.d_borderFlags);
236 }
237 
239 inline int QwtDoubleInterval::operator!=(const QwtDoubleInterval &other) const
240 {
241  return (!(*this == other));
242 }
243 
249 {
250  return extend(value);
251 }
252 
254 inline bool QwtDoubleInterval::isNull() const
255 {
256  return isValid() && d_minValue >= d_maxValue;
257 }
258 
264 inline bool QwtDoubleInterval::isValid() const
265 {
266  if ( (d_borderFlags & ExcludeBorders) == 0 )
267  return d_minValue <= d_maxValue;
268  else
269  return d_minValue < d_maxValue;
270 }
271 
279 {
280  d_minValue = 0.0;
281  d_maxValue = -1.0;
282 }
283 
284 #endif