00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #ifndef QWT_INTERVAL_H
00011 #define QWT_INTERVAL_H
00012
00013 #include "qwt_global.h"
00014 #ifndef QT_NO_DEBUG_STREAM
00015 #include <qdebug.h>
00016 #endif
00017
00024 class QWT_EXPORT QwtInterval
00025 {
00026 public:
00041 enum BorderMode
00042 {
00043 IncludeBorders = 0,
00044
00045 ExcludeMinimum = 1,
00046 ExcludeMaximum = 2,
00047
00048 ExcludeBorders = ExcludeMinimum | ExcludeMaximum
00049 };
00050
00051 QwtInterval();
00052 QwtInterval( double minValue, double maxValue,
00053 int borderFlags = IncludeBorders );
00054
00055 void setInterval( double minValue, double maxValue,
00056 int borderFlags = IncludeBorders );
00057
00058 QwtInterval normalized() const;
00059 QwtInterval inverted() const;
00060 QwtInterval limited( double minValue, double maxValue ) const;
00061
00062 bool operator==( const QwtInterval & ) const;
00063 bool operator!=( const QwtInterval & ) const;
00064
00065 void setBorderFlags( int );
00066 int borderFlags() const;
00067
00068 double minValue() const;
00069 double maxValue() const;
00070
00071 double width() const;
00072
00073 void setMinValue( double );
00074 void setMaxValue( double );
00075
00076 bool contains( double value ) const;
00077
00078 bool intersects( const QwtInterval & ) const;
00079 QwtInterval intersect( const QwtInterval & ) const;
00080 QwtInterval unite( const QwtInterval & ) const;
00081
00082 QwtInterval operator|( const QwtInterval & ) const;
00083 QwtInterval operator&( const QwtInterval & ) const;
00084
00085 QwtInterval &operator|=( const QwtInterval & );
00086 QwtInterval &operator&=( const QwtInterval & );
00087
00088 QwtInterval extend( double value ) const;
00089 QwtInterval operator|( double ) const;
00090 QwtInterval &operator|=( double );
00091
00092 bool isValid() const;
00093 bool isNull() const;
00094 void invalidate();
00095
00096 QwtInterval symmetrize( double value ) const;
00097
00098 private:
00099 double d_minValue;
00100 double d_maxValue;
00101 int d_borderFlags;
00102 };
00103
00110 inline QwtInterval::QwtInterval():
00111 d_minValue( 0.0 ),
00112 d_maxValue( -1.0 ),
00113 d_borderFlags( IncludeBorders )
00114 {
00115 }
00116
00126 inline QwtInterval::QwtInterval(
00127 double minValue, double maxValue, int borderFlags ):
00128 d_minValue( minValue ),
00129 d_maxValue( maxValue ),
00130 d_borderFlags( borderFlags )
00131 {
00132 }
00133
00141 inline void QwtInterval::setInterval(
00142 double minValue, double maxValue, int borderFlags )
00143 {
00144 d_minValue = minValue;
00145 d_maxValue = maxValue;
00146 d_borderFlags = borderFlags;
00147 }
00148
00155 inline void QwtInterval::setBorderFlags( int borderFlags )
00156 {
00157 d_borderFlags = borderFlags;
00158 }
00159
00164 inline int QwtInterval::borderFlags() const
00165 {
00166 return d_borderFlags;
00167 }
00168
00174 inline void QwtInterval::setMinValue( double minValue )
00175 {
00176 d_minValue = minValue;
00177 }
00178
00184 inline void QwtInterval::setMaxValue( double maxValue )
00185 {
00186 d_maxValue = maxValue;
00187 }
00188
00190 inline double QwtInterval::minValue() const
00191 {
00192 return d_minValue;
00193 }
00194
00196 inline double QwtInterval::maxValue() const
00197 {
00198 return d_maxValue;
00199 }
00200
00208 inline double QwtInterval::width() const
00209 {
00210 return isValid() ? ( d_maxValue - d_minValue ) : 0.0;
00211 }
00212
00217 inline QwtInterval QwtInterval::operator&(
00218 const QwtInterval &interval ) const
00219 {
00220 return intersect( interval );
00221 }
00222
00227 inline QwtInterval QwtInterval::operator|(
00228 const QwtInterval &interval ) const
00229 {
00230 return unite( interval );
00231 }
00232
00234 inline bool QwtInterval::operator==( const QwtInterval &other ) const
00235 {
00236 return ( d_minValue == other.d_minValue ) &&
00237 ( d_maxValue == other.d_maxValue ) &&
00238 ( d_borderFlags == other.d_borderFlags );
00239 }
00240
00242 inline bool QwtInterval::operator!=( const QwtInterval &other ) const
00243 {
00244 return ( !( *this == other ) );
00245 }
00246
00254 inline QwtInterval QwtInterval::operator|( double value ) const
00255 {
00256 return extend( value );
00257 }
00258
00260 inline bool QwtInterval::isNull() const
00261 {
00262 return isValid() && d_minValue >= d_maxValue;
00263 }
00264
00270 inline bool QwtInterval::isValid() const
00271 {
00272 if ( ( d_borderFlags & ExcludeBorders ) == 0 )
00273 return d_minValue <= d_maxValue;
00274 else
00275 return d_minValue < d_maxValue;
00276 }
00277
00284 inline void QwtInterval::invalidate()
00285 {
00286 d_minValue = 0.0;
00287 d_maxValue = -1.0;
00288 }
00289
00290 #ifndef QT_NO_DEBUG_STREAM
00291 QWT_EXPORT QDebug operator<<( QDebug, const QwtInterval & );
00292 #endif
00293
00294 #endif