1 /**
2  * @file lv_circ.c
3  * Circle drawing algorithm (with Bresenham)
4  * Only a 1/8 circle is calculated. Use CIRC_OCT1_X, CIRC_OCT1_Y macros to get
5  * the other octets.
6  */
7 
8 /*********************
9  *      INCLUDES
10  *********************/
11 #include "lv_circ.h"
12 
13 /*********************
14  *      DEFINES
15  *********************/
16 
17 /**********************
18  *      TYPEDEFS
19  **********************/
20 
21 /**********************
22  *  STATIC PROTOTYPES
23  **********************/
24 
25 /**********************
26  *  STATIC VARIABLES
27  **********************/
28 
29 /**********************
30  *      MACROS
31  **********************/
32 
33 /**********************
34  *   GLOBAL FUNCTIONS
35  **********************/
36 
37 /**
38  * Initialize the circle drawing
39  * @param c pointer to a point. The coordinates will be calculated here
40  * @param tmp point to a variable. It will store temporary data
41  * @param radius radius of the circle
42  */
lv_circ_init(lv_point_t * c,lv_coord_t * tmp,lv_coord_t radius)43 void lv_circ_init(lv_point_t * c, lv_coord_t * tmp, lv_coord_t radius)
44 {
45     c->x = radius;
46     c->y = 0;
47     *tmp = 1 - radius;
48 }
49 
50 /**
51  * Test the circle drawing is ready or not
52  * @param c same as in circ_init
53  * @return true if the circle is not ready yet
54  */
lv_circ_cont(lv_point_t * c)55 bool lv_circ_cont(lv_point_t * c)
56 {
57     return c->y <= c->x ? true : false;
58 }
59 
60 /**
61  * Get the next point from the circle
62  * @param c same as in circ_init. The next point stored here.
63  * @param tmp same as in circ_init.
64  */
lv_circ_next(lv_point_t * c,lv_coord_t * tmp)65 void lv_circ_next(lv_point_t * c, lv_coord_t * tmp)
66 {
67     c->y++;
68 
69     if(*tmp <= 0) {
70         (*tmp) += 2 * c->y + 1; /*Change in decision criterion for y -> y+1*/
71     } else {
72         c->x--;
73         (*tmp) += 2 * (c->y - c->x) + 1; /*Change for y -> y+1, x -> x-1*/
74     }
75 }
76 
77 /**********************
78  *   STATIC FUNCTIONS
79  **********************/
80