Public Types | Public Member Functions

QwtDoubleInterval Class Reference

A class representing an interval. More...

#include <qwt_double_interval.h>

List of all members.

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
QwtDoubleIntervaloperator|= (const QwtDoubleInterval &)
 Unites this interval with the given interval.
QwtDoubleIntervaloperator&= (const QwtDoubleInterval &)
 Intersects this interval with the given interval.
QwtDoubleInterval extend (double value) const
QwtDoubleInterval operator| (double) const
QwtDoubleIntervaloperator|= (double)
bool isValid () const
bool isNull () const
void invalidate ()
QwtDoubleInterval symmetrize (double value) const

Detailed Description

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.


Member Enumeration Documentation

Flag indicating if a border is included/excluded from an interval

  • IncludeBorders
    min/max values are inside the interval
  • ExcludeMinimum
    min value is not included in the interval
  • ExcludeMaximum
    max value is not included in the interval
  • ExcludeBorders
    min/max values are not included in the interval
See also:
setBorderMode(), testBorderMode()
Enumerator:
IncludeBorders 
ExcludeMinimum 
ExcludeMaximum 
ExcludeBorders 

Definition at line 38 of file qwt_double_interval.h.


Constructor & Destructor Documentation

QwtDoubleInterval::QwtDoubleInterval (  ) [inline]

Default Constructor.

Creates an invalid interval [0.0, -1.0]

See also:
setInterval(), isValid()

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

Parameters:
minValueMinimum value
maxValueMaximum value
borderFlagsInclude/Exclude borders

Definition at line 123 of file qwt_double_interval.h.

                                                          :
    d_minValue(minValue),
    d_maxValue(maxValue),
    d_borderFlags(borderFlags)
{
}

Member Function Documentation

int QwtDoubleInterval::borderFlags (  ) const [inline]
Returns:
Border flags
See also:
setBorderFlags()

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

Parameters:
valueValue
Returns:
true, if value >= minValue() && value <= maxValue()

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

Parameters:
valueValue
See also:
isValid()

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]

See also:
isValid()

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

Returns:
Inverted interval
See also:
normalized()

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]
Returns:
true, if isValid() && (minValue() >= maxValue())

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]
QwtDoubleInterval QwtDoubleInterval::limited ( double  lowerBound,
double  upperBound 
) const

Limit the interval, keeping the border modes

Parameters:
lowerBoundLower limit
upperBoundUpper limit
Returns:
Limited interval

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]
double QwtDoubleInterval::minValue (  ) const [inline]
QwtDoubleInterval QwtDoubleInterval::normalized (  ) const

Normalize the limits of the interval.

If maxValue() < minValue() the limits will be inverted.

Returns:
Normalized interval
See also:
isValid(), 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

See also:
intersect()

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

See also:
unite()

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

See also:
extend()

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

Parameters:
borderFlagsOr'd BorderMode flags
See also:
borderFlags()

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

Parameters:
minValueMinimum value
maxValueMaximum value
borderFlagsInclude/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

Parameters:
maxValueMaximum 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

Parameters:
minValueMinimum 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.

Parameters:
valueCenter
Returns:
Interval with value as 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]

The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines