1/*
2 * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
3 * Distributed under the terms of the MIT License.
4 */
5#ifndef CHART_DATA_RANGE_H
6#define CHART_DATA_RANGE_H
7
8#include <algorithm>
9
10
11class ChartDataRange {
12public:
13	double	min;
14	double	max;
15
16	ChartDataRange()
17		:
18		min(0),
19		max(0)
20	{
21	}
22
23	ChartDataRange(double min, double max)
24		:
25		min(min),
26		max(max)
27	{
28	}
29
30	ChartDataRange(const ChartDataRange& other)
31		:
32		min(other.min),
33		max(other.max)
34	{
35	}
36
37	bool IsValid() const
38	{
39
40		return min < max;
41	}
42
43	double Size() const
44	{
45		return max - min;
46	}
47
48	ChartDataRange& Extend(const ChartDataRange& other)
49	{
50		min = std::min(min, other.min);
51		max = std::max(max, other.max);
52		return *this;
53	}
54
55	ChartDataRange& OffsetBy(double offset)
56	{
57		min += offset;
58		max += offset;
59		return *this;
60	}
61
62	ChartDataRange& OffsetTo(double newMin)
63	{
64		max += newMin - min;
65		min = newMin;
66		return *this;
67	}
68
69	ChartDataRange& operator=(const ChartDataRange& other)
70	{
71		min = other.min;
72		max = other.max;
73		return *this;
74	}
75
76	bool operator==(const ChartDataRange& other) const
77	{
78		return min == other.min && max == other.max;
79	}
80
81	bool operator!=(const ChartDataRange& other) const
82	{
83		return !(*this == other);
84	}
85};
86
87
88#endif	// CHART_DATA_RANGE_H
89