|
8 | 8 | #define TWO_PI 6.28318530717958647693f
|
9 | 9 | #define INV_TWO_PI 0.15915494309189533576876437577476f
|
10 | 10 |
|
| 11 | +#ifdef MP_SOFT_ATAN2 |
| 12 | + |
| 13 | +// Approximates atan2(y, x) normalized to the [0,4) range |
| 14 | +// with a maximum error of 0.1620 degrees |
| 15 | +float soft_atan2( float y, float x ) |
| 16 | +{ |
| 17 | + static const uint32_t sign_mask = 0x80000000; |
| 18 | + static const float b = 0.596227f; |
| 19 | + |
| 20 | + // Extract the sign bits |
| 21 | + uint32_t ux_s = sign_mask & (uint32_t &)x; |
| 22 | + uint32_t uy_s = sign_mask & (uint32_t &)y; |
| 23 | + |
| 24 | + // Determine the quadrant offset |
| 25 | + float q = (float)( ( ~ux_s & uy_s ) >> 29 | ux_s >> 30 ); |
| 26 | + |
| 27 | + // Calculate the arctangent in the first quadrant |
| 28 | + float bxy_a = fabs( b * x * y ); |
| 29 | + float num = bxy_a + y * y; |
| 30 | + float atan_1q = num / ( x * x + bxy_a + num ); |
| 31 | + |
| 32 | + // Translate it to the proper quadrant |
| 33 | + uint32_t uatan_2q = (ux_s ^ uy_s) | (uint32_t &)atan_1q; |
| 34 | + return q + (float &)uatan_2q; |
| 35 | +} |
| 36 | + |
| 37 | +#endif /* MP_SOFT_ATAN */ |
| 38 | + |
11 | 39 |
|
12 | 40 | float floormod(float x, float y) {
|
13 | 41 | int32_t res = (int32_t)x;
|
@@ -49,7 +77,11 @@ void lv_conical_gradient(uint8_t *buf, uint16_t radius, const lv_grad_dsc_t *gra
|
49 | 77 | run = radius;
|
50 | 78 |
|
51 | 79 | for (uint32_t x=0; x < diameter; x++) {
|
52 |
| - t = (float)atan2((float)rise, (float)run) + (float)PI - (float)angle; |
| 80 | + #ifdef MP_SOFT_ATAN2 |
| 81 | + t = (float)soft_atan2((float)rise, (float)run) + (float)PI - (float)angle; |
| 82 | + #else |
| 83 | + t = (float)atan2((float)rise, (float)run) + (float)PI - (float)angle; |
| 84 | + #endif |
53 | 85 |
|
54 | 86 | if (twist > 0) {
|
55 | 87 | t += TWO_PI * sqrtf((float)(rise * rise + run * run) / (float)twist);
|
|
0 commit comments