GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: gx_radial_slider_angle_calculate.c Lines: 23 23 100.0 %
Date: 2026-03-06 19:21:09 Branches: 8 8 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
/**   Radial Slider Management (Slider)                                   */
19
/**                                                                       */
20
/**************************************************************************/
21
22
#define GX_SOURCE_CODE
23
24
25
/* Include necessary system files.  */
26
27
#include "gx_api.h"
28
#include "gx_utility.h"
29
#include "gx_radial_slider.h"
30
31
/**************************************************************************/
32
/*                                                                        */
33
/*  FUNCTION                                               RELEASE        */
34
/*                                                                        */
35
/*    _gx_radial_slider_angle_calculate                   PORTABLE C      */
36
/*                                                           6.1          */
37
/*  AUTHOR                                                                */
38
/*                                                                        */
39
/*    Kenneth Maxwell, Microsoft Corporation                              */
40
/*                                                                        */
41
/*  DESCRIPTION                                                           */
42
/*                                                                        */
43
/*    This service calculates the slider angle according to a point value.*/
44
/*                                                                        */
45
/*  INPUT                                                                 */
46
/*                                                                        */
47
/*    slider                                Radial slider control block   */
48
/*    point                                 Point value on radial track   */
49
/*    return_value                          Retrieved angle value         */
50
/*                                                                        */
51
/*  OUTPUT                                                                */
52
/*                                                                        */
53
/*    status                                Completion status             */
54
/*                                                                        */
55
/*  CALLS                                                                 */
56
/*                                                                        */
57
/*    _gx_utility_math_acos                 Compute acos value            */
58
/*    _gx_utility_math_asin                 Compute asin value            */
59
/*    _gx_utility_math_sqrt                 Compute sqrt value            */
60
/*                                                                        */
61
/*  CALLED BY                                                             */
62
/*                                                                        */
63
/*    GUIX Internal Code                                                  */
64
/*                                                                        */
65
/**************************************************************************/
66
32
UINT _gx_radial_slider_angle_calculate(GX_RADIAL_SLIDER *slider, GX_POINT point, GX_VALUE *return_value)
67
{
68
GX_RADIAL_SLIDER_INFO *info;
69
INT                    new_value;
70
INT                    dist;
71
INT                    x_dist;
72
INT                    y_dist;
73
INT                    x_center;
74
INT                    y_center;
75
76
32
    info = &slider -> gx_radial_slider_info;
77
78
32
    x_center = slider -> gx_widget_size.gx_rectangle_left + info -> gx_radial_slider_info_xcenter;
79
32
    y_center = slider -> gx_widget_size.gx_rectangle_top + info -> gx_radial_slider_info_ycenter;
80
81
32
    x_dist = (INT)(point.gx_point_x - x_center);
82
32
    y_dist = (INT)(point.gx_point_y - y_center);
83
84
32
    dist = (x_dist * x_dist) + (y_dist * y_dist);
85
32
    dist = (INT)_gx_utility_math_sqrt((UINT)dist);
86
87
32
    if (!dist)
88
    {
89
1
        *return_value = 0;
90
1
        return GX_FAILURE;
91
    }
92
93
31
    if (point.gx_point_y <= y_center)
94
    {
95
18
        x_dist = GX_FIXED_VAL_MAKE(x_dist) / dist;
96
97
        /* The needle is between [0, 180].  */
98
18
        new_value = _gx_utility_math_acos(x_dist);
99
    }
100
    else
101
    {
102
13
        y_dist = (GX_FIXED_VAL_MAKE(y_dist)) / dist;
103
104
        /* The needle is between [180, 360]  */
105
13
        new_value = _gx_utility_math_asin(y_dist);
106
107
13
        if (point.gx_point_x < x_center)
108
        {
109
6
            new_value = 180 + new_value;
110
        }
111
        else
112
        {
113
7
            new_value = 360 - new_value;
114
        }
115
    }
116
117
    /* Range value inside specified [-90, 270]*/
118
31
    if (new_value > 270)
119
    {
120
7
        new_value = new_value - 360;
121
    }
122
123
31
    *return_value = (GX_VALUE)new_value;
124
125
31
    return(GX_SUCCESS);
126
}
127