00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #include "qwt_math.h"
00011 #include "qwt_data.h"
00012
00014 QwtData::QwtData()
00015 {
00016 }
00017
00019 QwtData::~QwtData()
00020 {
00021 }
00022
00034 QwtDoubleRect QwtData::boundingRect() const
00035 {
00036 const size_t sz = size();
00037
00038 if ( sz <= 0 )
00039 return QwtDoubleRect(1.0, 1.0, -2.0, -2.0);
00040
00041 double minX, maxX, minY, maxY;
00042 minX = maxX = x(0);
00043 minY = maxY = y(0);
00044
00045 for ( size_t i = 1; i < sz; i++ )
00046 {
00047 const double xv = x(i);
00048 if ( xv < minX )
00049 minX = xv;
00050 if ( xv > maxX )
00051 maxX = xv;
00052
00053 const double yv = y(i);
00054 if ( yv < minY )
00055 minY = yv;
00056 if ( yv > maxY )
00057 maxY = yv;
00058 }
00059 return QwtDoubleRect(minX, minY, maxX - minX, maxY - minY);
00060 }
00061
00068 #if QT_VERSION >= 0x040000
00069 QwtPolygonFData::QwtPolygonFData(const QPolygonF &polygon):
00070 #else
00071 QwtPolygonFData::QwtPolygonFData(const QwtArray<QwtDoublePoint> &polygon):
00072 #endif
00073 d_data(polygon)
00074 {
00075 }
00076
00078 QwtPolygonFData& QwtPolygonFData::operator=(
00079 const QwtPolygonFData &data)
00080 {
00081 if (this != &data)
00082 {
00083 d_data = data.d_data;
00084 }
00085 return *this;
00086 }
00087
00089 size_t QwtPolygonFData::size() const
00090 {
00091 return d_data.size();
00092 }
00093
00100 double QwtPolygonFData::x(size_t i) const
00101 {
00102 return d_data[int(i)].x();
00103 }
00104
00111 double QwtPolygonFData::y(size_t i) const
00112 {
00113 return d_data[int(i)].y();
00114 }
00115
00116 #if QT_VERSION >= 0x040000
00117 const QPolygonF &QwtPolygonFData::data() const
00118 #else
00119 const QwtArray<QwtDoublePoint> &QwtPolygonFData::data() const
00120 #endif
00121 {
00122 return d_data;
00123 }
00124
00128 QwtData *QwtPolygonFData::copy() const
00129 {
00130 return new QwtPolygonFData(d_data);
00131 }
00132
00141 QwtArrayData::QwtArrayData(
00142 const QwtArray<double> &x, const QwtArray<double> &y):
00143 d_x(x),
00144 d_y(y)
00145 {
00146 }
00147
00156 QwtArrayData::QwtArrayData(const double *x, const double *y, size_t size)
00157 {
00158 #if QT_VERSION >= 0x040000
00159 d_x.resize(size);
00160 qMemCopy(d_x.data(), x, size * sizeof(double));
00161
00162 d_y.resize(size);
00163 qMemCopy(d_y.data(), y, size * sizeof(double));
00164 #else
00165 d_x.detach();
00166 d_x.duplicate(x, size);
00167
00168 d_y.detach();
00169 d_y.duplicate(y, size);
00170 #endif
00171 }
00172
00174 QwtArrayData& QwtArrayData::operator=(const QwtArrayData &data)
00175 {
00176 if (this != &data)
00177 {
00178 d_x = data.d_x;
00179 d_y = data.d_y;
00180 }
00181 return *this;
00182 }
00183
00185 size_t QwtArrayData::size() const
00186 {
00187 return qwtMin(d_x.size(), d_y.size());
00188 }
00189
00196 double QwtArrayData::x(size_t i) const
00197 {
00198 return d_x[int(i)];
00199 }
00200
00207 double QwtArrayData::y(size_t i) const
00208 {
00209 return d_y[int(i)];
00210 }
00211
00213 const QwtArray<double> &QwtArrayData::xData() const
00214 {
00215 return d_x;
00216 }
00217
00219 const QwtArray<double> &QwtArrayData::yData() const
00220 {
00221 return d_y;
00222 }
00223
00227 QwtData *QwtArrayData::copy() const
00228 {
00229 return new QwtArrayData(d_x, d_y);
00230 }
00231
00237 QwtDoubleRect QwtArrayData::boundingRect() const
00238 {
00239 const size_t sz = size();
00240
00241 if ( sz <= 0 )
00242 return QwtDoubleRect(1.0, 1.0, -2.0, -2.0);
00243
00244 double minX, maxX, minY, maxY;
00245 QwtArray<double>::ConstIterator xIt = d_x.begin();
00246 QwtArray<double>::ConstIterator yIt = d_y.begin();
00247 QwtArray<double>::ConstIterator end = d_x.begin() + sz;
00248 minX = maxX = *xIt++;
00249 minY = maxY = *yIt++;
00250
00251 while ( xIt < end )
00252 {
00253 const double xv = *xIt++;
00254 if ( xv < minX )
00255 minX = xv;
00256 if ( xv > maxX )
00257 maxX = xv;
00258
00259 const double yv = *yIt++;
00260 if ( yv < minY )
00261 minY = yv;
00262 if ( yv > maxY )
00263 maxY = yv;
00264 }
00265 return QwtDoubleRect(minX, minY, maxX - minX, maxY - minY);
00266 }
00267
00281 QwtCPointerData::QwtCPointerData(
00282 const double *x, const double *y, size_t size):
00283 d_x(x),
00284 d_y(y),
00285 d_size(size)
00286 {
00287 }
00288
00290 QwtCPointerData& QwtCPointerData::operator=(const QwtCPointerData &data)
00291 {
00292 if (this != &data)
00293 {
00294 d_x = data.d_x;
00295 d_y = data.d_y;
00296 d_size = data.d_size;
00297 }
00298 return *this;
00299 }
00300
00302 size_t QwtCPointerData::size() const
00303 {
00304 return d_size;
00305 }
00306
00313 double QwtCPointerData::x(size_t i) const
00314 {
00315 return d_x[int(i)];
00316 }
00317
00324 double QwtCPointerData::y(size_t i) const
00325 {
00326 return d_y[int(i)];
00327 }
00328
00330 const double *QwtCPointerData::xData() const
00331 {
00332 return d_x;
00333 }
00334
00336 const double *QwtCPointerData::yData() const
00337 {
00338 return d_y;
00339 }
00340
00344 QwtData *QwtCPointerData::copy() const
00345 {
00346 return new QwtCPointerData(d_x, d_y, d_size);
00347 }
00348
00354 QwtDoubleRect QwtCPointerData::boundingRect() const
00355 {
00356 const size_t sz = size();
00357
00358 if ( sz <= 0 )
00359 return QwtDoubleRect(1.0, 1.0, -2.0, -2.0);
00360
00361 double minX, maxX, minY, maxY;
00362 const double *xIt = d_x;
00363 const double *yIt = d_y;
00364 const double *end = d_x + sz;
00365 minX = maxX = *xIt++;
00366 minY = maxY = *yIt++;
00367
00368 while ( xIt < end )
00369 {
00370 const double xv = *xIt++;
00371 if ( xv < minX )
00372 minX = xv;
00373 if ( xv > maxX )
00374 maxX = xv;
00375
00376 const double yv = *yIt++;
00377 if ( yv < minY )
00378 minY = yv;
00379 if ( yv > maxY )
00380 maxY = yv;
00381 }
00382 return QwtDoubleRect(minX, minY, maxX - minX, maxY - minY);
00383 }