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 |
|
|
/** 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 |
|
|
/**************************************************************************/ |
70 |
|
154441 |
UINT _gx_utility_circle_point_get(INT xcenter, INT ycenter, UINT r, INT angle, GX_POINT *point) |
71 |
|
|
{ |
72 |
|
|
|
73 |
|
|
INT x; |
74 |
|
|
INT y; |
75 |
|
|
INT d; |
76 |
|
|
INT x_sign; |
77 |
|
|
INT y_sign; |
78 |
|
154441 |
GX_BOOL swap = GX_FALSE; |
79 |
|
|
|
80 |
|
154441 |
angle %= 360; |
81 |
|
|
|
82 |
✓✓ |
154441 |
if (angle < 0) |
83 |
|
|
{ |
84 |
|
1 |
angle += 360; |
85 |
|
|
} |
86 |
|
|
|
87 |
✓✓ |
154441 |
if (angle == 0) |
88 |
|
|
{ |
89 |
|
2962 |
point -> gx_point_x = (GX_VALUE)(xcenter + (INT)r); |
90 |
|
2962 |
point -> gx_point_y = (GX_VALUE)ycenter; |
91 |
|
|
} |
92 |
✓✓ |
151479 |
else if (angle == 90) |
93 |
|
|
{ |
94 |
|
40217 |
point -> gx_point_x = (GX_VALUE)xcenter; |
95 |
|
40217 |
point -> gx_point_y = (GX_VALUE)(ycenter - (INT)r); |
96 |
|
|
} |
97 |
✓✓ |
111262 |
else if (angle == 180) |
98 |
|
|
{ |
99 |
|
15735 |
point -> gx_point_x = (GX_VALUE)(xcenter - (INT)r); |
100 |
|
15735 |
point -> gx_point_y = (GX_VALUE)ycenter; |
101 |
|
|
} |
102 |
✓✓ |
95527 |
else if (angle == 270) |
103 |
|
|
{ |
104 |
|
28967 |
point -> gx_point_x = (GX_VALUE)xcenter; |
105 |
|
28967 |
point -> gx_point_y = (GX_VALUE)(ycenter + (INT)r); |
106 |
|
|
} |
107 |
|
|
else |
108 |
|
|
{ |
109 |
|
66560 |
point -> gx_point_x = (GX_VALUE)(GX_FIXED_VAL_TO_INT(r * _gx_utility_math_cos(GX_FIXED_VAL_MAKE(angle)))); |
110 |
|
66560 |
point -> gx_point_y = (GX_VALUE)(GX_FIXED_VAL_TO_INT(r * _gx_utility_math_sin(GX_FIXED_VAL_MAKE(angle)))); |
111 |
|
|
|
112 |
✓✓ |
66560 |
if (angle <= 90) |
113 |
|
|
{ |
114 |
|
32494 |
x_sign = 1; |
115 |
|
32494 |
y_sign = 1; |
116 |
|
|
|
117 |
✓✓ |
32494 |
if (angle < 45) |
118 |
|
|
{ |
119 |
|
24270 |
swap = GX_TRUE; |
120 |
|
|
} |
121 |
|
|
} |
122 |
✓✓ |
34066 |
else if (angle <= 180) |
123 |
|
|
{ |
124 |
|
10069 |
x_sign = -1; |
125 |
|
10069 |
y_sign = 1; |
126 |
|
|
|
127 |
✓✓ |
10069 |
if (angle > 135) |
128 |
|
|
{ |
129 |
|
6699 |
swap = GX_TRUE; |
130 |
|
|
} |
131 |
|
|
} |
132 |
✓✓ |
23997 |
else if (angle <= 270) |
133 |
|
|
{ |
134 |
|
10345 |
x_sign = -1; |
135 |
|
10345 |
y_sign = -1; |
136 |
|
|
|
137 |
✓✓ |
10345 |
if (angle < 225) |
138 |
|
|
{ |
139 |
|
8016 |
swap = GX_TRUE; |
140 |
|
|
} |
141 |
|
|
} |
142 |
|
|
else |
143 |
|
|
{ |
144 |
|
13652 |
x_sign = 1; |
145 |
|
13652 |
y_sign = -1; |
146 |
|
|
|
147 |
✓✓ |
13652 |
if (angle > 315) |
148 |
|
|
{ |
149 |
|
4106 |
swap = GX_TRUE; |
150 |
|
|
} |
151 |
|
|
} |
152 |
|
|
|
153 |
|
66560 |
x = 0; |
154 |
|
66560 |
y = (INT)r; |
155 |
|
66560 |
d = (INT)(5 - 4 * r); |
156 |
|
|
|
157 |
|
66560 |
point -> gx_point_x = (GX_VALUE)(point -> gx_point_x * x_sign); |
158 |
|
66560 |
point -> gx_point_y = (GX_VALUE)(point -> gx_point_y * y_sign); |
159 |
|
|
|
160 |
✓✓ |
66560 |
if (swap) |
161 |
|
|
{ |
162 |
|
43091 |
GX_SWAP_VALS(point -> gx_point_x, point -> gx_point_y); |
163 |
|
|
} |
164 |
|
|
|
165 |
✓✓ |
2335347 |
while (x <= y) |
166 |
|
|
{ |
167 |
✓✓✓✓
|
2329911 |
if ((x > point -> gx_point_x) || (y < point -> gx_point_y)) |
168 |
|
|
{ |
169 |
|
|
break; |
170 |
|
|
} |
171 |
|
|
|
172 |
✓✓ |
2268787 |
if (d < 0) |
173 |
|
|
{ |
174 |
|
1719950 |
d += 8 * x + 12; |
175 |
|
|
} |
176 |
|
|
else |
177 |
|
|
{ |
178 |
|
548837 |
d += 8 * (x - y) + 20; |
179 |
|
548837 |
y--; |
180 |
|
|
} |
181 |
|
2268787 |
x++; |
182 |
|
|
} |
183 |
|
|
|
184 |
✓✓ |
66560 |
if (swap) |
185 |
|
|
{ |
186 |
|
43091 |
GX_SWAP_VALS(x, y); |
187 |
|
|
} |
188 |
|
|
|
189 |
|
66560 |
x *= x_sign; |
190 |
|
66560 |
y *= y_sign; |
191 |
|
|
|
192 |
|
66560 |
point -> gx_point_x = (GX_VALUE)(xcenter + x); |
193 |
|
66560 |
point -> gx_point_y = (GX_VALUE)(ycenter - y); |
194 |
|
|
} |
195 |
|
|
|
196 |
|
154441 |
return GX_SUCCESS; |
197 |
|
|
} |
198 |
|
|
|