GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: gx_radial_slider_anchor_angle_calculate.c Lines: 24 24 100.0 %
Date: 2024-12-05 08:52:37 Branches: 18 18 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
/**   Radial Slider Management (Slider)                                   */
18
/**                                                                       */
19
/**************************************************************************/
20
21
#define GX_SOURCE_CODE
22
23
24
/* Include necessary system files.  */
25
26
#include "gx_api.h"
27
#include "gx_radial_slider.h"
28
29
/**************************************************************************/
30
/*                                                                        */
31
/*  FUNCTION                                               RELEASE        */
32
/*                                                                        */
33
/*    _gx_radial_slider_anchor_angle_calculate            PORTABLE C      */
34
/*                                                           6.1          */
35
/*  AUTHOR                                                                */
36
/*                                                                        */
37
/*    Kenneth Maxwell, Microsoft Corporation                              */
38
/*                                                                        */
39
/*  DESCRIPTION                                                           */
40
/*                                                                        */
41
/*    This service retrieves the nearest anchor angle for the specified   */
42
/*    angle value.                                                        */
43
/*                                                                        */
44
/*  INPUT                                                                 */
45
/*                                                                        */
46
/*    slider                                Radial slider control block   */
47
/*    angle_value                           Angle value whose neareast    */
48
/*                                            anchor angle is calculated  */
49
/*                                                                        */
50
/*  OUTPUT                                                                */
51
/*                                                                        */
52
/*    status                                Completion status             */
53
/*                                                                        */
54
/*  CALLS                                                                 */
55
/*                                                                        */
56
/*    None                                                                */
57
/*                                                                        */
58
/*  CALLED BY                                                             */
59
/*                                                                        */
60
/*    GUIX Internal Code                                                  */
61
/*                                                                        */
62
/*  RELEASE HISTORY                                                       */
63
/*                                                                        */
64
/*    DATE              NAME                      DESCRIPTION             */
65
/*                                                                        */
66
/*  05-19-2020     Kenneth Maxwell          Initial Version 6.0           */
67
/*  09-30-2020     Kenneth Maxwell          Modified comment(s),          */
68
/*                                            resulting in version 6.1    */
69
/*                                                                        */
70
/**************************************************************************/
71
19
UINT _gx_radial_slider_anchor_angle_calculate(GX_RADIAL_SLIDER *slider, GX_VALUE *angle_value)
72
{
73
INT                    index;
74
GX_VALUE               min_value;
75
GX_VALUE               max_value;
76
GX_VALUE               neareast_anchor_value;
77
19
GX_RADIAL_SLIDER_INFO *info = &slider -> gx_radial_slider_info;
78
79
19
    index = 0;
80
81
    /* Range angle value inside min/max angles. */
82
19
    if (*angle_value <= info->gx_radial_slider_info_min_angle)
83
    {
84
2
        neareast_anchor_value = info->gx_radial_slider_info_min_angle;
85
    }
86
17
    else if (*angle_value >= info->gx_radial_slider_info_max_angle)
87
    {
88
2
        neareast_anchor_value = info->gx_radial_slider_info_max_angle;
89
    }
90
    else
91
    {
92
15
        neareast_anchor_value = *angle_value;
93
    }
94
95
19
    if (info -> gx_radial_slider_info_angle_list)
96
    {
97
        /* If an angle list is supplied, set the target value to one of the values
98
           in angle list that is nearest to the given value. */
99
70
        while (index < info -> gx_radial_slider_info_list_count)
100
        {
101
69
            if (index == 0)
102
            {
103
9
                min_value = info -> gx_radial_slider_info_angle_list[index];
104
            }
105
            else
106
            {
107
60
                min_value = (GX_VALUE)((info -> gx_radial_slider_info_angle_list[index] + info -> gx_radial_slider_info_angle_list[index - 1]) >> 1);
108
            }
109
110
69
            if (index == info -> gx_radial_slider_info_list_count - 1)
111
            {
112
2
                max_value = info -> gx_radial_slider_info_angle_list[index];
113
            }
114
            else
115
            {
116
67
                max_value = (GX_VALUE)((info -> gx_radial_slider_info_angle_list[index] + info -> gx_radial_slider_info_angle_list[index + 1]) >> 1);
117
            }
118
119
69
            if (min_value > max_value)
120
            {
121
59
                GX_SWAP_VALS(min_value, max_value);
122
            }
123
124

69
            if ((neareast_anchor_value >= min_value) && (neareast_anchor_value <= max_value))
125
            {
126
8
                neareast_anchor_value = info -> gx_radial_slider_info_angle_list[index];
127
8
                break;
128
            }
129
130
61
            index++;
131
        }
132
    }
133
134
19
    (*angle_value) = neareast_anchor_value;
135
136
19
    return(GX_SUCCESS);
137
}
138