00001 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- ***************************** 00002 * Qwt Widget Library 00003 * Copyright (C) 1997 Josef Wilgen 00004 * Copyright (C) 2002 Uwe Rathmann 00005 * 00006 * This library is free software; you can redistribute it and/or 00007 * modify it under the terms of the Qwt License, Version 1.0 00008 *****************************************************************************/ 00009 00010 #ifndef QWT_DOUBLE_INTERVAL_H 00011 #define QWT_DOUBLE_INTERVAL_H 00012 00013 #include "qwt_global.h" 00014 00015 class QWT_EXPORT QwtDoubleInterval 00016 { 00017 public: 00018 inline QwtDoubleInterval(); 00019 inline QwtDoubleInterval(double minValue, double maxValue); 00020 00021 inline void setInterval(double minValue, double maxValue); 00022 00023 QwtDoubleInterval normalized() const; 00024 QwtDoubleInterval invert() const; 00025 QwtDoubleInterval limit(double minValue, double maxValue) const; 00026 00027 inline int operator==(const QwtDoubleInterval &) const; 00028 inline int operator!=(const QwtDoubleInterval &) const; 00029 00030 inline double minValue() const; 00031 inline double maxValue() const; 00032 00033 inline double width() const; 00034 00035 inline void setMinValue(double); 00036 inline void setMaxValue(double); 00037 00038 bool contains(double value) const; 00039 00040 bool intersects(const QwtDoubleInterval &) const; 00041 QwtDoubleInterval intersect(const QwtDoubleInterval &) const; 00042 QwtDoubleInterval unite(const QwtDoubleInterval &) const; 00043 00044 inline QwtDoubleInterval operator|(const QwtDoubleInterval &) const; 00045 inline QwtDoubleInterval operator&(const QwtDoubleInterval &) const; 00046 00047 QwtDoubleInterval &operator|=(const QwtDoubleInterval &); 00048 QwtDoubleInterval &operator&=(const QwtDoubleInterval &); 00049 00050 QwtDoubleInterval extend(double value) const; 00051 inline QwtDoubleInterval operator|(double) const; 00052 QwtDoubleInterval &operator|=(double); 00053 00054 inline bool isValid() const; 00055 inline bool isNull() const; 00056 inline void invalidate(); 00057 00058 QwtDoubleInterval symmetrize(double value) const; 00059 00060 private: 00061 double d_minValue; 00062 double d_maxValue; 00063 }; 00064 00065 inline QwtDoubleInterval::QwtDoubleInterval(): 00066 d_minValue(0.0), 00067 d_maxValue(-1.0) 00068 { 00069 } 00070 00071 inline QwtDoubleInterval::QwtDoubleInterval(double minValue, double maxValue): 00072 d_minValue(minValue), 00073 d_maxValue(maxValue) 00074 { 00075 } 00076 00077 inline void QwtDoubleInterval::setInterval(double minValue, double maxValue) 00078 { 00079 d_minValue = minValue; 00080 d_maxValue = maxValue; 00081 } 00082 00083 inline void QwtDoubleInterval::setMinValue(double minValue) 00084 { 00085 d_minValue = minValue; 00086 } 00087 00088 inline void QwtDoubleInterval::setMaxValue(double maxValue) 00089 { 00090 d_maxValue = maxValue; 00091 } 00092 00093 inline double QwtDoubleInterval::minValue() const 00094 { 00095 return d_minValue; 00096 } 00097 00098 inline double QwtDoubleInterval::maxValue() const 00099 { 00100 return d_maxValue; 00101 } 00102 00103 inline double QwtDoubleInterval::width() const 00104 { 00105 return isValid() ? (d_maxValue - d_minValue) : 0.0; 00106 } 00107 00108 inline QwtDoubleInterval QwtDoubleInterval::operator&( 00109 const QwtDoubleInterval &interval ) const 00110 { 00111 return intersect(interval); 00112 } 00113 00114 inline QwtDoubleInterval QwtDoubleInterval::operator|( 00115 const QwtDoubleInterval &interval) const 00116 { 00117 return unite(interval); 00118 } 00119 00120 inline int QwtDoubleInterval::operator==(const QwtDoubleInterval &other) const 00121 { 00122 return (d_minValue == other.d_minValue) && 00123 (d_maxValue == other.d_maxValue); 00124 } 00125 00126 inline int QwtDoubleInterval::operator!=(const QwtDoubleInterval &other) const 00127 { 00128 return (!(*this == other)); 00129 } 00130 00131 inline QwtDoubleInterval QwtDoubleInterval::operator|(double value) const 00132 { 00133 return extend(value); 00134 } 00135 00136 inline bool QwtDoubleInterval::isNull() const 00137 { 00138 return d_minValue >= d_maxValue; 00139 } 00140 00141 inline bool QwtDoubleInterval::isValid() const 00142 { 00143 return d_minValue <= d_maxValue; 00144 } 00145 00146 inline void QwtDoubleInterval::invalidate() 00147 { 00148 d_minValue = 0.0; 00149 d_maxValue = -1.0; 00150 } 00151 #endif