@@ -29,140 +29,7 @@ void blend_tile(const pp_tile_t *t) {
2929 }
3030}
3131
32-
33- // void _pp_round_rect_corner_points(pp_path_t *path, PP_COORD_TYPE cx, PP_COORD_TYPE cy, PP_COORD_TYPE r, int q) {
34- // float quality = 5; // higher the number, lower the quality - selected by experiment
35- // int steps = ceil(r / quality) + 2; // + 2 to include start and end
36- // float delta = -(M_PI / 2) / steps;
37- // float theta = (M_PI / 2) * q; // select start theta for this quadrant
38- // for(int i = 0; i <= steps; i++) {
39- // PP_COORD_TYPE xo = sin(theta) * r, yo = cos(theta) * r;
40- // pp_path_add_point(path, (pp_point_t){cx + xo, cy + yo});
41- // theta += delta;
42- // }
43- // }
44-
45- // pp_poly_t* f_rrect(PP_COORD_TYPE x, PP_COORD_TYPE y, PP_COORD_TYPE w, PP_COORD_TYPE h, PP_COORD_TYPE tlr, PP_COORD_TYPE trr, PP_COORD_TYPE brr, PP_COORD_TYPE blr) {
46- // pp_poly_t *poly = pp_poly_new();
47- // pp_path_t *path = pp_poly_add_path(poly);
48-
49- // if(tlr == 0) {
50- // pp_path_add_point(path, (pp_point_t){x, y});
51- // }else{
52- // _pp_round_rect_corner_points(path, x + tlr, y + tlr, tlr, 3);
53- // }
54-
55- // if(trr == 0) {
56- // pp_path_add_point(path, (pp_point_t){x + w, y});
57- // }else{
58- // _pp_round_rect_corner_points(path, x + w - trr, y + trr, trr, 2);
59- // }
60-
61- // if(brr == 0) {
62- // pp_path_add_point(path, (pp_point_t){x + w, y + h});
63- // }else{
64- // _pp_round_rect_corner_points(path, x + w - brr, y + h - brr, brr, 1);
65- // }
66-
67- // if(blr == 0) {
68- // pp_path_add_point(path, (pp_point_t){x, y + h});
69- // }else{
70- // _pp_round_rect_corner_points(path, x + blr, y + h - blr, blr, 0);
71- // }
72-
73- // return poly;
74- // }
75-
76- // pp_poly_t* rrect(PP_COORD_TYPE x, PP_COORD_TYPE y, PP_COORD_TYPE w, PP_COORD_TYPE h, PP_COORD_TYPE tlr, PP_COORD_TYPE trr, PP_COORD_TYPE brr, PP_COORD_TYPE blr, PP_COORD_TYPE t) {
77- // pp_poly_t *outer = f_rrect(x, y, w, h, tlr, trr, brr, blr);
78-
79- // tlr = _pp_max(0, tlr - t);
80- // trr = _pp_max(0, trr - t);
81- // brr = _pp_max(0, brr - t);
82- // blr = _pp_max(0, blr - t);
83-
84- // pp_poly_t *inner = f_rrect(x + t, y + t, w - 2 * t, h - 2 * t, tlr, trr, brr, blr);
85- // outer->paths->next = inner->paths;
86- // inner->paths = NULL;
87- // free(inner);
88- // return outer;
89- // }
90-
91- // pp_poly_t* f_rect(PP_COORD_TYPE x, PP_COORD_TYPE y, PP_COORD_TYPE w, PP_COORD_TYPE h) {
92- // pp_poly_t *poly = pp_poly_new();
93- // pp_path_t *path = pp_poly_add_path(poly);
94- // pp_path_add_points(path, (pp_point_t[]){{x, y}, {x + w, y}, {x + w, y + h}, {x, y + h}}, 4);
95- // return poly;
96- // }
97-
98- // pp_poly_t* rect(PP_COORD_TYPE x, PP_COORD_TYPE y, PP_COORD_TYPE w, PP_COORD_TYPE h, PP_COORD_TYPE t) {
99- // pp_poly_t *poly = pp_poly_new();
100- // pp_path_t *outer = pp_poly_add_path(poly), *inner = pp_poly_add_path(poly);
101- // pp_path_add_points(outer, (pp_point_t[]){{x, y}, {x + w, y}, {x + w, y + h}, {x, y + h}}, 4);
102- // x += t; y += t; w -= 2 * t; h -= 2 * t;
103- // pp_path_add_points(inner, (pp_point_t[]){{x, y}, {x + w, y}, {x + w, y + h}, {x, y + h}}, 4);
104- // return poly;
105- // }
106- /*
107- pp_poly_t* f_reg(PP_COORD_TYPE x, PP_COORD_TYPE y, PP_COORD_TYPE r, int s) {
108- pp_poly_t *poly = pp_poly_new();
109- pp_path_t *path = pp_poly_add_path(poly);
110- for(int i = 0; i < s; i++) {
111- pp_point_t p;
112- float step = ((M_PI * 2.0f) / (float)s) * (float)i;
113- p.x = sin(step) * r + x;
114- p.y = cos(step) * r + y;
115- pp_path_add_point(path, p);
116- }
117- return poly;
118- }
119-
120- pp_poly_t* reg(PP_COORD_TYPE x, PP_COORD_TYPE y, PP_COORD_TYPE r, int s, PP_COORD_TYPE t) {
121- pp_poly_t *outer = f_reg(x, y, r, s);
122- pp_poly_t *inner = f_reg(x, y, r - t, s);
123- outer->paths->next = inner->paths;
124- inner->paths = NULL;
125- free(inner);
126- return outer;
127- }*/
12832/*
129- pp_poly_t* f_circ(PP_COORD_TYPE x, PP_COORD_TYPE y, PP_COORD_TYPE r) {
130- int s = _pp_max(8, r);
131- return f_reg(x, y, r, s);
132- }
133-
134- pp_poly_t* circ(PP_COORD_TYPE x, PP_COORD_TYPE y, PP_COORD_TYPE r, PP_COORD_TYPE t) {
135- pp_poly_t *outer = f_circ(x, y, r);
136- pp_poly_t *inner = f_circ(x, y, r - t);
137- outer->paths->next = inner->paths;
138- inner->paths = NULL;
139- free(inner);
140- return outer;
141- }*/
142-
143- pp_poly_t * f_star (PP_COORD_TYPE x , PP_COORD_TYPE y , int c , PP_COORD_TYPE or , PP_COORD_TYPE ir ) {
144- pp_poly_t * poly = pp_poly_new ();
145- pp_path_t * path = pp_poly_add_path (poly );
146- for (int i = 0 ; i < c * 2 ; i ++ ) {
147- pp_point_t p ;
148- float step = ((M_PI * 2 ) / (float )(c * 2 )) * (float )i ;
149- PP_COORD_TYPE r = i % 2 == 0 ? or : ir ;
150- p .x = sin (step ) * r + x ;
151- p .y = cos (step ) * r + y ;
152- pp_path_add_point (path , p );
153- }
154- return poly ;
155- }
156-
157- pp_poly_t * star (PP_COORD_TYPE x , PP_COORD_TYPE y , int c , PP_COORD_TYPE or , PP_COORD_TYPE ir , PP_COORD_TYPE t ) {
158- pp_poly_t * outer = f_star (x , y , c , or , ir );
159- pp_poly_t * inner = f_star (x , y , c , or - (t * or / ir ), ir - t );
160- outer -> paths -> next = inner -> paths ;
161- inner -> paths = NULL ;
162- free (inner );
163- return outer ;
164- }
165-
16633pp_poly_t* f_gear(PP_COORD_TYPE x, PP_COORD_TYPE y, int c, PP_COORD_TYPE or, PP_COORD_TYPE ir) {
16734 pp_poly_t *poly = pp_poly_new();
16835 pp_path_t *path = pp_poly_add_path(poly);
@@ -181,7 +48,7 @@ pp_poly_t* f_gear(PP_COORD_TYPE x, PP_COORD_TYPE y, int c, PP_COORD_TYPE or, PP_
18148 pp_path_add_point(path, p);
18249 }
18350 return poly;
184- }
51+ }*/
18552
18653pp_poly_t * gear (PP_COORD_TYPE x , PP_COORD_TYPE y , int c , PP_COORD_TYPE or , PP_COORD_TYPE ir , PP_COORD_TYPE t ) {
18754 /*pp_poly_t *outer = f_gear(x, y, c, or, ir);
@@ -193,69 +60,6 @@ pp_poly_t* gear(PP_COORD_TYPE x, PP_COORD_TYPE y, int c, PP_COORD_TYPE or, PP_CO
19360 return NULL ;
19461}
19562
196- pp_poly_t * line (PP_COORD_TYPE x1 , PP_COORD_TYPE y1 , PP_COORD_TYPE x2 , PP_COORD_TYPE y2 , PP_COORD_TYPE t ) {
197- pp_poly_t * poly = pp_poly_new ();
198- pp_path_t * path = pp_poly_add_path (poly );
199-
200- // create a normalised perpendicular vector
201- pp_point_t v = {y2 - y1 , x2 - x1 };
202- float mag = sqrt (v .x * v .x + v .y * v .y );
203- t /= 2.0f ; v .x /= mag ; v .y /= mag ; v .x *= - t ; v .y *= t ;
204- pp_path_add_points (path , (pp_point_t []){{x1 + v .x , y1 + v .y }, {x2 + v .x , y2 + v .y }, {x2 - v .x , y2 - v .y }, {x1 - v .x , y1 - v .y }}, 4 );
205- return poly ;
206- }
207-
208- /*
209- pp_poly_t *pie(PP_COORD_TYPE x, PP_COORD_TYPE y, PP_COORD_TYPE r, float sa, float ea) {
210- pp_poly_t *poly = pp_poly_new();
211- pp_path_t *path = pp_poly_add_path(poly);
212- pp_path_add_point(path, (pp_point_t){x, y});
213-
214- sa = sa * (M_PI / 180.0f);
215- ea = ea * (M_PI / 180.0f);
216- int s = _pp_max(8, r);
217- float astep = (ea - sa) / s;
218- for(float a = sa; a < ea; a+=astep) {
219- pp_point_t p;
220- p.x = sin(a) * r + x;
221- p.y = cos(a) * r + y;
222- pp_path_add_point(path, p);
223- }
224-
225- return poly;
226- }
227-
228-
229- pp_poly_t *arc(PP_COORD_TYPE x, PP_COORD_TYPE y, PP_COORD_TYPE r, float sa, float ea, PP_COORD_TYPE thickness) {
230- pp_poly_t *poly = pp_poly_new();
231- pp_path_t *path = pp_poly_add_path(poly);
232-
233- sa = sa * (M_PI / 180.0f);
234- ea = ea * (M_PI / 180.0f);
235-
236- int s = _pp_max(8, r);
237- float astep = (ea - sa) / s;
238- float a = sa;
239- for(int i = 0; i <= s; i++) {
240- pp_point_t p;
241- p.x = sin(a) * r + x;
242- p.y = cos(a) * r + y;
243- pp_path_add_point(path, p);
244- a += astep;
245- }
246-
247- r -= thickness;
248- a = ea;
249- for(int i = 0; i <= s; i++) {
250- pp_point_t p;
251- p.x = sin(a) * r + x;
252- p.y = cos(a) * r + y;
253- pp_path_add_point(path, p);
254- a -= astep;
255- }
256-
257- return poly;
258- }*/
25963
26064int main () {
26165 pp_tile_callback (blend_tile );
@@ -302,10 +106,12 @@ int main() {
302106 poly = ppp_regular (r );
303107 }break ;
304108 case 6 : {
305- poly = f_star (0 , 0 , 7 , size , size * .75 );
109+ ppp_star_def r = {0 , 0 , 7 , size , size * 0.75f };
110+ poly = ppp_star (r );
306111 }break ;
307112 case 7 : {
308- poly = star (0 , 0 , 7 , size , size * .75 , thickness );
113+ ppp_star_def r = {0 , 0 , 7 , size , size * 0.75f , thickness };
114+ poly = ppp_star (r );
309115 }break ;
310116 case 8 : {
311117 ppp_rect_def r = {- size , - size , size * 2 , size * 2 , 0 , size * .5 , size * .05 , size * .15 , size * .7 };
0 commit comments