ScummVM API documentation
Range.h
1/* ScummVM - Graphic Adventure Engine
2 *
3 * ScummVM is the legal property of its developers, whose names
4 * are too numerous to list here. Please refer to the COPYRIGHT
5 * file distributed with this source distribution.
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 *
20 */
21
22#ifndef QDENGINE_MINIGAMES_ADV_RANGE_H
23#define QDENGINE_MINIGAMES_ADV_RANGE_H
24
25namespace QDEngine {
26
27class Rangef {
28public:
29 Rangef(float min = 0.f, float max = 0.f)
30 : _min(min)
31 , _max(max)
32 {}
33
34 float minimum() const {
35 return _min;
36 }
37 void setMinimum(float min) {
38 _min = min;
39 }
40
41 float maximum() const {
42 return _max;
43 }
44 void setMaximum(float max) {
45 _max = max;
46 }
47
48 void set(float min, float max);
49
50 float length() const {
51 return _max - _min;
52 }
53 float center() const {
54 return (_max + _min) / 2.f;
55 }
56
58 bool is_valid() const {
59 return _min <= _max;
60 }
61
63 bool include(float value) const {
64 return (_min <= value) && (_max >= value);
65 }
67 bool include(const Rangef& range) const {
68 return _min <= range._min && _max >= range._max;
69 }
70
72 Rangef intersection(const Rangef& range);
73
75 float clip(float &value) const;
76
77private:
78 float _min;
79 float _max;
80};
81
82// --------------------- Rangei
83
84class Rangei {
85public:
86 Rangei(int min = 0.f, int max = 0.f)
87 : _min(min)
88 , _max(max)
89 {}
90
91 int minimum() const {
92 return _min;
93 }
94 void setMinimum(int min) {
95 _min = min;
96 }
97
98 int maximum() const {
99 return _max;
100 }
101 void setMaximum(int max) {
102 _max = max;
103 }
104
105 void set(int min, int max);
106
107 int length() const {
108 return _max - _min;
109 }
110 int center() const {
111 return (_max + _min) / 2;
112 }
113
115 bool is_valid() const {
116 return _min <= _max;
117 }
118
120 bool include(int value) const {
121 return (_min <= value) && (_max >= value);
122 }
124 bool include(const Rangei& range) const {
125 return _min <= range._min && _max >= range._max;
126 }
127
130
132 int clip(int &value);
133
134private:
135 int _min;
136 int _max;
137};
138
139} // namespace QDEngine
140
141#endif // QDENGINE_MINIGAMES_ADV_RANGE_H
Definition: Range.h:27
bool is_valid() const
Корректен ли интервал (нет - в случае когда minimum > maximum);.
Definition: Range.h:58
float clip(float &value) const
Возвращает _value в пределах интервала [minimum, maximum].
Rangef intersection(const Rangef &range)
Возвращает пересечение интервала *this и _range.
bool include(float value) const
Включает ли отрезок (закрытый интервал) точку _value.
Definition: Range.h:63
bool include(const Rangef &range) const
Включает ли интервал в себя _range.
Definition: Range.h:67
Definition: Range.h:84
bool include(int value) const
Включает ли отрезок (закрытый интервал) точку _value.
Definition: Range.h:120
bool include(const Rangei &range) const
Включает ли интервал в себя _range.
Definition: Range.h:124
int clip(int &value)
Возвращает _value в пределах интервала [minimum, maximum].
Rangei intersection(const Rangei &range)
Возвращает пересечение интервала *this и _range.
bool is_valid() const
Корректен ли интервал (нет - в случае когда minimum > maximum);.
Definition: Range.h:115
Базовый класс для игровых ресурсов.
Definition: console.h:28