GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: gx_utility_rectangle_overlap_detect.c Lines: 20 20 100.0 %
Date: 2024-12-05 08:52:37 Branches: 14 14 100.0 %

Line Branch Exec Source
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
/**************************************************************************/
74
26411815
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
26411815
GX_BOOL      overlap = GX_FALSE;
80
81
26411815
    if (second_rectangle -> gx_rectangle_left < first_rectangle -> gx_rectangle_left)
82
    {
83
12162149
        test.gx_rectangle_left = first_rectangle -> gx_rectangle_left;
84
    }
85
    else
86
    {
87
14249666
        test.gx_rectangle_left = second_rectangle -> gx_rectangle_left;
88
    }
89
90
26411815
    if (second_rectangle -> gx_rectangle_top < first_rectangle -> gx_rectangle_top)
91
    {
92
11865021
        test.gx_rectangle_top = first_rectangle -> gx_rectangle_top;
93
    }
94
    else
95
    {
96
14546794
        test.gx_rectangle_top = second_rectangle -> gx_rectangle_top;
97
    }
98
99
26411815
    if (second_rectangle -> gx_rectangle_right > first_rectangle -> gx_rectangle_right)
100
    {
101
12136455
        test.gx_rectangle_right = first_rectangle -> gx_rectangle_right;
102
    }
103
    else
104
    {
105
14275360
        test.gx_rectangle_right = second_rectangle -> gx_rectangle_right;
106
    }
107
26411815
    if (second_rectangle -> gx_rectangle_bottom > first_rectangle -> gx_rectangle_bottom)
108
    {
109
11321976
        test.gx_rectangle_bottom = first_rectangle -> gx_rectangle_bottom;
110
    }
111
    else
112
    {
113
15089839
        test.gx_rectangle_bottom = second_rectangle -> gx_rectangle_bottom;
114
    }
115
26411815
    if (test.gx_rectangle_left <= test.gx_rectangle_right &&
116
24966152
        test.gx_rectangle_top <= test.gx_rectangle_bottom)
117
    {
118
23827098
        overlap = GX_TRUE;
119
    }
120
26411815
    if (return_overlap_area)
121
    {
122
25609966
        *return_overlap_area = test;
123
    }
124
26411815
    return(overlap);
125
}
126