| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295 | /* -*- mode: C++ ; c-file-style: "stroustrup" -*- ***************************** * Qwt Widget Library * Copyright (C) 1997   Josef Wilgen * Copyright (C) 2002   Uwe Rathmann * * This library is free software; you can redistribute it and/or * modify it under the terms of the Qwt License, Version 1.0 *****************************************************************************/#ifndef QWT_INTERVAL_H#define QWT_INTERVAL_H#include "qwt_global.h"#ifndef QT_NO_DEBUG_STREAM#include <qdebug.h>#endif/*!  \brief A class representing an interval  The interval is represented by 2 doubles, the lower and the upper limit.*/class QWT_EXPORT QwtInterval{public:    /*!      Flag indicating if a border is included/excluded from an interval      - IncludeBorders\n        min/max values are inside the interval      - ExcludeMinimum\n        min value is not included in the interval      - ExcludeMaximum\n        max value is not included in the interval      - ExcludeBorders\n        min/max values are not included in the interval      \sa setBorderMode(), testBorderMode()    */    enum BorderMode    {        IncludeBorders = 0,        ExcludeMinimum = 1,        ExcludeMaximum = 2,        ExcludeBorders = ExcludeMinimum | ExcludeMaximum    };    QwtInterval();    QwtInterval( double minValue, double maxValue,        int borderFlags = IncludeBorders );    void setInterval( double minValue, double maxValue,        int borderFlags = IncludeBorders );    QwtInterval normalized() const;    QwtInterval inverted() const;    QwtInterval limited( double minValue, double maxValue ) const;    bool operator==( const QwtInterval & ) const;    bool operator!=( const QwtInterval & ) const;    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 QwtInterval & ) const;    QwtInterval intersect( const QwtInterval & ) const;    QwtInterval unite( const QwtInterval & ) const;    QwtInterval operator|( const QwtInterval & ) const;    QwtInterval operator&( const QwtInterval & ) const;    QwtInterval &operator|=( const QwtInterval & );    QwtInterval &operator&=( const QwtInterval & );    QwtInterval extend( double value ) const;    QwtInterval operator|( double ) const;    QwtInterval &operator|=( double );    bool isValid() const;    bool isNull() const;    void invalidate();    QwtInterval symmetrize( double value ) const;private:    double d_minValue;    double d_maxValue;    int d_borderFlags;};/*!  \brief Default Constructor  Creates an invalid interval [0.0, -1.0]  \sa setInterval(), isValid()*/inline QwtInterval::QwtInterval():    d_minValue( 0.0 ),    d_maxValue( -1.0 ),    d_borderFlags( IncludeBorders ){}/*!   Constructor   Build an interval with from min/max values   \param minValue Minimum value   \param maxValue Maximum value   \param borderFlags Include/Exclude borders*/inline QwtInterval::QwtInterval(        double minValue, double maxValue, int borderFlags ):    d_minValue( minValue ),    d_maxValue( maxValue ),    d_borderFlags( borderFlags ){}/*!   Assign the limits of the interval   \param minValue Minimum value   \param maxValue Maximum value   \param borderFlags Include/Exclude borders*/inline void QwtInterval::setInterval(    double minValue, double maxValue, int borderFlags ){    d_minValue = minValue;    d_maxValue = maxValue;    d_borderFlags = borderFlags;}/*!   Change the border flags   \param borderFlags Or'd BorderMode flags   \sa borderFlags()*/inline void QwtInterval::setBorderFlags( int borderFlags ){    d_borderFlags = borderFlags;}/*!   \return Border flags   \sa setBorderFlags()*/inline int QwtInterval::borderFlags() const{    return d_borderFlags;}/*!   Assign the lower limit of the interval   \param minValue Minimum value*/inline void QwtInterval::setMinValue( double minValue ){    d_minValue = minValue;}/*!   Assign the upper limit of the interval   \param maxValue Maximum value*/inline void QwtInterval::setMaxValue( double maxValue ){    d_maxValue = maxValue;}//! \return Lower limit of the intervalinline double QwtInterval::minValue() const{    return d_minValue;}//! \return Upper limit of the intervalinline double QwtInterval::maxValue() const{    return d_maxValue;}/*!   Return the width of an interval   The width of invalid intervals is 0.0, otherwise the result is   maxValue() - minValue().   \sa isValid()*/inline double QwtInterval::width() const{    return isValid() ? ( d_maxValue - d_minValue ) : 0.0;}/*!   Intersection of two intervals   \sa intersect()*/inline QwtInterval QwtInterval::operator&(    const QwtInterval &interval ) const{    return intersect( interval );}/*!   Union of two intervals   \sa unite()*/inline QwtInterval QwtInterval::operator|(    const QwtInterval &interval ) const{    return unite( interval );}//! Compare two intervalsinline bool QwtInterval::operator==( const QwtInterval &other ) const{    return ( d_minValue == other.d_minValue ) &&           ( d_maxValue == other.d_maxValue ) &&           ( d_borderFlags == other.d_borderFlags );}//! Compare two intervalsinline bool QwtInterval::operator!=( const QwtInterval &other ) const{    return ( !( *this == other ) );}/*!   Extend an interval   \param value Value   \return Extended interval   \sa extend()*/inline QwtInterval QwtInterval::operator|( double value ) const{    return extend( value );}//! \return true, if isValid() && (minValue() >= maxValue())inline bool QwtInterval::isNull() const{    return isValid() && d_minValue >= d_maxValue;}/*!   A interval is valid when minValue() <= maxValue().   In case of QwtInterval::ExcludeBorders it is true   when minValue() < maxValue()*/inline bool QwtInterval::isValid() const{    if ( ( d_borderFlags & ExcludeBorders ) == 0 )        return d_minValue <= d_maxValue;    else        return d_minValue < d_maxValue;}/*!  Invalidate the interval  The limits are set to interval [0.0, -1.0]  \sa isValid()*/inline void QwtInterval::invalidate(){    d_minValue = 0.0;    d_maxValue = -1.0;}#ifndef QT_NO_DEBUG_STREAMQWT_EXPORT QDebug operator<<( QDebug, const QwtInterval & );#endif#endif
 |