GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: gx_display_driver_arc_clipping_get.c Lines: 177 177 100.0 %
Date: 2026-03-06 19:21:09 Branches: 38 38 100.0 %

Line Branch Exec Source
1
/***************************************************************************
2
 * Copyright (c) 2024 Microsoft Corporation
3
 * Copyright (c) 2026-present Eclipse ThreadX contributors
4
 *
5
 * This program and the accompanying materials are made available under the
6
 * terms of the MIT License which is available at
7
 * https://opensource.org/licenses/MIT.
8
 *
9
 * SPDX-License-Identifier: MIT
10
 **************************************************************************/
11
12
13
/**************************************************************************/
14
/**************************************************************************/
15
/**                                                                       */
16
/** GUIX Component                                                        */
17
/**                                                                       */
18
/**   Display Management (Display)                                        */
19
/**                                                                       */
20
/**************************************************************************/
21
22
#define GX_SOURCE_CODE
23
24
25
/* Include necessary system files.  */
26
27
#include "gx_api.h"
28
#include "gx_system.h"
29
#include "gx_utility.h"
30
#include "gx_display.h"
31
32
/**************************************************************************/
33
/*                                                                        */
34
/*  FUNCTION                                               RELEASE        */
35
/*                                                                        */
36
/*    _gx_display_driver_arc_clipping_get                 PORTABLE C      */
37
/*                                                           6.1          */
38
/*  AUTHOR                                                                */
39
/*                                                                        */
40
/*    Kenneth Maxwell, Microsoft Corporation                              */
41
/*                                                                        */
42
/*  DESCRIPTION                                                           */
43
/*                                                                        */
44
/*    This function returns the clipping area of a circle arc.            */
45
/*                                                                        */
46
/*  INPUT                                                                 */
47
/*                                                                        */
48
/*    xcenter                               x-coord of center of circle   */
49
/*    ycenter                               y-coord of center of circle   */
50
/*    r                                     Radius of circle              */
51
/*    start_angle                           Start angle for clipping      */
52
/*    end_argle                             End angle for clipping        */
53
/*    clip_1                                Clip result                   */
54
/*    cllp_2                                Clip result                   */
55
/*    clip_3                                Clip result                   */
56
/*    clip_4                                Clip result                   */
57
/*                                                                        */
58
/*  OUTPUT                                                                */
59
/*                                                                        */
60
/*    None                                                                */
61
/*                                                                        */
62
/*  CALLS                                                                 */
63
/*                                                                        */
64
/*    _gx_utility_circle_point_get          Get point coord on a circle   */
65
/*                                                                        */
66
/*  CALLED BY                                                             */
67
/*                                                                        */
68
/*    GUIX Internal Code                                                  */
69
/*                                                                        */
70
/**************************************************************************/
71
#if defined(GX_ARC_DRAWING_SUPPORT)
72
29395
VOID _gx_display_driver_arc_clipping_get(INT xcenter, INT ycenter, UINT r, INT start_angle, INT end_angle,
73
                                         GX_RECTANGLE *clip_1, GX_RECTANGLE *clip_2, GX_RECTANGLE *clip_3, GX_RECTANGLE *clip_4)
74
{
75
76
GX_POINT start_point;
77
GX_POINT end_point;
78
29395
GX_VALUE ori_r = (GX_VALUE)r;
79
29395
GX_VALUE neg_r = (GX_VALUE)(-ori_r);
80
81
29395
    memset(clip_1, 0, sizeof(GX_RECTANGLE));
82
29395
    memset(clip_2, 0, sizeof(GX_RECTANGLE));
83
29395
    memset(clip_3, 0, sizeof(GX_RECTANGLE));
84
29395
    memset(clip_4, 0, sizeof(GX_RECTANGLE));
85
86
    /* Get two endpoint of the arc. */
87
29395
    _gx_utility_circle_point_get(0, 0, r, start_angle, &start_point);
88
29395
    _gx_utility_circle_point_get(0, 0, r, end_angle, &end_point);
89
90
    /* Calculate clipping. */
91
29395
    if (start_angle < 90)
92
    {
93
8789
        if (end_angle <= 90)
94
        {
95
7857
            clip_1 -> gx_rectangle_left = end_point.gx_point_x;
96
7857
            clip_1 -> gx_rectangle_top = end_point.gx_point_y;
97
7857
            clip_1 -> gx_rectangle_right = start_point.gx_point_x;
98
7857
            clip_1 -> gx_rectangle_bottom = start_point.gx_point_y;
99
        }
100
        else
101
        {
102
932
            clip_1 -> gx_rectangle_left = 0;
103
932
            clip_1 -> gx_rectangle_top = neg_r;
104
932
            clip_1 -> gx_rectangle_right = start_point.gx_point_x;
105
932
            clip_1 -> gx_rectangle_bottom = start_point.gx_point_y;
106
107
932
            if (end_angle <= 180)
108
            {
109
653
                clip_2 -> gx_rectangle_left = end_point.gx_point_x;
110
653
                clip_2 -> gx_rectangle_top = neg_r;
111
653
                clip_2 -> gx_rectangle_right = 0;
112
653
                clip_2 -> gx_rectangle_bottom = end_point.gx_point_y;
113
            }
114
            else
115
            {
116
279
                clip_2 -> gx_rectangle_left = neg_r;
117
279
                clip_2 -> gx_rectangle_top = neg_r;
118
279
                clip_2 -> gx_rectangle_right = 0;
119
279
                clip_2 -> gx_rectangle_bottom = 0;
120
121
279
                if (end_angle <= 270)
122
                {
123
91
                    clip_3 -> gx_rectangle_left = neg_r;
124
91
                    clip_3 -> gx_rectangle_top = 0;
125
91
                    clip_3 -> gx_rectangle_right = end_point.gx_point_x;
126
91
                    clip_3 -> gx_rectangle_bottom = end_point.gx_point_y;
127
                }
128
                else
129
                {
130
188
                    clip_2 -> gx_rectangle_bottom = ori_r;
131
132
188
                    if (end_angle <= 360)
133
                    {
134
176
                        clip_3 -> gx_rectangle_left = 0;
135
176
                        clip_3 -> gx_rectangle_top = end_point.gx_point_y;
136
176
                        clip_3 -> gx_rectangle_right = end_point.gx_point_x;
137
176
                        clip_3 -> gx_rectangle_bottom = ori_r;
138
                    }
139
                    else
140
                    {
141
12
                        clip_3 -> gx_rectangle_left = 0;
142
12
                        clip_3 -> gx_rectangle_top = 0;
143
12
                        clip_3 -> gx_rectangle_right = ori_r;
144
12
                        clip_3 -> gx_rectangle_bottom = ori_r;
145
146
12
                        clip_4 -> gx_rectangle_left = end_point.gx_point_x;
147
12
                        clip_4 -> gx_rectangle_top = end_point.gx_point_y;
148
12
                        clip_4 -> gx_rectangle_right = ori_r;
149
12
                        clip_4 -> gx_rectangle_bottom = 0;
150
                    }
151
                }
152
            }
153
        }
154
    }
155
20606
    else if (start_angle < 180)
156
    {
157
4181
        if (end_angle <= 180)
158
        {
159
1777
            clip_1 -> gx_rectangle_left = end_point.gx_point_x;
160
1777
            clip_1 -> gx_rectangle_top = start_point.gx_point_y;
161
1777
            clip_1 -> gx_rectangle_right = start_point.gx_point_x;
162
1777
            clip_1 -> gx_rectangle_bottom = end_point.gx_point_y;
163
        }
164
        else
165
        {
166
2404
            clip_1 -> gx_rectangle_left = neg_r;
167
2404
            clip_1 -> gx_rectangle_top = start_point.gx_point_y;
168
2404
            clip_1 -> gx_rectangle_right = start_point.gx_point_x;
169
2404
            clip_1 -> gx_rectangle_bottom = 0;
170
171
2404
            if (end_angle <= 270)
172
            {
173
2361
                clip_2 -> gx_rectangle_left = neg_r;
174
2361
                clip_2 -> gx_rectangle_top = 0;
175
2361
                clip_2 -> gx_rectangle_right = end_point.gx_point_x;
176
2361
                clip_2 -> gx_rectangle_bottom = end_point.gx_point_y;
177
            }
178
            else
179
            {
180
43
                clip_2 -> gx_rectangle_left = neg_r;
181
43
                clip_2 -> gx_rectangle_top = 0;
182
43
                clip_2 -> gx_rectangle_right = 0;
183
43
                clip_2 -> gx_rectangle_bottom = ori_r;
184
185
43
                if (end_angle <= 360)
186
                {
187
37
                    clip_3 -> gx_rectangle_left = 0;
188
37
                    clip_3 -> gx_rectangle_top = end_point.gx_point_y;
189
37
                    clip_3 -> gx_rectangle_right = end_point.gx_point_x;
190
37
                    clip_3 -> gx_rectangle_bottom = ori_r;
191
                }
192
                else
193
                {
194
6
                    clip_2 -> gx_rectangle_right = ori_r;
195
196
6
                    if (end_angle <= 450)
197
                    {
198
1
                        clip_3 -> gx_rectangle_left = end_point.gx_point_x;
199
1
                        clip_3 -> gx_rectangle_top = end_point.gx_point_y;
200
1
                        clip_3 -> gx_rectangle_right = ori_r;
201
1
                        clip_3 -> gx_rectangle_bottom = 0;
202
                    }
203
                    else
204
                    {
205
5
                        clip_3 -> gx_rectangle_left = 0;
206
5
                        clip_3 -> gx_rectangle_top = neg_r;
207
5
                        clip_3 -> gx_rectangle_right = ori_r;
208
5
                        clip_3 -> gx_rectangle_bottom = 0;
209
210
5
                        clip_4 -> gx_rectangle_left = end_point.gx_point_x;
211
5
                        clip_4 -> gx_rectangle_top = neg_r;
212
5
                        clip_4 -> gx_rectangle_right = 0;
213
5
                        clip_4 -> gx_rectangle_bottom = end_point.gx_point_y;
214
                    }
215
                }
216
            }
217
        }
218
    }
219
16425
    else if (start_angle < 270)
220
    {
221
6591
        if (end_angle <= 270)
222
        {
223
6030
            clip_1 -> gx_rectangle_left = start_point.gx_point_x;
224
6030
            clip_1 -> gx_rectangle_top = start_point.gx_point_y;
225
6030
            clip_1 -> gx_rectangle_right = end_point.gx_point_x;
226
6030
            clip_1 -> gx_rectangle_bottom = end_point.gx_point_y;
227
        }
228
        else
229
        {
230
561
            clip_1 -> gx_rectangle_left = start_point.gx_point_x;
231
561
            clip_1 -> gx_rectangle_top = start_point.gx_point_y;
232
561
            clip_1 -> gx_rectangle_right = 0;
233
561
            clip_1 -> gx_rectangle_bottom = ori_r;
234
235
561
            if (end_angle <= 360)
236
            {
237
549
                clip_2 -> gx_rectangle_left = 0;
238
549
                clip_2 -> gx_rectangle_top = end_point.gx_point_y;
239
549
                clip_2 -> gx_rectangle_right = end_point.gx_point_x;
240
549
                clip_2 -> gx_rectangle_bottom = ori_r;
241
            }
242
            else
243
            {
244
12
                clip_2 -> gx_rectangle_left = 0;
245
12
                clip_2 -> gx_rectangle_top = 0;
246
12
                clip_2 -> gx_rectangle_right = ori_r;
247
12
                clip_2 -> gx_rectangle_bottom = ori_r;
248
249
12
                if (end_angle <= 450)
250
                {
251
5
                    clip_3 -> gx_rectangle_left = end_point.gx_point_x;
252
5
                    clip_3 -> gx_rectangle_top = end_point.gx_point_y;
253
5
                    clip_3 -> gx_rectangle_right = ori_r;
254
5
                    clip_3 -> gx_rectangle_bottom = ori_r;
255
                }
256
                else
257
                {
258
7
                    clip_2 -> gx_rectangle_top = neg_r;
259
260
7
                    if (end_angle <= 540)
261
                    {
262
4
                        clip_3 -> gx_rectangle_left = end_point.gx_point_x;
263
4
                        clip_3 -> gx_rectangle_top = neg_r;
264
4
                        clip_3 -> gx_rectangle_right = 0;
265
4
                        clip_3 -> gx_rectangle_bottom = end_point.gx_point_y;
266
                    }
267
                    else
268
                    {
269
3
                        clip_3 -> gx_rectangle_left = neg_r;
270
3
                        clip_3 -> gx_rectangle_top = neg_r;
271
3
                        clip_3 -> gx_rectangle_right = 0;
272
3
                        clip_3 -> gx_rectangle_bottom = 0;
273
274
3
                        clip_4 -> gx_rectangle_left = neg_r;
275
3
                        clip_4 -> gx_rectangle_top = 0;
276
3
                        clip_4 -> gx_rectangle_right = end_point.gx_point_x;
277
3
                        clip_4 -> gx_rectangle_bottom = end_point.gx_point_y;
278
                    }
279
                }
280
            }
281
        }
282
    }
283
    else
284
    {
285
9834
        if (end_angle <= 360)
286
        {
287
2150
            clip_1 -> gx_rectangle_left = start_point.gx_point_x;
288
2150
            clip_1 -> gx_rectangle_top = end_point.gx_point_y;
289
2150
            clip_1 -> gx_rectangle_right = end_point.gx_point_x;
290
2150
            clip_1 -> gx_rectangle_bottom = start_point.gx_point_y;
291
        }
292
        else
293
        {
294
7684
            clip_1 -> gx_rectangle_left = start_point.gx_point_x;
295
7684
            clip_1 -> gx_rectangle_top = 0;
296
7684
            clip_1 -> gx_rectangle_right = ori_r;
297
7684
            clip_1 -> gx_rectangle_bottom = start_point.gx_point_y;
298
299
7684
            if (end_angle <= 450)
300
            {
301
7615
                clip_2 -> gx_rectangle_left = end_point.gx_point_x;
302
7615
                clip_2 -> gx_rectangle_top = end_point.gx_point_y;
303
7615
                clip_2 -> gx_rectangle_right = ori_r;
304
7615
                clip_2 -> gx_rectangle_bottom = 0;
305
            }
306
            else
307
            {
308
69
                clip_2 -> gx_rectangle_left = 0;
309
69
                clip_2 -> gx_rectangle_top = neg_r;
310
69
                clip_2 -> gx_rectangle_right = ori_r;
311
69
                clip_2 -> gx_rectangle_bottom = 0;
312
313
69
                if (end_angle <= 540)
314
                {
315
13
                    clip_3 -> gx_rectangle_left = end_point.gx_point_x;
316
13
                    clip_3 -> gx_rectangle_top = neg_r;
317
13
                    clip_3 -> gx_rectangle_right = 0;
318
13
                    clip_3 -> gx_rectangle_bottom = end_point.gx_point_y;
319
                }
320
                else
321
                {
322
56
                    clip_2 -> gx_rectangle_left = neg_r;
323
324
56
                    if (end_angle <= 630)
325
                    {
326
3
                        clip_3 -> gx_rectangle_left = neg_r;
327
3
                        clip_3 -> gx_rectangle_top = 0;
328
3
                        clip_3 -> gx_rectangle_right = end_point.gx_point_x;
329
3
                        clip_3 -> gx_rectangle_bottom = end_point.gx_point_y;
330
                    }
331
                    else
332
                    {
333
53
                        clip_3 -> gx_rectangle_left = neg_r;
334
53
                        clip_3 -> gx_rectangle_top = 0;
335
53
                        clip_3 -> gx_rectangle_right = 0;
336
53
                        clip_3 -> gx_rectangle_bottom = ori_r;
337
338
53
                        clip_4 -> gx_rectangle_left = 0;
339
53
                        clip_4 -> gx_rectangle_top = end_point.gx_point_y;
340
53
                        clip_4 -> gx_rectangle_right = end_point.gx_point_x;
341
53
                        clip_4 -> gx_rectangle_bottom = ori_r;
342
                    }
343
                }
344
            }
345
        }
346
    }
347
348
29395
    clip_1 -> gx_rectangle_left = (GX_VALUE)(clip_1 -> gx_rectangle_left + (GX_VALUE)xcenter);
349
29395
    clip_1 -> gx_rectangle_top = (GX_VALUE)(clip_1 -> gx_rectangle_top + (GX_VALUE)ycenter);
350
29395
    clip_1 -> gx_rectangle_right = (GX_VALUE)(clip_1 -> gx_rectangle_right + (GX_VALUE)xcenter);
351
29395
    clip_1 -> gx_rectangle_bottom = (GX_VALUE)(clip_1 -> gx_rectangle_bottom + (GX_VALUE)ycenter);
352
353
29395
    clip_2 -> gx_rectangle_left = (GX_VALUE)(clip_2 -> gx_rectangle_left + (GX_VALUE)xcenter);
354
29395
    clip_2 -> gx_rectangle_top = (GX_VALUE)(clip_2 -> gx_rectangle_top + (GX_VALUE)ycenter);
355
29395
    clip_2 -> gx_rectangle_right = (GX_VALUE)(clip_2 -> gx_rectangle_right + (GX_VALUE)xcenter);
356
29395
    clip_2 -> gx_rectangle_bottom = (GX_VALUE)(clip_2 -> gx_rectangle_bottom + (GX_VALUE)ycenter);
357
358
29395
    clip_3 -> gx_rectangle_left = (GX_VALUE)(clip_3 -> gx_rectangle_left + (GX_VALUE)xcenter);
359
29395
    clip_3 -> gx_rectangle_top = (GX_VALUE)(clip_3 -> gx_rectangle_top + (GX_VALUE)ycenter);
360
29395
    clip_3 -> gx_rectangle_right = (GX_VALUE)(clip_3 -> gx_rectangle_right + (GX_VALUE)xcenter);
361
29395
    clip_3 -> gx_rectangle_bottom = (GX_VALUE)(clip_3 -> gx_rectangle_bottom + (GX_VALUE)ycenter);
362
363
29395
    clip_4 -> gx_rectangle_left = (GX_VALUE)(clip_4 -> gx_rectangle_left + (GX_VALUE)xcenter);
364
29395
    clip_4 -> gx_rectangle_top = (GX_VALUE)(clip_4 -> gx_rectangle_top + (GX_VALUE)ycenter);
365
29395
    clip_4 -> gx_rectangle_right = (GX_VALUE)(clip_4 -> gx_rectangle_right + (GX_VALUE)xcenter);
366
29395
    clip_4 -> gx_rectangle_bottom = (GX_VALUE)(clip_4 -> gx_rectangle_bottom + (GX_VALUE)ycenter);
367
29395
}
368
#endif
369