microui  14.2.0
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  * @file
17  * @brief Utility functions to handle rectangles
18  *
19  * @see ui_rect_t
20  *
21  * @author MicroEJ Developer Team
22  * @version 14.2.0
23  */
24 
25 // --------------------------------------------------------------------------------
26 // Includes
27 // --------------------------------------------------------------------------------
28 
29 #include <stddef.h>
30 
31 #include "ui_rect.h"
32 #include "ui_util.h"
33 
34 // --------------------------------------------------------------------------------
35 // Constants
36 // --------------------------------------------------------------------------------
37 
38 #define UI_RECT_EMPTY { 1u, 1u, 0u, 0u }
39 
40 // --------------------------------------------------------------------------------
41 // Functions
42 // --------------------------------------------------------------------------------
43 
44 /*
45  * @brief Computes the minimum bounding rectangle of an array of two rectangles
46  *
47  * The behavior is undefined if the array is empty.
48  *
49  * @param[in] first the first rectangle
50  * @param[in] second the second rectangle
51  * @return the minimum bounding rectangle
52  */
53 static inline ui_rect_t UI_RECT_get_minimum_bounding_rect_two_rects(const ui_rect_t *first, const ui_rect_t *second) {
54  return UI_RECT_new_xyxy(MIN(first->x1, second->x1), MIN(first->y1, second->y1), MAX(first->x2, second->x2),
55  MAX(first->y2, second->y2));
56 }
57 
58 /*
59  * @brief Computes the minimum bounding rectangle of an array of rectangles
60  *
61  * The behavior is undefined if the array is empty.
62  *
63  * @param[in] rects the array of rectangles
64  * @param[in] count the length of the array
65  * @return the minimum bounding rectangle
66  */
67 ui_rect_t UI_RECT_get_minimum_bounding_rect(const ui_rect_t rects[], const size_t count);
68 
69 /*
70  * @brief Computes the union of two rectangles
71  *
72  * @param[out] output rectangles defining the union of the parameters
73  * @param[in] first the first rectangle
74  * @param[in] second the second rectangle
75  *
76  * @return the number of resulting rectangles. Some of them may be empty.
77  */
78 uint32_t UI_RECT_union(ui_rect_t output[3], const ui_rect_t *first, const ui_rect_t *second);
79 
80 /*
81  * @brief Computes the difference between two rectangles
82  *
83  * @param[out] rectangles defining the difference between the parameters
84  * @param[in] first the original rectangle
85  * @param[in] second the rectangle that will be removed from the original one
86  *
87  * @return the number of resulting rectangles. Some of them may be empty.
88  */
89 uint32_t UI_RECT_subtract(ui_rect_t output[4], const ui_rect_t *first, const ui_rect_t *second);
90 
91 // --------------------------------------------------------------------------------
92 // EOF
93 // --------------------------------------------------------------------------------
94 
95 #ifdef __cplusplus
96 }
97 #endif
98 
99 #endif // UI_RECT_UTIL_H