Main Page | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members | Related Pages

qwt_double_interval.cpp

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 #include <qglobal.h>
00011 #if QT_VERSION >= 0x040000
00012 #include <qalgorithms.h>
00013 #else
00014 #include <qtl.h>
00015 #endif
00016 
00017 #include "qwt_math.h"
00018 #include "qwt_double_interval.h"
00019 
00020 QwtDoubleInterval QwtDoubleInterval::normalized() const
00021 {
00022     if ( !isValid() )
00023     {
00024         return QwtDoubleInterval(d_maxValue, d_minValue);
00025     }
00026     else
00027         return *this;
00028 }
00029 
00030 QwtDoubleInterval QwtDoubleInterval::invert() const
00031 {
00032     return QwtDoubleInterval(d_maxValue, d_minValue);
00033 }
00034 
00035 bool QwtDoubleInterval::contains(double value) const
00036 {
00037     if ( !isValid() )
00038         return false;
00039 
00040     return (value >= d_minValue) && (value <= d_maxValue);
00041 }
00042 
00043 QwtDoubleInterval QwtDoubleInterval::unite(
00044     const QwtDoubleInterval &interval) const
00045 {
00046     if ( !isValid() )
00047     {
00048         if ( !interval.isValid() )
00049             return QwtDoubleInterval();
00050         else
00051             return interval;
00052     }
00053     if ( !interval.isValid() )
00054         return *this;
00055 
00056     const double minValue = qwtMin(d_minValue, interval.minValue());
00057     const double maxValue = qwtMax(d_maxValue, interval.maxValue());
00058 
00059     return QwtDoubleInterval(minValue, maxValue);
00060 }
00061 
00062 QwtDoubleInterval QwtDoubleInterval::intersect(
00063     const QwtDoubleInterval &interval) const
00064 {
00065     if ( !interval.isValid() || !isValid() )
00066         return QwtDoubleInterval();
00067 
00068     QwtDoubleInterval i1 = *this;
00069     QwtDoubleInterval i2 = interval;
00070 
00071     if ( i1.minValue() > i2.minValue() )
00072         qSwap(i1, i2);
00073 
00074     if ( i1.maxValue() < i2.minValue() )
00075         return QwtDoubleInterval();
00076 
00077     return QwtDoubleInterval(i2.minValue(), 
00078                 qwtMin(i1.maxValue(), i2.maxValue()));
00079 }
00080 
00081 QwtDoubleInterval& QwtDoubleInterval::operator|=(
00082     const QwtDoubleInterval &interval)
00083 {
00084     *this = *this | interval;
00085     return *this;
00086 }
00087 
00088 QwtDoubleInterval& QwtDoubleInterval::operator&=(
00089     const QwtDoubleInterval &interval) 
00090 {
00091     *this = *this & interval;
00092     return *this;
00093 }
00094 
00095 bool QwtDoubleInterval::intersects(const QwtDoubleInterval &interval) const
00096 {
00097     if ( !isValid() || !interval.isValid() )
00098         return false;
00099 
00100     QwtDoubleInterval i1 = *this;
00101     QwtDoubleInterval i2 = interval;
00102 
00103     if ( i1.minValue() > i2.minValue() )
00104         qSwap(i1, i2);
00105 
00106     return i1.maxValue() >= i2.minValue();
00107 }
00108 
00109 QwtDoubleInterval QwtDoubleInterval::symmetrize(double center) const
00110 {
00111     if ( !isValid() )
00112         return *this;
00113 
00114     const double delta =
00115         qwtMax(qwtAbs(center - d_maxValue), qwtAbs(center - d_minValue));
00116 
00117     return QwtDoubleInterval(center - delta, center + delta);
00118 }
00119 
00120 QwtDoubleInterval QwtDoubleInterval::limit(
00121     double lBound, double hBound) const
00122 {
00123     if ( !isValid() || lBound > hBound )
00124         return QwtDoubleInterval();
00125 
00126     double minValue = qwtMax(d_minValue, lBound);
00127     minValue = qwtMin(minValue, hBound);
00128 
00129     double maxValue = qwtMax(d_maxValue, lBound);
00130     maxValue = qwtMin(maxValue, hBound);
00131 
00132     return QwtDoubleInterval(minValue, maxValue);
00133 }
00134 
00135 QwtDoubleInterval QwtDoubleInterval::extend(double v) const
00136 {
00137     if ( !isValid() )
00138         return *this;
00139 
00140     return QwtDoubleInterval(
00141         qwtMin(v, d_minValue), qwtMax(v, d_maxValue) );
00142 }
00143 
00144 QwtDoubleInterval& QwtDoubleInterval::operator|=(double value)
00145 {
00146     *this = *this | value;
00147     return *this;
00148 }
00149 

Generated on Mon Jan 30 22:16:25 2006 for Qwt User's Guide by  doxygen 1.4.4