1
/* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
3
* Copyright (C) 1997 Josef Wilgen
4
* Copyright (C) 2002 Uwe Rathmann
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
*****************************************************************************/
10
#ifndef QWT_INTERVAL_H
11
#define QWT_INTERVAL_H
13
#include "qwt_global.h"
14
#ifndef QT_NO_DEBUG_STREAM
19
\brief A class representing an interval
21
The interval is represented by 2 doubles, the lower and the upper limit.
24
class QWT_EXPORT QwtInterval
28
Flag indicating if a border is included or excluded
29
\sa setBorderFlags(), borderFlags()
33
//! Min/Max values are inside the interval
34
IncludeBorders = 0x00,
36
//! Min value is not included in the interval
37
ExcludeMinimum = 0x01,
39
//! Max value is not included in the interval
40
ExcludeMaximum = 0x02,
42
//! Min/Max values are not included in the interval
43
ExcludeBorders = ExcludeMinimum | ExcludeMaximum
47
typedef QFlags<BorderFlag> BorderFlags;
50
QwtInterval( double minValue, double maxValue,
51
BorderFlags = IncludeBorders );
53
void setInterval( double minValue, double maxValue,
54
BorderFlags = IncludeBorders );
56
QwtInterval normalized() const;
57
QwtInterval inverted() const;
58
QwtInterval limited( double minValue, double maxValue ) const;
60
bool operator==( const QwtInterval & ) const;
61
bool operator!=( const QwtInterval & ) const;
63
void setBorderFlags( BorderFlags );
64
BorderFlags borderFlags() const;
66
double minValue() const;
67
double maxValue() const;
71
void setMinValue( double );
72
void setMaxValue( double );
74
bool contains( double value ) const;
76
bool intersects( const QwtInterval & ) const;
77
QwtInterval intersect( const QwtInterval & ) const;
78
QwtInterval unite( const QwtInterval & ) const;
80
QwtInterval operator|( const QwtInterval & ) const;
81
QwtInterval operator&( const QwtInterval & ) const;
83
QwtInterval &operator|=( const QwtInterval & );
84
QwtInterval &operator&=( const QwtInterval & );
86
QwtInterval extend( double value ) const;
87
QwtInterval operator|( double ) const;
88
QwtInterval &operator|=( double );
94
QwtInterval symmetrize( double value ) const;
99
BorderFlags d_borderFlags;
102
Q_DECLARE_TYPEINFO(QwtInterval, Q_MOVABLE_TYPE);
105
\brief Default Constructor
107
Creates an invalid interval [0.0, -1.0]
108
\sa setInterval(), isValid()
110
inline QwtInterval::QwtInterval():
113
d_borderFlags( IncludeBorders )
120
Build an interval with from min/max values
122
\param minValue Minimum value
123
\param maxValue Maximum value
124
\param borderFlags Include/Exclude borders
126
inline QwtInterval::QwtInterval(
127
double minValue, double maxValue, BorderFlags borderFlags ):
128
d_minValue( minValue ),
129
d_maxValue( maxValue ),
130
d_borderFlags( borderFlags )
135
Assign the limits of the interval
137
\param minValue Minimum value
138
\param maxValue Maximum value
139
\param borderFlags Include/Exclude borders
141
inline void QwtInterval::setInterval(
142
double minValue, double maxValue, BorderFlags borderFlags )
144
d_minValue = minValue;
145
d_maxValue = maxValue;
146
d_borderFlags = borderFlags;
150
Change the border flags
152
\param borderFlags Or'd BorderMode flags
155
inline void QwtInterval::setBorderFlags( BorderFlags borderFlags )
157
d_borderFlags = borderFlags;
164
inline QwtInterval::BorderFlags QwtInterval::borderFlags() const
166
return d_borderFlags;
170
Assign the lower limit of the interval
172
\param minValue Minimum value
174
inline void QwtInterval::setMinValue( double minValue )
176
d_minValue = minValue;
180
Assign the upper limit of the interval
182
\param maxValue Maximum value
184
inline void QwtInterval::setMaxValue( double maxValue )
186
d_maxValue = maxValue;
189
//! \return Lower limit of the interval
190
inline double QwtInterval::minValue() const
195
//! \return Upper limit of the interval
196
inline double QwtInterval::maxValue() const
202
Return the width of an interval
203
The width of invalid intervals is 0.0, otherwise the result is
204
maxValue() - minValue().
208
inline double QwtInterval::width() const
210
return isValid() ? ( d_maxValue - d_minValue ) : 0.0;
214
Intersection of two intervals
217
inline QwtInterval QwtInterval::operator&(
218
const QwtInterval &interval ) const
220
return intersect( interval );
224
Union of two intervals
227
inline QwtInterval QwtInterval::operator|(
228
const QwtInterval &interval ) const
230
return unite( interval );
233
//! Compare two intervals
234
inline bool QwtInterval::operator==( const QwtInterval &other ) const
236
return ( d_minValue == other.d_minValue ) &&
237
( d_maxValue == other.d_maxValue ) &&
238
( d_borderFlags == other.d_borderFlags );
241
//! Compare two intervals
242
inline bool QwtInterval::operator!=( const QwtInterval &other ) const
244
return ( !( *this == other ) );
251
\return Extended interval
254
inline QwtInterval QwtInterval::operator|( double value ) const
256
return extend( value );
259
//! \return true, if isValid() && (minValue() >= maxValue())
260
inline bool QwtInterval::isNull() const
262
return isValid() && d_minValue >= d_maxValue;
266
A interval is valid when minValue() <= maxValue().
267
In case of QwtInterval::ExcludeBorders it is true
268
when minValue() < maxValue()
270
inline bool QwtInterval::isValid() const
272
if ( ( d_borderFlags & ExcludeBorders ) == 0 )
273
return d_minValue <= d_maxValue;
275
return d_minValue < d_maxValue;
279
Invalidate the interval
281
The limits are set to interval [0.0, -1.0]
284
inline void QwtInterval::invalidate()
290
Q_DECLARE_OPERATORS_FOR_FLAGS( QwtInterval::BorderFlags );
292
#ifndef QT_NO_DEBUG_STREAM
293
QWT_EXPORT QDebug operator<<( QDebug, const QwtInterval & );