A class representing an interval. More...
#include <qwt_double_interval.h>
Public Types | |
enum | BorderMode { IncludeBorders = 0, ExcludeMinimum = 1, ExcludeMaximum = 2, ExcludeBorders = ExcludeMinimum | ExcludeMaximum } |
Public Member Functions | |
QwtDoubleInterval () | |
Default Constructor. | |
QwtDoubleInterval (double minValue, double maxValue, int borderFlags=IncludeBorders) | |
void | setInterval (double minValue, double maxValue, int borderFlags=IncludeBorders) |
QwtDoubleInterval | normalized () const |
Normalize the limits of the interval. | |
QwtDoubleInterval | inverted () const |
QwtDoubleInterval | limited (double minValue, double maxValue) const |
int | operator== (const QwtDoubleInterval &) const |
Compare two intervals. | |
int | operator!= (const QwtDoubleInterval &) const |
Compare two intervals. | |
void | setBorderFlags (int) |
int | borderFlags () const |
double | minValue () const |
double | maxValue () const |
double | width () const |
void | setMinValue (double) |
void | setMaxValue (double) |
bool | contains (double value) const |
bool | intersects (const QwtDoubleInterval &) const |
QwtDoubleInterval | intersect (const QwtDoubleInterval &) const |
Intersect 2 intervals. | |
QwtDoubleInterval | unite (const QwtDoubleInterval &) const |
Unite 2 intervals. | |
QwtDoubleInterval | operator| (const QwtDoubleInterval &) const |
QwtDoubleInterval | operator& (const QwtDoubleInterval &) const |
QwtDoubleInterval & | operator|= (const QwtDoubleInterval &) |
Unites this interval with the given interval. | |
QwtDoubleInterval & | operator&= (const QwtDoubleInterval &) |
Intersects this interval with the given interval. | |
QwtDoubleInterval | extend (double value) const |
QwtDoubleInterval | operator| (double) const |
QwtDoubleInterval & | operator|= (double) |
bool | isValid () const |
bool | isNull () const |
void | invalidate () |
QwtDoubleInterval | symmetrize (double value) const |
A class representing an interval.
The interval is represented by 2 doubles, the lower and the upper limit.
Definition at line 21 of file qwt_double_interval.h.
Flag indicating if a border is included/excluded from an interval
Definition at line 38 of file qwt_double_interval.h.
{ IncludeBorders = 0, ExcludeMinimum = 1, ExcludeMaximum = 2, ExcludeBorders = ExcludeMinimum | ExcludeMaximum };
QwtDoubleInterval::QwtDoubleInterval | ( | ) | [inline] |
Default Constructor.
Creates an invalid interval [0.0, -1.0]
Definition at line 107 of file qwt_double_interval.h.
Referenced by extend(), intersect(), inverted(), limited(), symmetrize(), and unite().
: d_minValue(0.0), d_maxValue(-1.0), d_borderFlags(IncludeBorders) { }
QwtDoubleInterval::QwtDoubleInterval | ( | double | minValue, |
double | maxValue, | ||
int | borderFlags = IncludeBorders |
||
) | [inline] |
Constructor
Build an interval with from min/max values
minValue | Minimum value |
maxValue | Maximum value |
borderFlags | Include/Exclude borders |
Definition at line 123 of file qwt_double_interval.h.
: d_minValue(minValue), d_maxValue(maxValue), d_borderFlags(borderFlags) { }
int QwtDoubleInterval::borderFlags | ( | ) | const [inline] |
Definition at line 161 of file qwt_double_interval.h.
Referenced by intersect(), intersects(), inverted(), setBorderFlags(), setInterval(), and unite().
{
return d_borderFlags;
}
bool QwtDoubleInterval::contains | ( | double | value ) | const |
Test if a value is inside an interval
value | Value |
Definition at line 64 of file qwt_double_interval.cpp.
References ExcludeMaximum, ExcludeMinimum, and isValid().
Referenced by QwtRasterData::contourLines().
{ if ( !isValid() ) return false; if ( value < d_minValue || value > d_maxValue ) return false; if ( value == d_minValue && d_borderFlags & ExcludeMinimum ) return false; if ( value == d_maxValue && d_borderFlags & ExcludeMaximum ) return false; return true; }
QwtDoubleInterval QwtDoubleInterval::extend | ( | double | value ) | const |
Extend the interval
If value is below minValue, value becomes the lower limit. If value is above maxValue, value becomes the upper limit.
extend has no effect for invalid intervals
value | Value |
Definition at line 307 of file qwt_double_interval.cpp.
References isValid(), QwtDoubleInterval(), qwtMax, and qwtMin.
Referenced by QwtLog10ScaleEngine::autoScale(), QwtLinearScaleEngine::autoScale(), and operator|().
{ if ( !isValid() ) return *this; return QwtDoubleInterval( qwtMin(value, d_minValue), qwtMax(value, d_maxValue), d_borderFlags ); }
QwtDoubleInterval QwtDoubleInterval::intersect | ( | const QwtDoubleInterval & | other ) | const |
Intersect 2 intervals.
Definition at line 141 of file qwt_double_interval.cpp.
References borderFlags(), ExcludeMaximum, ExcludeMinimum, isValid(), maxValue(), minValue(), QwtDoubleInterval(), setBorderFlags(), setMaxValue(), and setMinValue().
Referenced by operator&().
{ if ( !other.isValid() || !isValid() ) return QwtDoubleInterval(); QwtDoubleInterval i1 = *this; QwtDoubleInterval i2 = other; // swap i1/i2, so that the minimum of i1 // is smaller then the minimum of i2 if ( i1.minValue() > i2.minValue() ) { qSwap(i1, i2); } else if ( i1.minValue() == i2.minValue() ) { if ( i1.borderFlags() & ExcludeMinimum ) qSwap(i1, i2); } if ( i1.maxValue() < i2.minValue() ) { return QwtDoubleInterval(); } if ( i1.maxValue() == i2.minValue() ) { if ( i1.borderFlags() & ExcludeMaximum || i2.borderFlags() & ExcludeMinimum ) { return QwtDoubleInterval(); } } QwtDoubleInterval intersected; int flags = 0; intersected.setMinValue(i2.minValue()); flags |= i2.borderFlags() & ExcludeMinimum; if ( i1.maxValue() < i2.maxValue() ) { intersected.setMaxValue(i1.maxValue()); flags |= i1.borderFlags() & ExcludeMaximum; } else if ( i2.maxValue() < i1.maxValue() ) { intersected.setMaxValue(i2.maxValue()); flags |= i2.borderFlags() & ExcludeMaximum; } else // i1.maxValue() == i2.maxValue() { intersected.setMaxValue(i1.maxValue() ); flags |= i1.borderFlags() & i2.borderFlags() & ExcludeMaximum; } intersected.setBorderFlags(flags); return intersected; }
bool QwtDoubleInterval::intersects | ( | const QwtDoubleInterval & | other ) | const |
Test if two intervals overlap
Definition at line 222 of file qwt_double_interval.cpp.
References borderFlags(), ExcludeMaximum, ExcludeMinimum, isValid(), maxValue(), and minValue().
{ if ( !isValid() || !other.isValid() ) return false; QwtDoubleInterval i1 = *this; QwtDoubleInterval i2 = other; // swap i1/i2, so that the minimum of i1 // is smaller then the minimum of i2 if ( i1.minValue() > i2.minValue() ) { qSwap(i1, i2); } else if ( i1.minValue() == i2.minValue() && i1.borderFlags() & ExcludeMinimum ) { qSwap(i1, i2); } if ( i1.maxValue() > i2.minValue() ) { return true; } if ( i1.maxValue() == i2.minValue() ) { return !( (i1.borderFlags() & ExcludeMaximum) || (i2.borderFlags() & ExcludeMinimum) ); } return false; }
void QwtDoubleInterval::invalidate | ( | ) | [inline] |
Invalidate the interval
The limits are set to interval [0.0, -1.0]
Definition at line 278 of file qwt_double_interval.h.
{ d_minValue = 0.0; d_maxValue = -1.0; }
QwtDoubleInterval QwtDoubleInterval::inverted | ( | ) | const |
Invert the limits of the interval
Definition at line 47 of file qwt_double_interval.cpp.
References borderFlags(), ExcludeMaximum, ExcludeMinimum, and QwtDoubleInterval().
Referenced by normalized().
{ int borderFlags = 0; if ( d_borderFlags & ExcludeMinimum ) borderFlags |= ExcludeMaximum; if ( d_borderFlags & ExcludeMaximum ) borderFlags |= ExcludeMinimum; return QwtDoubleInterval(d_maxValue, d_minValue, borderFlags); }
bool QwtDoubleInterval::isNull | ( | ) | const [inline] |
Definition at line 254 of file qwt_double_interval.h.
References isValid().
Referenced by QwtPlotRescaler::rescale().
{ return isValid() && d_minValue >= d_maxValue; }
bool QwtDoubleInterval::isValid | ( | ) | const [inline] |
A interval is valid when minValue() <= maxValue(). In case of QwtDoubleInterval::ExcludeBorders it is true when minValue() < maxValue()
Definition at line 264 of file qwt_double_interval.h.
References ExcludeBorders.
Referenced by QwtIntervalData::boundingRect(), QwtColorMap::colorTable(), QwtScaleEngine::contains(), contains(), QwtRasterData::contourLines(), QwtScaleWidget::dimForLength(), QwtScaleWidget::draw(), QwtScaleWidget::drawColorBar(), extend(), intersect(), intersects(), isNull(), QwtScaleWidget::layoutScale(), limited(), QwtScaleEngine::strip(), symmetrize(), unite(), QwtPlot::updateAxes(), and width().
{ if ( (d_borderFlags & ExcludeBorders) == 0 ) return d_minValue <= d_maxValue; else return d_minValue < d_maxValue; }
QwtDoubleInterval QwtDoubleInterval::limited | ( | double | lowerBound, |
double | upperBound | ||
) | const |
Limit the interval, keeping the border modes
lowerBound | Lower limit |
upperBound | Upper limit |
Definition at line 281 of file qwt_double_interval.cpp.
References isValid(), maxValue(), minValue(), QwtDoubleInterval(), qwtMax, and qwtMin.
Referenced by QwtLog10ScaleEngine::autoScale(), and QwtLog10ScaleEngine::divideScale().
{ if ( !isValid() || lowerBound > upperBound ) return QwtDoubleInterval(); double minValue = qwtMax(d_minValue, lowerBound); minValue = qwtMin(minValue, upperBound); double maxValue = qwtMax(d_maxValue, lowerBound); maxValue = qwtMin(maxValue, upperBound); return QwtDoubleInterval(minValue, maxValue, d_borderFlags); }
double QwtDoubleInterval::maxValue | ( | ) | const [inline] |
Definition at line 193 of file qwt_double_interval.h.
Referenced by QwtLinearScaleEngine::align(), QwtLog10ScaleEngine::autoScale(), QwtLinearScaleEngine::autoScale(), QwtIntervalData::boundingRect(), QwtLinearColorMap::colorIndex(), QwtScaleEngine::contains(), QwtLog10ScaleEngine::divideScale(), QmitkHistogram::draw(), QwtPlotRescaler::expandInterval(), intersect(), intersects(), limited(), QwtLog10ScaleEngine::log10(), QwtLog10ScaleEngine::pow10(), QwtPlotRescaler::rescale(), QwtScaleDiv::setInterval(), setInterval(), setMaxValue(), QwtAbstractScale::setScale(), unite(), and QwtPlot::updateAxes().
{
return d_maxValue;
}
double QwtDoubleInterval::minValue | ( | ) | const [inline] |
Definition at line 187 of file qwt_double_interval.h.
Referenced by QwtLinearScaleEngine::align(), QwtLog10ScaleEngine::autoScale(), QwtLinearScaleEngine::autoScale(), QwtIntervalData::boundingRect(), QwtLinearColorMap::colorIndex(), QwtColorMap::colorTable(), QwtScaleEngine::contains(), QwtLog10ScaleEngine::divideScale(), QmitkHistogram::draw(), QwtPlotRescaler::expandInterval(), intersect(), intersects(), limited(), QwtLog10ScaleEngine::log10(), QwtLog10ScaleEngine::pow10(), QwtPlotRescaler::rescale(), QwtAlphaColorMap::rgb(), QwtLinearColorMap::rgb(), QwtScaleDiv::setInterval(), setInterval(), setMinValue(), QwtAbstractScale::setScale(), unite(), and QwtPlot::updateAxes().
{
return d_minValue;
}
QwtDoubleInterval QwtDoubleInterval::normalized | ( | ) | const |
Normalize the limits of the interval.
If maxValue() < minValue() the limits will be inverted.
Definition at line 28 of file qwt_double_interval.cpp.
References ExcludeMinimum, and inverted().
Referenced by QwtLinearScaleEngine::autoScale(), QwtLog10ScaleEngine::divideScale(), QwtLinearScaleEngine::divideScale(), QwtScaleWidget::drawColorBar(), and QwtPlotRescaler::interval().
{ if ( d_minValue > d_maxValue ) { return inverted(); } if ( d_minValue == d_maxValue && d_borderFlags == ExcludeMinimum ) { return inverted(); } return *this; }
int QwtDoubleInterval::operator!= | ( | const QwtDoubleInterval & | other ) | const [inline] |
Compare two intervals.
Definition at line 239 of file qwt_double_interval.h.
{ return (!(*this == other)); }
QwtDoubleInterval QwtDoubleInterval::operator& | ( | const QwtDoubleInterval & | interval ) | const [inline] |
Intersection of two intervals
Definition at line 214 of file qwt_double_interval.h.
References intersect().
{ return intersect(interval); }
QwtDoubleInterval & QwtDoubleInterval::operator&= | ( | const QwtDoubleInterval & | interval ) |
Intersects this interval with the given interval.
Definition at line 212 of file qwt_double_interval.cpp.
{ *this = *this & interval; return *this; }
int QwtDoubleInterval::operator== | ( | const QwtDoubleInterval & | other ) | const [inline] |
Compare two intervals.
Definition at line 231 of file qwt_double_interval.h.
{
return (d_minValue == other.d_minValue) &&
(d_maxValue == other.d_maxValue) &&
(d_borderFlags == other.d_borderFlags);
}
QwtDoubleInterval QwtDoubleInterval::operator| | ( | const QwtDoubleInterval & | interval ) | const [inline] |
Union of two intervals
Definition at line 224 of file qwt_double_interval.h.
References unite().
{ return unite(interval); }
QwtDoubleInterval QwtDoubleInterval::operator| | ( | double | value ) | const [inline] |
Extend an interval
Definition at line 248 of file qwt_double_interval.h.
References extend().
{ return extend(value); }
QwtDoubleInterval & QwtDoubleInterval::operator|= | ( | const QwtDoubleInterval & | interval ) |
Unites this interval with the given interval.
Definition at line 204 of file qwt_double_interval.cpp.
{ *this = *this | interval; return *this; }
QwtDoubleInterval & QwtDoubleInterval::operator|= | ( | double | value ) |
Definition at line 316 of file qwt_double_interval.cpp.
{ *this = *this | value; return *this; }
void QwtDoubleInterval::setBorderFlags | ( | int | borderFlags ) | [inline] |
Change the border flags
borderFlags | Or'd BorderMode flags |
Definition at line 152 of file qwt_double_interval.h.
References borderFlags().
Referenced by intersect(), and unite().
{ d_borderFlags = borderFlags; }
void QwtDoubleInterval::setInterval | ( | double | minValue, |
double | maxValue, | ||
int | borderFlags = IncludeBorders |
||
) | [inline] |
Assign the limits of the interval
minValue | Minimum value |
maxValue | Maximum value |
borderFlags | Include/Exclude borders |
Definition at line 138 of file qwt_double_interval.h.
References borderFlags(), maxValue(), and minValue().
Referenced by QwtLog10ScaleEngine::autoScale().
{ d_minValue = minValue; d_maxValue = maxValue; d_borderFlags = borderFlags; }
void QwtDoubleInterval::setMaxValue | ( | double | maxValue ) | [inline] |
Assign the upper limit of the interval
maxValue | Maximum value |
Definition at line 181 of file qwt_double_interval.h.
References maxValue().
Referenced by QwtLinearScaleEngine::autoScale(), QwtPlotRescaler::expandInterval(), intersect(), and unite().
{ d_maxValue = maxValue; }
void QwtDoubleInterval::setMinValue | ( | double | minValue ) | [inline] |
Assign the lower limit of the interval
minValue | Minimum value |
Definition at line 171 of file qwt_double_interval.h.
References minValue().
Referenced by QwtLinearScaleEngine::autoScale(), QwtPlotRescaler::expandInterval(), intersect(), and unite().
{ d_minValue = minValue; }
QwtDoubleInterval QwtDoubleInterval::symmetrize | ( | double | value ) | const |
Adjust the limit that is closer to value, so that value becomes the center of the interval.
value | Center |
Definition at line 262 of file qwt_double_interval.cpp.
References isValid(), qwtAbs, QwtDoubleInterval(), and qwtMax.
Referenced by QwtLinearScaleEngine::autoScale().
{ if ( !isValid() ) return *this; const double delta = qwtMax(qwtAbs(value - d_maxValue), qwtAbs(value - d_minValue)); return QwtDoubleInterval(value - delta, value + delta); }
QwtDoubleInterval QwtDoubleInterval::unite | ( | const QwtDoubleInterval & | other ) | const |
Unite 2 intervals.
Definition at line 82 of file qwt_double_interval.cpp.
References borderFlags(), ExcludeMaximum, ExcludeMinimum, isValid(), maxValue(), minValue(), QwtDoubleInterval(), setBorderFlags(), setMaxValue(), and setMinValue().
Referenced by operator|().
{ /* If one of the intervals is invalid return the other one. If both are invalid return an invalid default interval */ if ( !isValid() ) { if ( !other.isValid() ) return QwtDoubleInterval(); else return other; } if ( !other.isValid() ) return *this; QwtDoubleInterval united; int flags = 0; // minimum if ( d_minValue < other.minValue() ) { united.setMinValue(d_minValue); flags &= d_borderFlags & ExcludeMinimum; } else if ( other.minValue() < d_minValue ) { united.setMinValue(other.minValue()); flags &= other.borderFlags() & ExcludeMinimum; } else // d_minValue == other.minValue() { united.setMinValue(d_minValue); flags &= (d_borderFlags & other.borderFlags()) & ExcludeMinimum; } // maximum if ( d_maxValue > other.maxValue() ) { united.setMaxValue(d_maxValue); flags &= d_borderFlags & ExcludeMaximum; } else if ( other.maxValue() > d_maxValue ) { united.setMaxValue(other.maxValue()); flags &= other.borderFlags() & ExcludeMaximum; } else // d_maxValue == other.maxValue() ) { united.setMaxValue(d_maxValue); flags &= d_borderFlags & other.borderFlags() & ExcludeMaximum; } united.setBorderFlags(flags); return united; }
double QwtDoubleInterval::width | ( | ) | const [inline] |
Return the width of an interval The width of invalid intervals is 0.0, otherwise the result is maxValue() - minValue().
Definition at line 205 of file qwt_double_interval.h.
References isValid().
Referenced by QwtLog10ScaleEngine::autoScale(), QwtLinearScaleEngine::autoScale(), QwtLinearColorMap::colorIndex(), QwtColorMap::colorTable(), QwtScaleEngine::contains(), QwtLog10ScaleEngine::divideScale(), QwtLinearScaleEngine::divideScale(), QwtPlotRescaler::expandInterval(), QwtPlotRescaler::expandScale(), QwtAlphaColorMap::rgb(), QwtLinearColorMap::rgb(), and QwtPlotRescaler::syncScale().
{ return isValid() ? (d_maxValue - d_minValue) : 0.0; }