1 /***************************************************************************
2  * Copyright (c) 2024 Microsoft Corporation
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the MIT License which is available at
6  * https://opensource.org/licenses/MIT.
7  *
8  * SPDX-License-Identifier: MIT
9  **************************************************************************/
10 
11 
12 /**************************************************************************/
13 /**************************************************************************/
14 /**                                                                       */
15 /** GUIX Component                                                        */
16 /**                                                                       */
17 /**   Utility (Utility)                                                   */
18 /**                                                                       */
19 /**************************************************************************/
20 
21 #define GX_SOURCE_CODE
22 
23 
24 /* Include necessary system files.  */
25 
26 #include "gx_api.h"
27 #include "gx_utility.h"
28 
29 
30 /**************************************************************************/
31 /*                                                                        */
32 /*  FUNCTION                                               RELEASE        */
33 /*                                                                        */
34 /*    _gx_utility_rectangle_overlap_detect                PORTABLE C      */
35 /*                                                           6.1          */
36 /*  AUTHOR                                                                */
37 /*                                                                        */
38 /*    Kenneth Maxwell, Microsoft Corporation                              */
39 /*                                                                        */
40 /*  DESCRIPTION                                                           */
41 /*                                                                        */
42 /*    This service detects any overlap of the supplied rectangles.        */
43 /*    If overlap is found, the service returns GX_TRUE and the            */
44 /*    overlapping rectangle.                                              */
45 /*                                                                        */
46 /*  INPUT                                                                 */
47 /*                                                                        */
48 /*    first_rectangle                       First rectangle               */
49 /*    second_rectangle                      Second rectangle              */
50 /*    return_overlap_area                   Overlapping rectangle area    */
51 /*                                                                        */
52 /*  OUTPUT                                                                */
53 /*                                                                        */
54 /*    [GX_TRUE | GX_FALSE]                                                */
55 /*                                                                        */
56 /*  CALLS                                                                 */
57 /*                                                                        */
58 /*    None                                                                */
59 /*                                                                        */
60 /*  CALLED BY                                                             */
61 /*                                                                        */
62 /*    Application Code                                                    */
63 /*    GUIX Internal Code                                                  */
64 /*                                                                        */
65 /*  RELEASE HISTORY                                                       */
66 /*                                                                        */
67 /*    DATE              NAME                      DESCRIPTION             */
68 /*                                                                        */
69 /*  05-19-2020     Kenneth Maxwell          Initial Version 6.0           */
70 /*  09-30-2020     Kenneth Maxwell          Modified comment(s),          */
71 /*                                            resulting in version 6.1    */
72 /*                                                                        */
73 /**************************************************************************/
_gx_utility_rectangle_overlap_detect(GX_RECTANGLE * first_rectangle,GX_RECTANGLE * second_rectangle,GX_RECTANGLE * return_overlap_area)74 GX_BOOL  _gx_utility_rectangle_overlap_detect(GX_RECTANGLE *first_rectangle, GX_RECTANGLE *second_rectangle,
75                                               GX_RECTANGLE *return_overlap_area)
76 {
77 
78 GX_RECTANGLE test;
79 GX_BOOL      overlap = GX_FALSE;
80 
81     if (second_rectangle -> gx_rectangle_left < first_rectangle -> gx_rectangle_left)
82     {
83         test.gx_rectangle_left = first_rectangle -> gx_rectangle_left;
84     }
85     else
86     {
87         test.gx_rectangle_left = second_rectangle -> gx_rectangle_left;
88     }
89 
90     if (second_rectangle -> gx_rectangle_top < first_rectangle -> gx_rectangle_top)
91     {
92         test.gx_rectangle_top = first_rectangle -> gx_rectangle_top;
93     }
94     else
95     {
96         test.gx_rectangle_top = second_rectangle -> gx_rectangle_top;
97     }
98 
99     if (second_rectangle -> gx_rectangle_right > first_rectangle -> gx_rectangle_right)
100     {
101         test.gx_rectangle_right = first_rectangle -> gx_rectangle_right;
102     }
103     else
104     {
105         test.gx_rectangle_right = second_rectangle -> gx_rectangle_right;
106     }
107     if (second_rectangle -> gx_rectangle_bottom > first_rectangle -> gx_rectangle_bottom)
108     {
109         test.gx_rectangle_bottom = first_rectangle -> gx_rectangle_bottom;
110     }
111     else
112     {
113         test.gx_rectangle_bottom = second_rectangle -> gx_rectangle_bottom;
114     }
115     if (test.gx_rectangle_left <= test.gx_rectangle_right &&
116         test.gx_rectangle_top <= test.gx_rectangle_bottom)
117     {
118         overlap = GX_TRUE;
119     }
120     if (return_overlap_area)
121     {
122         *return_overlap_area = test;
123     }
124     return(overlap);
125 }
126 
127