qwt_interval_data.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 "qwt_math.h"
00011 #include "qwt_interval_data.h"
00012 
00013 QwtIntervalData::QwtIntervalData()
00014 {
00015 }
00016 
00017 QwtIntervalData::QwtIntervalData(
00018         const QwtArray<QwtDoubleInterval> &intervals, 
00019         const QwtArray<double> &values):
00020     d_intervals(intervals),
00021     d_values(values)
00022 {
00023 }
00024     
00025 void QwtIntervalData::setData(
00026     const QwtArray<QwtDoubleInterval> &intervals,
00027     const QwtArray<double> &values)
00028 {
00029     d_intervals = intervals;
00030     d_values = values;
00031 }
00032 
00033 QwtDoubleRect QwtIntervalData::boundingRect() const
00034 {
00035     double minX, maxX, minY, maxY;
00036     minX = maxX = minY = maxY = 0.0;
00037 
00038     bool isValid = false;
00039 
00040     const size_t sz = size();
00041     for ( size_t i = 0; i < sz; i++ )
00042     {
00043         const QwtDoubleInterval intv = interval(i);
00044         if ( !intv.isValid() )
00045             continue;
00046 
00047         const double v = value(i);
00048 
00049         if ( !isValid )
00050         {
00051             minX = intv.minValue();
00052             maxX = intv.maxValue();
00053             minY = maxY = v;
00054 
00055             isValid = true;
00056         }
00057         else
00058         {
00059             if ( intv.minValue() < minX )
00060                 minX = intv.minValue();
00061             if ( intv.maxValue() > maxX )
00062                 maxX = intv.maxValue();
00063 
00064             if ( v < minY )
00065                 minY = v;
00066             if ( v > maxY )
00067                 maxY = v;
00068         }
00069     }
00070     if ( !isValid )
00071         return QwtDoubleRect(1.0, 1.0, -2.0, -2.0); // invalid
00072 
00073     return QwtDoubleRect(minX, minY, maxX - minX, maxY - minY);
00074 }

Generated on Mon Feb 26 21:22:36 2007 for Qwt User's Guide by  doxygen 1.4.6