source: ntrip/branches/BNC_2.12/qwt/qwt_interval.h@ 8641

Last change on this file since 8641 was 4271, checked in by mervart, 13 years ago
File size: 6.5 KB
Line 
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_INTERVAL_H
11#define QWT_INTERVAL_H
12
13#include "qwt_global.h"
14#ifndef QT_NO_DEBUG_STREAM
15#include <qdebug.h>
16#endif
17
18/*!
19 \brief A class representing an interval
20
21 The interval is represented by 2 doubles, the lower and the upper limit.
22*/
23
24class QWT_EXPORT QwtInterval
25{
26public:
27 /*!
28 Flag indicating if a border is included or excluded
29 \sa setBorderFlags(), borderFlags()
30 */
31 enum BorderFlag
32 {
33 //! Min/Max values are inside the interval
34 IncludeBorders = 0x00,
35
36 //! Min value is not included in the interval
37 ExcludeMinimum = 0x01,
38
39 //! Max value is not included in the interval
40 ExcludeMaximum = 0x02,
41
42 //! Min/Max values are not included in the interval
43 ExcludeBorders = ExcludeMinimum | ExcludeMaximum
44 };
45
46 //! Border flags
47 typedef QFlags<BorderFlag> BorderFlags;
48
49 QwtInterval();
50 QwtInterval( double minValue, double maxValue,
51 BorderFlags = IncludeBorders );
52
53 void setInterval( double minValue, double maxValue,
54 BorderFlags = IncludeBorders );
55
56 QwtInterval normalized() const;
57 QwtInterval inverted() const;
58 QwtInterval limited( double minValue, double maxValue ) const;
59
60 bool operator==( const QwtInterval & ) const;
61 bool operator!=( const QwtInterval & ) const;
62
63 void setBorderFlags( BorderFlags );
64 BorderFlags borderFlags() const;
65
66 double minValue() const;
67 double maxValue() const;
68
69 double width() const;
70
71 void setMinValue( double );
72 void setMaxValue( double );
73
74 bool contains( double value ) const;
75
76 bool intersects( const QwtInterval & ) const;
77 QwtInterval intersect( const QwtInterval & ) const;
78 QwtInterval unite( const QwtInterval & ) const;
79
80 QwtInterval operator|( const QwtInterval & ) const;
81 QwtInterval operator&( const QwtInterval & ) const;
82
83 QwtInterval &operator|=( const QwtInterval & );
84 QwtInterval &operator&=( const QwtInterval & );
85
86 QwtInterval extend( double value ) const;
87 QwtInterval operator|( double ) const;
88 QwtInterval &operator|=( double );
89
90 bool isValid() const;
91 bool isNull() const;
92 void invalidate();
93
94 QwtInterval symmetrize( double value ) const;
95
96private:
97 double d_minValue;
98 double d_maxValue;
99 BorderFlags d_borderFlags;
100};
101
102Q_DECLARE_TYPEINFO(QwtInterval, Q_MOVABLE_TYPE);
103
104/*!
105 \brief Default Constructor
106
107 Creates an invalid interval [0.0, -1.0]
108 \sa setInterval(), isValid()
109*/
110inline QwtInterval::QwtInterval():
111 d_minValue( 0.0 ),
112 d_maxValue( -1.0 ),
113 d_borderFlags( IncludeBorders )
114{
115}
116
117/*!
118 Constructor
119
120 Build an interval with from min/max values
121
122 \param minValue Minimum value
123 \param maxValue Maximum value
124 \param borderFlags Include/Exclude borders
125*/
126inline QwtInterval::QwtInterval(
127 double minValue, double maxValue, BorderFlags borderFlags ):
128 d_minValue( minValue ),
129 d_maxValue( maxValue ),
130 d_borderFlags( borderFlags )
131{
132}
133
134/*!
135 Assign the limits of the interval
136
137 \param minValue Minimum value
138 \param maxValue Maximum value
139 \param borderFlags Include/Exclude borders
140*/
141inline void QwtInterval::setInterval(
142 double minValue, double maxValue, BorderFlags borderFlags )
143{
144 d_minValue = minValue;
145 d_maxValue = maxValue;
146 d_borderFlags = borderFlags;
147}
148
149/*!
150 Change the border flags
151
152 \param borderFlags Or'd BorderMode flags
153 \sa borderFlags()
154*/
155inline void QwtInterval::setBorderFlags( BorderFlags borderFlags )
156{
157 d_borderFlags = borderFlags;
158}
159
160/*!
161 \return Border flags
162 \sa setBorderFlags()
163*/
164inline QwtInterval::BorderFlags QwtInterval::borderFlags() const
165{
166 return d_borderFlags;
167}
168
169/*!
170 Assign the lower limit of the interval
171
172 \param minValue Minimum value
173*/
174inline void QwtInterval::setMinValue( double minValue )
175{
176 d_minValue = minValue;
177}
178
179/*!
180 Assign the upper limit of the interval
181
182 \param maxValue Maximum value
183*/
184inline void QwtInterval::setMaxValue( double maxValue )
185{
186 d_maxValue = maxValue;
187}
188
189//! \return Lower limit of the interval
190inline double QwtInterval::minValue() const
191{
192 return d_minValue;
193}
194
195//! \return Upper limit of the interval
196inline double QwtInterval::maxValue() const
197{
198 return d_maxValue;
199}
200
201/*!
202 Return the width of an interval
203 The width of invalid intervals is 0.0, otherwise the result is
204 maxValue() - minValue().
205
206 \sa isValid()
207*/
208inline double QwtInterval::width() const
209{
210 return isValid() ? ( d_maxValue - d_minValue ) : 0.0;
211}
212
213/*!
214 Intersection of two intervals
215 \sa intersect()
216*/
217inline QwtInterval QwtInterval::operator&(
218 const QwtInterval &interval ) const
219{
220 return intersect( interval );
221}
222
223/*!
224 Union of two intervals
225 \sa unite()
226*/
227inline QwtInterval QwtInterval::operator|(
228 const QwtInterval &interval ) const
229{
230 return unite( interval );
231}
232
233//! Compare two intervals
234inline bool QwtInterval::operator==( const QwtInterval &other ) const
235{
236 return ( d_minValue == other.d_minValue ) &&
237 ( d_maxValue == other.d_maxValue ) &&
238 ( d_borderFlags == other.d_borderFlags );
239}
240
241//! Compare two intervals
242inline bool QwtInterval::operator!=( const QwtInterval &other ) const
243{
244 return ( !( *this == other ) );
245}
246
247/*!
248 Extend an interval
249
250 \param value Value
251 \return Extended interval
252 \sa extend()
253*/
254inline QwtInterval QwtInterval::operator|( double value ) const
255{
256 return extend( value );
257}
258
259//! \return true, if isValid() && (minValue() >= maxValue())
260inline bool QwtInterval::isNull() const
261{
262 return isValid() && d_minValue >= d_maxValue;
263}
264
265/*!
266 A interval is valid when minValue() <= maxValue().
267 In case of QwtInterval::ExcludeBorders it is true
268 when minValue() < maxValue()
269*/
270inline bool QwtInterval::isValid() const
271{
272 if ( ( d_borderFlags & ExcludeBorders ) == 0 )
273 return d_minValue <= d_maxValue;
274 else
275 return d_minValue < d_maxValue;
276}
277
278/*!
279 Invalidate the interval
280
281 The limits are set to interval [0.0, -1.0]
282 \sa isValid()
283*/
284inline void QwtInterval::invalidate()
285{
286 d_minValue = 0.0;
287 d_maxValue = -1.0;
288}
289
290Q_DECLARE_OPERATORS_FOR_FLAGS( QwtInterval::BorderFlags )
291
292#ifndef QT_NO_DEBUG_STREAM
293QWT_EXPORT QDebug operator<<( QDebug, const QwtInterval & );
294#endif
295
296#endif
Note: See TracBrowser for help on using the repository browser.