~ubuntu-branches/ubuntu/oneiric/qwt/oneiric-proposed

« back to all changes in this revision

Viewing changes to qwt-5.1.0/src/qwt_interval_data.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Fathi Boudra
  • Date: 2008-05-26 10:26:31 UTC
  • mfrom: (1.1.3 upstream) (2.1.1 lenny)
  • Revision ID: james.westby@ubuntu.com-20080526102631-bp95mfccnrb957nx
Tags: 5.1.1-1
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
2
 
 * Qwt Widget Library
3
 
 * Copyright (C) 1997   Josef Wilgen
4
 
 * Copyright (C) 2002   Uwe Rathmann
5
 
 * 
6
 
 * This library is free software; you can redistribute it and/or
7
 
 * modify it under the terms of the Qwt License, Version 1.0
8
 
 *****************************************************************************/
9
 
 
10
 
#include "qwt_math.h"
11
 
#include "qwt_interval_data.h"
12
 
 
13
 
QwtIntervalData::QwtIntervalData()
14
 
{
15
 
}
16
 
 
17
 
QwtIntervalData::QwtIntervalData(
18
 
        const QwtArray<QwtDoubleInterval> &intervals, 
19
 
        const QwtArray<double> &values):
20
 
    d_intervals(intervals),
21
 
    d_values(values)
22
 
{
23
 
}
24
 
    
25
 
void QwtIntervalData::setData(
26
 
    const QwtArray<QwtDoubleInterval> &intervals,
27
 
    const QwtArray<double> &values)
28
 
{
29
 
    d_intervals = intervals;
30
 
    d_values = values;
31
 
}
32
 
 
33
 
QwtDoubleRect QwtIntervalData::boundingRect() const
34
 
{
35
 
    double minX, maxX, minY, maxY;
36
 
    minX = maxX = minY = maxY = 0.0;
37
 
 
38
 
    bool isValid = false;
39
 
 
40
 
    const size_t sz = size();
41
 
    for ( size_t i = 0; i < sz; i++ )
42
 
    {
43
 
        const QwtDoubleInterval intv = interval(i);
44
 
        if ( !intv.isValid() )
45
 
            continue;
46
 
 
47
 
        const double v = value(i);
48
 
 
49
 
        if ( !isValid )
50
 
        {
51
 
            minX = intv.minValue();
52
 
            maxX = intv.maxValue();
53
 
            minY = maxY = v;
54
 
 
55
 
            isValid = true;
56
 
        }
57
 
        else
58
 
        {
59
 
            if ( intv.minValue() < minX )
60
 
                minX = intv.minValue();
61
 
            if ( intv.maxValue() > maxX )
62
 
                maxX = intv.maxValue();
63
 
 
64
 
            if ( v < minY )
65
 
                minY = v;
66
 
            if ( v > maxY )
67
 
                maxY = v;
68
 
        }
69
 
    }
70
 
    if ( !isValid )
71
 
        return QwtDoubleRect(1.0, 1.0, -2.0, -2.0); // invalid
72
 
 
73
 
    return QwtDoubleRect(minX, minY, maxX - minX, maxY - minY);
74
 
}