Merge tag 'pull-sp-20240412' of https://gitlab.com/rth7680/qemu into staging
[qemu/armbru.git] / include / ui / rect.h
blob7ebf47ebcdc2af5db072ec20717bcba950bbd7eb
1 /*
2 * SPDX-License-Identifier: GPL-2.0-or-later
3 */
4 #ifndef QEMU_RECT_H
5 #define QEMU_RECT_H
8 typedef struct QemuRect {
9 int16_t x;
10 int16_t y;
11 uint16_t width;
12 uint16_t height;
13 } QemuRect;
15 static inline void qemu_rect_init(QemuRect *rect,
16 int16_t x, int16_t y,
17 uint16_t width, uint16_t height)
19 rect->x = x;
20 rect->y = y;
21 rect->width = width;
22 rect->height = height;
25 static inline void qemu_rect_translate(QemuRect *rect,
26 int16_t dx, int16_t dy)
28 rect->x += dx;
29 rect->y += dy;
32 static inline bool qemu_rect_intersect(const QemuRect *a, const QemuRect *b,
33 QemuRect *res)
35 int16_t x1, x2, y1, y2;
37 x1 = MAX(a->x, b->x);
38 y1 = MAX(a->y, b->y);
39 x2 = MIN(a->x + a->width, b->x + b->width);
40 y2 = MIN(a->y + a->height, b->y + b->height);
42 if (x1 >= x2 || y1 >= y2) {
43 if (res) {
44 qemu_rect_init(res, 0, 0, 0, 0);
47 return false;
50 if (res) {
51 qemu_rect_init(res, x1, y1, x2 - x1, y2 - y1);
54 return true;
57 #endif