34 ui_rect_t result = rects[0];
35 for (
size_t i = 1; i < count; i++) {
36 result = UI_RECT_get_minimum_bounding_rect_two_rects(&result, &rects[i]);
42 uint32_t
UI_RECT_union(ui_rect_t output[3],
const ui_rect_t *first,
const ui_rect_t *second) {
44 if (UI_RECT_contains_rect(first, second)) {
46 UI_RECT_mark_empty(&output[1]);
47 UI_RECT_mark_empty(&output[2]);
49 }
else if (UI_RECT_contains_rect(second, first)) {
51 UI_RECT_mark_empty(&output[1]);
52 UI_RECT_mark_empty(&output[2]);
54 }
else if (!UI_RECT_intersects_rect(first, second)) {
57 UI_RECT_mark_empty(&output[2]);
60 const ui_rect_t *top_above = (first->y1 < second->y1) ? first : second;
61 const ui_rect_t *top_below = (first->y1 < second->y1) ? second : first;
62 const ui_rect_t *bottom_below = (first->y2 > second->y2) ? first : second;
63 const ui_rect_t *bottom_above = (first->y2 > second->y2) ? second : first;
67 output[count] = UI_RECT_new_xyxy(top_above->x1, top_above->y1, top_above->x2, top_below->y1 - 1);
68 if (!UI_RECT_is_empty(output)) {
72 output[count] = UI_RECT_new_xyxy(
MIN(first->x1, second->x1), top_below->y1,
MAX(first->x2, second->x2),
74 if (!UI_RECT_is_empty(output)) {
78 output[count] = UI_RECT_new_xyxy(bottom_below->x1, bottom_above->y2 + 1, bottom_below->x2, bottom_below->y2);
79 if (!UI_RECT_is_empty(output)) {
89 uint32_t
UI_RECT_subtract(ui_rect_t output[4],
const ui_rect_t *first,
const ui_rect_t *second) {
91 if (UI_RECT_contains_rect(first, second)) {
92 output[0] = UI_RECT_new_xyxy(first->x1, first->y1, first->x2, second->y1 - 1);
93 output[1] = UI_RECT_new_xyxy(first->x1, second->y1, second->x1 - 1, second->y2);
94 output[2] = UI_RECT_new_xyxy(second->x2 + 1, second->y1, first->x2, second->y2);
95 output[3] = UI_RECT_new_xyxy(first->x1, second->y2 + 1, first->x2, first->y2);
97 }
else if (UI_RECT_contains_rect(second, first)) {
98 UI_RECT_mark_empty(&output[0]);
99 UI_RECT_mark_empty(&output[1]);
100 UI_RECT_mark_empty(&output[2]);
101 UI_RECT_mark_empty(&output[3]);
103 }
else if (!UI_RECT_intersects_rect(first, second)) {
105 UI_RECT_mark_empty(&output[1]);
106 UI_RECT_mark_empty(&output[2]);
107 UI_RECT_mark_empty(&output[3]);
110 output[0] = UI_RECT_new_xyxy(first->x1, first->y1, first->x2, second->y1 - 1);
111 output[1] = UI_RECT_new_xyxy(first->x1,
MAX(first->y1, second->y1), second->x1 - 1,
MIN(first->y2, second->y2));
112 output[2] = UI_RECT_new_xyxy(second->x2 + 1,
MAX(first->y1, second->y1), first->x2,
MIN(first->y2, second->y2));
113 output[3] = UI_RECT_new_xyxy(first->x1, second->y2 + 1, first->x2, first->y2);
Utility functions to handle rectangles.
ui_rect_t UI_RECT_get_minimum_bounding_rect(const ui_rect_t rects[], const size_t count)
Computes the minimum bounding rectangle of an array of rectangles.
uint32_t UI_RECT_subtract(ui_rect_t output[4], const ui_rect_t *first, const ui_rect_t *second)
Computes the difference between two rectangles.
uint32_t UI_RECT_union(ui_rect_t output[3], const ui_rect_t *first, const ui_rect_t *second)
Computes the union of two rectangles.
#define MIN(a, b)
Gets the lowest value.
#define MAX(a, b)
Gets the highest value.