microui  4.0.1
microui
ui_rect_util.h
1 /*
2  * C
3  *
4  * Copyright 2024 MicroEJ Corp. All rights reserved.
5  * Use of this source code is governed by a BSD-style license that can be found with this software.
6  */
7 
8 #ifndef UI_RECT_UTIL_H
9 #define UI_RECT_UTIL_H
10 
11 #ifdef __cplusplus
12 extern "C" {
13 #endif
14 
15 // --------------------------------------------------------------------------------
16 // Includes
17 // --------------------------------------------------------------------------------
18 
19 #include <stddef.h>
20 
21 #include "ui_rect.h"
22 #include "ui_util.h"
23 
24 // --------------------------------------------------------------------------------
25 // Constants
26 // --------------------------------------------------------------------------------
27 
28 #define UI_RECT_EMPTY { 1u, 1u, 0u, 0u }
29 
30 // --------------------------------------------------------------------------------
31 // Functions
32 // --------------------------------------------------------------------------------
33 
34 /*
35  * @brief Computes the minimum bounding rectangle of an array of two rectangles
36  *
37  * The behavior is undefined if the array is empty.
38  *
39  * @param[in] first the first rectangle
40  * @param[in] second the second rectangle
41  * @return the minimum bounding rectangle
42  */
43 static inline ui_rect_t UI_RECT_get_minimum_bounding_rect_two_rects(const ui_rect_t* first, const ui_rect_t* second) {
44  return UI_RECT_new_xyxy(MIN(first->x1, second->x1), MIN(first->y1, second->y1), MAX(first->x2, second->x2), MAX(first->y2, second->y2));
45 }
46 
47 /*
48  * @brief Computes the minimum bounding rectangle of an array of rectangles
49  *
50  * The behavior is undefined if the array is empty.
51  *
52  * @param[in] rects the array of rectangles
53  * @param[in] count the length of the array
54  * @return the minimum bounding rectangle
55  */
56 ui_rect_t UI_RECT_get_minimum_bounding_rect(const ui_rect_t rects[], const size_t count);
57 
58 /*
59  * @brief Computes the union of two rectangles
60  *
61  * @param[out] output rectangles defining the union of the parameters
62  * @param[in] first the first rectangle
63  * @param[in] second the second rectangle
64  *
65  * @return the number of resulting rectangles. Some of them may be empty.
66  */
67 uint32_t UI_RECT_union(ui_rect_t output[3], const ui_rect_t* first, const ui_rect_t* second);
68 
69 /*
70  * @brief Computes the difference between two rectangles
71  *
72  * @param[out] rectangles defining the difference between the parameters
73  * @param[in] first the original rectangle
74  * @param[in] second the rectangle that will be removed from the original one
75  *
76  * @return the number of resulting rectangles. Some of them may be empty.
77  */
78 uint32_t UI_RECT_subtract(ui_rect_t output[4], const ui_rect_t* first, const ui_rect_t* second);
79 
80 // --------------------------------------------------------------------------------
81 // EOF
82 // --------------------------------------------------------------------------------
83 
84 #ifdef __cplusplus
85 }
86 #endif
87 
88 #endif // UI_RECT_UTIL_H