ScummVM API documentation
rect_float.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 BLADERUNNER_RECT_FLOAT_H
23#define BLADERUNNER_RECT_FLOAT_H
24
25#include "common/debug.h"
26#include "common/types.h"
27#include "common/util.h"
28#include "math/utils.h"
29
30namespace BladeRunner {
31
32struct RectFloat {
33 float x0;
34 float y0;
35 float x1;
36 float y1;
37
38 RectFloat()
39 : x0(0.0f), y0(0.0f), x1(0.0f), y1(0.0f)
40 {}
41 RectFloat(float x0_, float y0_, float x1_, float y1_)
42 : x0(x0_), y0(y0_), x1(x1_), y1(y1_)
43 {}
44
45 void expand(float d) {
46 x0 -= d;
47 y0 -= d;
48 x1 += d;
49 y1 += d;
50 }
51
52 void trunc_2_decimals() {
53 x0 = Math::trunc(x0 * 100.0f) / 100.0f;
54 y0 = Math::trunc(y0 * 100.0f) / 100.0f;
55 x1 = Math::trunc(x1 * 100.0f) / 100.0f;
56 y1 = Math::trunc(y1 * 100.0f) / 100.0f;
57 }
58};
59
60inline bool overlaps(const RectFloat &a, const RectFloat &b) {
61 return !(a.y1 < b.y0 || a.y0 > b.y1 || a.x0 > b.x1 || a.x1 < b.x0);
62}
63
64inline RectFloat merge(const RectFloat &a, const RectFloat &b) {
65 RectFloat c;
66 c.x0 = MIN(a.x0, b.x0);
67 c.y0 = MIN(a.y0, b.y0);
68 c.x1 = MAX(a.x1, b.x1);
69 c.y1 = MAX(a.y1, b.y1);
70 return c;
71}
72
73} // End of namespace BladeRunner
74
75#endif
T MIN(T a, T b)
Definition: util.h:63
T MAX(T a, T b)
Definition: util.h:66
Definition: rect_float.h:32