1 /**************************************************************************/
2 /* */
3 /* Copyright (c) Microsoft Corporation. All rights reserved. */
4 /* */
5 /* This software is licensed under the Microsoft Software License */
6 /* Terms for Microsoft Azure RTOS. Full text of the license can be */
7 /* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
8 /* and in the root directory of this software. */
9 /* */
10 /**************************************************************************/
11
12
13 /**************************************************************************/
14 /**************************************************************************/
15 /** */
16 /** GUIX Component */
17 /** */
18 /** Utility (Utility) */
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
31 /**************************************************************************/
32 /* */
33 /* FUNCTION RELEASE */
34 /* */
35 /* _gx_utility_circle_point_get PORTABLE C */
36 /* 6.1 */
37 /* AUTHOR */
38 /* */
39 /* Kenneth Maxwell, Microsoft Corporation */
40 /* */
41 /* DESCRIPTION */
42 /* */
43 /* This function gets the point on circle with specified angle */
44 /* and radius. */
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 /* angle The angle where the point is */
52 /* point Return value of the point at */
53 /* the angle */
54 /* */
55 /* OUTPUT */
56 /* */
57 /* None */
58 /* */
59 /* CALLS */
60 /* */
61 /* _gx_utility_math_cos Compute cosine */
62 /* _gx_utility_math_sin Compute sine */
63 /* */
64 /* CALLED BY */
65 /* */
66 /* Application Code */
67 /* GUIX Internal Code */
68 /* */
69 /* RELEASE HISTORY */
70 /* */
71 /* DATE NAME DESCRIPTION */
72 /* */
73 /* 05-19-2020 Kenneth Maxwell Initial Version 6.0 */
74 /* 09-30-2020 Kenneth Maxwell Modified comment(s), */
75 /* resulting in version 6.1 */
76 /* */
77 /**************************************************************************/
_gx_utility_circle_point_get(INT xcenter,INT ycenter,UINT r,INT angle,GX_POINT * point)78 UINT _gx_utility_circle_point_get(INT xcenter, INT ycenter, UINT r, INT angle, GX_POINT *point)
79 {
80
81 INT x;
82 INT y;
83 INT d;
84 INT x_sign;
85 INT y_sign;
86 GX_BOOL swap = GX_FALSE;
87
88 angle %= 360;
89
90 if (angle < 0)
91 {
92 angle += 360;
93 }
94
95 if (angle == 0)
96 {
97 point -> gx_point_x = (GX_VALUE)(xcenter + (INT)r);
98 point -> gx_point_y = (GX_VALUE)ycenter;
99 }
100 else if (angle == 90)
101 {
102 point -> gx_point_x = (GX_VALUE)xcenter;
103 point -> gx_point_y = (GX_VALUE)(ycenter - (INT)r);
104 }
105 else if (angle == 180)
106 {
107 point -> gx_point_x = (GX_VALUE)(xcenter - (INT)r);
108 point -> gx_point_y = (GX_VALUE)ycenter;
109 }
110 else if (angle == 270)
111 {
112 point -> gx_point_x = (GX_VALUE)xcenter;
113 point -> gx_point_y = (GX_VALUE)(ycenter + (INT)r);
114 }
115 else
116 {
117 point -> gx_point_x = (GX_VALUE)(GX_FIXED_VAL_TO_INT(r * _gx_utility_math_cos(GX_FIXED_VAL_MAKE(angle))));
118 point -> gx_point_y = (GX_VALUE)(GX_FIXED_VAL_TO_INT(r * _gx_utility_math_sin(GX_FIXED_VAL_MAKE(angle))));
119
120 if (angle <= 90)
121 {
122 x_sign = 1;
123 y_sign = 1;
124
125 if (angle < 45)
126 {
127 swap = GX_TRUE;
128 }
129 }
130 else if (angle <= 180)
131 {
132 x_sign = -1;
133 y_sign = 1;
134
135 if (angle > 135)
136 {
137 swap = GX_TRUE;
138 }
139 }
140 else if (angle <= 270)
141 {
142 x_sign = -1;
143 y_sign = -1;
144
145 if (angle < 225)
146 {
147 swap = GX_TRUE;
148 }
149 }
150 else
151 {
152 x_sign = 1;
153 y_sign = -1;
154
155 if (angle > 315)
156 {
157 swap = GX_TRUE;
158 }
159 }
160
161 x = 0;
162 y = (INT)r;
163 d = (INT)(5 - 4 * r);
164
165 point -> gx_point_x = (GX_VALUE)(point -> gx_point_x * x_sign);
166 point -> gx_point_y = (GX_VALUE)(point -> gx_point_y * y_sign);
167
168 if (swap)
169 {
170 GX_SWAP_VALS(point -> gx_point_x, point -> gx_point_y);
171 }
172
173 while (x <= y)
174 {
175 if ((x > point -> gx_point_x) || (y < point -> gx_point_y))
176 {
177 break;
178 }
179
180 if (d < 0)
181 {
182 d += 8 * x + 12;
183 }
184 else
185 {
186 d += 8 * (x - y) + 20;
187 y--;
188 }
189 x++;
190 }
191
192 if (swap)
193 {
194 GX_SWAP_VALS(x, y);
195 }
196
197 x *= x_sign;
198 y *= y_sign;
199
200 point -> gx_point_x = (GX_VALUE)(xcenter + x);
201 point -> gx_point_y = (GX_VALUE)(ycenter - y);
202 }
203
204 return GX_SUCCESS;
205 }
206
207