qwt_interval_data.cpp 1.76 KB
Newer Older
pixhawk's avatar
pixhawk committed
1 2 3 4
/* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
 * Qwt Widget Library
 * Copyright (C) 1997   Josef Wilgen
 * Copyright (C) 2002   Uwe Rathmann
5
 *
pixhawk's avatar
pixhawk committed
6 7 8 9 10 11 12 13 14 15 16 17
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the Qwt License, Version 1.0
 *****************************************************************************/

#include "qwt_math.h"
#include "qwt_interval_data.h"

QwtIntervalData::QwtIntervalData()
{
}

QwtIntervalData::QwtIntervalData(
18 19
    const QwtArray<QwtDoubleInterval> &intervals,
    const QwtArray<double> &values):
pixhawk's avatar
pixhawk committed
20 21 22 23
    d_intervals(intervals),
    d_values(values)
{
}
24

pixhawk's avatar
pixhawk committed
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
void QwtIntervalData::setData(
    const QwtArray<QwtDoubleInterval> &intervals,
    const QwtArray<double> &values)
{
    d_intervals = intervals;
    d_values = values;
}

QwtDoubleRect QwtIntervalData::boundingRect() const
{
    double minX, maxX, minY, maxY;
    minX = maxX = minY = maxY = 0.0;

    bool isValid = false;

    const size_t sz = size();
41
    for ( size_t i = 0; i < sz; i++ ) {
pixhawk's avatar
pixhawk committed
42 43 44 45 46 47
        const QwtDoubleInterval intv = interval(i);
        if ( !intv.isValid() )
            continue;

        const double v = value(i);

48
        if ( !isValid ) {
pixhawk's avatar
pixhawk committed
49 50 51 52 53
            minX = intv.minValue();
            maxX = intv.maxValue();
            minY = maxY = v;

            isValid = true;
54
        } else {
pixhawk's avatar
pixhawk committed
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
            if ( intv.minValue() < minX )
                minX = intv.minValue();
            if ( intv.maxValue() > maxX )
                maxX = intv.maxValue();

            if ( v < minY )
                minY = v;
            if ( v > maxY )
                maxY = v;
        }
    }
    if ( !isValid )
        return QwtDoubleRect(1.0, 1.0, -2.0, -2.0); // invalid

    return QwtDoubleRect(minX, minY, maxX - minX, maxY - minY);
}