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

# qwt_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 // vim: expandtab
    00011
    00012 #include "qwt_data.h"
    00013
    00014 QwtData::QwtData()
    00015 {
    00016 }
    00017
    00018 QwtData::~QwtData()
    00019 {
    00020 }
    00021
    00033 QwtDoubleRect QwtData::boundingRect() const
    00034 {
    00035     const size_t sz = size();
    00036
    00037     if ( sz <= 0 )
    00038         return QwtDoubleRect(1.0, -1.0, 1.0, -1.0); // invalid
    00039
    00040     double minX, maxX, minY, maxY;
    00041     minX = maxX = x(0);
    00042     minY = maxY = y(0);
    00043
    00044     for ( size_t i = 1; i < sz; i++ )
    00045     {
    00046         const double xv = x(i);
    00047         if ( xv < minX )
    00048             minX = xv;
    00049         if ( xv > maxX )
    00050             maxX = xv;
    00051
    00052         const double yv = y(i);
    00053         if ( yv < minY )
    00054             minY = yv;
    00055         if ( yv > maxY )
    00056             maxY = yv;
    00057     }
    00058     return QwtDoubleRect(minX, maxX, minY, maxY);
    00059 }
    00060
    00061 QwtDoublePointData::QwtDoublePointData(const QwtArray<QwtDoublePoint> &data):
    00062     d_data(data)
    00063 {
    00064 }
    00065
    00067 QwtDoublePointData& QwtDoublePointData::operator=(
    00068     const QwtDoublePointData &data)
    00069 {
    00070     if (this != &data)
    00071     {
    00072         d_data = data.d_data;
    00073     }
    00074     return *this;
    00075 }
    00076
    00077 size_t QwtDoublePointData::size() const
    00078 {
    00079     return d_data.size();
    00080 }
    00081
    00082 double QwtDoublePointData::x(size_t i) const
    00083 {
    00084     return d_data[int(i)].x();
    00085 }
    00086
    00087 double QwtDoublePointData::y(size_t i) const
    00088 {
    00089     return d_data[int(i)].y();
    00090 }
    00091
    00092 QwtData *QwtDoublePointData::copy() const
    00093 {
    00094     return new QwtDoublePointData(d_data);
    00095 }
    00096
    00102 QwtArrayData::QwtArrayData(
    00103     const QwtArray<double> &x, const QwtArray<double> &y): d_x(x), d_y(y)
    00104 {
    00105 }
    00106
    00112 QwtArrayData::QwtArrayData(const double *x, const double *y, size_t size)
    00113 {
    00114     d_x.detach();
    00115     d_x.duplicate(x, size);
    00116     d_y.detach();
    00117     d_y.duplicate(y, size);
    00118 }
    00119
    00121 QwtArrayData& QwtArrayData::operator=(const QwtArrayData &data)
    00122 {
    00123     if (this != &data)
    00124     {
    00125         d_x = data.d_x;
    00126         d_y = data.d_y;
    00127     }
    00128     return *this;
    00129 }
    00130
    00131 size_t QwtArrayData::size() const
    00132 {
    00133     return QMIN(d_x.size(), d_y.size());
    00134 }
    00135
    00136 double QwtArrayData::x(size_t i) const
    00137 {
    00138     return d_x[int(i)];
    00139 }
    00140
    00141 double QwtArrayData::y(size_t i) const
    00142 {
    00143     return d_y[int(i)];
    00144 }
    00145
    00146 QwtData *QwtArrayData::copy() const
    00147 {
    00148     return new QwtArrayData(d_x, d_y);
    00149 }
    00150
    00156 QwtDoubleRect QwtArrayData::boundingRect() const
    00157 {
    00158     const size_t sz = size();
    00159
    00160     if ( sz <= 0 )
    00161         return QwtDoubleRect(1.0, -1.0, 1.0, -1.0); // invalid
    00162
    00163     double minX, maxX, minY, maxY;
    00164     QwtArray<double>::ConstIterator xIt = d_x.begin();
    00165     QwtArray<double>::ConstIterator yIt = d_y.begin();
    00166     QwtArray<double>::ConstIterator end = d_x.begin() + sz;
    00167     minX = maxX = *xIt++;
    00168     minY = maxY = *yIt++;
    00169
    00170     while ( xIt < end )
    00171     {
    00172         const double xv = *xIt++;
    00173         if ( xv < minX )
    00174             minX = xv;
    00175         if ( xv > maxX )
    00176             maxX = xv;
    00177
    00178         const double yv = *yIt++;
    00179         if ( yv < minY )
    00180             minY = yv;
    00181         if ( yv > maxY )
    00182             maxY = yv;
    00183     }
    00184     return QwtDoubleRect(minX, maxX, minY, maxY);
    00185 }
    00186
    00187 QwtCPointerData::QwtCPointerData(const double *x, const double *y,
    00188                                  size_t size):
    00189     d_x(x), d_y(y), d_size(size)
    00190 {
    00191 }
    00192
    00194 QwtCPointerData& QwtCPointerData::operator=(const QwtCPointerData &data)
    00195 {
    00196     if (this != &data)
    00197     {
    00198         d_x = data.d_x;
    00199         d_y = data.d_y;
    00200         d_size = data.d_size;
    00201     }
    00202     return *this;
    00203 }
    00204
    00205 size_t QwtCPointerData::size() const
    00206 {
    00207     return d_size;
    00208 }
    00209
    00210 double QwtCPointerData::x(size_t i) const
    00211 {
    00212     return d_x[int(i)];
    00213 }
    00214
    00215 double QwtCPointerData::y(size_t i) const
    00216 {
    00217     return d_y[int(i)];
    00218 }
    00219
    00220 QwtData *QwtCPointerData::copy() const
    00221 {
    00222     return new QwtCPointerData(d_x, d_y, d_size);
    00223 }
    00224
    00230 QwtDoubleRect QwtCPointerData::boundingRect() const
    00231 {
    00232     const size_t sz = size();
    00233
    00234     if ( sz <= 0 )
    00235         return QwtDoubleRect(1.0, -1.0, 1.0, -1.0); // invalid
    00236
    00237     double minX, maxX, minY, maxY;
    00238     const double *xIt = d_x;
    00239     const double *yIt = d_y;
    00240     const double *end = d_x + sz;
    00241     minX = maxX = *xIt++;
    00242     minY = maxY = *yIt++;
    00243
    00244     while ( xIt < end )
    00245     {
    00246         const double xv = *xIt++;
    00247         if ( xv < minX )
    00248             minX = xv;
    00249         if ( xv > maxX )
    00250             maxX = xv;
    00251
    00252         const double yv = *yIt++;
    00253         if ( yv < minY )
    00254             minY = yv;
    00255         if ( yv > maxY )
    00256             maxY = yv;
    00257     }
    00258     return QwtDoubleRect(minX, maxX, minY, maxY);
    00259 }
    00260
    00261 // Local Variables:
    00262 // mode: C++
    00263 // c-file-style: "stroustrup"
    00264 // indent-tabs-mode: nil
    00265 // End: