From d6ce86cae4b9cac6bdcd1ebf81333c6cb9e759b8 Mon Sep 17 00:00:00 2001 From: Thomas Bernard Date: Sat, 3 Mar 2018 02:26:02 +0100 Subject: [PATCH] Remove Circle_limit global variable --- src/factory.c | 3 +- src/global.h | 4 --- src/graph.c | 40 ++++++++++++++++----------- src/graph.h | 14 +++++----- src/operatio.c | 75 ++++++++++++++++++++++---------------------------- 5 files changed, 65 insertions(+), 71 deletions(-) diff --git a/src/factory.c b/src/factory.c index 71e0cecf..63d203e3 100644 --- a/src/factory.c +++ b/src/factory.c @@ -599,8 +599,7 @@ int L_DrawCircle(lua_State* L) LUA_ARG_NUMBER(4, "drawcircle", c, INT_MIN, INT_MAX); Set_Pixel_figure((void (*) (word,word,byte))Pixel_figure_no_screen); - Circle_limit = r*r; - Draw_empty_circle_general(x1, y1, r, c); + Draw_empty_circle_general(x1, y1, r*r, c); return 0; } diff --git a/src/global.h b/src/global.h index c9941ec7..d15cf120 100644 --- a/src/global.h +++ b/src/global.h @@ -566,10 +566,6 @@ GFX2_GLOBAL byte Mask_table[256]; extern word ZOOM_FACTOR[NB_ZOOM_FACTORS]; #endif -// -- Data for ellipses and circles -// FIXME: move this to graph.c -GFX2_GLOBAL long Circle_limit; - // -- Data for gradients /// First color of the gradient. diff --git a/src/graph.c b/src/graph.c index f858397c..04db35c8 100644 --- a/src/graph.c +++ b/src/graph.c @@ -104,9 +104,9 @@ static byte Pixel_in_ellipse(long x, long y, const T_Ellipse_limits * Ellipse) // Circle_cursor_Y pixels (Circle_cursor_Y>0 = en bas, // Circle_cursor_Y<0 = en haut) du centre se trouve dans le cercle en // cours. -static byte Pixel_in_circle(long x, long y) +static byte Pixel_in_circle(long x, long y, long limit) { - if((x * x + y * y) <= Circle_limit) + if((x * x + y * y) <= limit) return 255; return 0; } @@ -1219,13 +1219,16 @@ void Fill_general(byte fill_color) // -- Tracer général d'un cercle vide ------------------------------------- -void Draw_empty_circle_general(short center_x,short center_y,short radius,byte color) +void Draw_empty_circle_general(short center_x,short center_y, long sqradius,byte color) { short start_x; short start_y; short x_pos; short y_pos; long x, y; + short radius; + + radius = sqrt(sqradius); // Ensuite, on va parcourire le quart haut gauche du cercle start_x=center_x-radius; @@ -1234,7 +1237,7 @@ void Draw_empty_circle_general(short center_x,short center_y,short radius,byte c // Affichage des extremitées du cercle sur chaque quart du cercle: for (y_pos=start_y,y=-radius;y_posLimit_right) end_x=Limit_right; - Gradient_total_range=Circle_limit+ + Gradient_total_range=sqradius+ ((center_x-spot_x)*(center_x-spot_x))+ ((center_y-spot_y)*(center_y-spot_y))+ (2L*radius*sqrt( @@ -2252,7 +2260,7 @@ void Draw_grad_circle(short center_x,short center_y,short radius,short spot_x,sh distance_y =(y_pos-spot_y); distance_y*=distance_y; for (x_pos=start_x,x=(long)start_x-center_x;x_pos<=end_x;x_pos++,x++) - if (Pixel_in_circle(x, y)) + if (Pixel_in_circle(x, y, sqradius)) { distance_x =(x_pos-spot_x); distance_x*=distance_x; diff --git a/src/graph.h b/src/graph.h index bac4285f..f999b597 100644 --- a/src/graph.h +++ b/src/graph.h @@ -60,13 +60,13 @@ void Pixel_figure_preview_xor(short x_pos,short y_pos,byte color); void Pixel_figure_preview_xorback(word x_pos,word y_pos,byte color); void Pixel_figure_in_brush(word x_pos,word y_pos,byte color); -void Draw_empty_circle_general(short center_x,short center_y,short radius,byte color); +void Draw_empty_circle_general(short center_x,short center_y,long sqradius,byte color); -void Draw_empty_circle_permanent(short center_x,short center_y,short radius,byte color); -void Draw_empty_circle_preview (short center_x,short center_y,short radius,byte color); -void Hide_empty_circle_preview (short center_x,short center_y,short radius); -void Draw_empty_circle_general(short center_x,short center_y,short radius,byte color); -void Draw_filled_circle (short center_x,short center_y,short radius,byte color); +void Draw_empty_circle_permanent(short center_x,short center_y,long sqradius,byte color); +void Draw_empty_circle_preview (short center_x,short center_y,long sqradius,byte color); +void Hide_empty_circle_preview (short center_x,short center_y,long sqradius); +void Draw_empty_circle_general(short center_x,short center_y,long sqradius,byte color); +void Draw_filled_circle (short center_x,short center_y,long sqradius,byte color); int Circle_squared_diameter(int diameter); @@ -97,7 +97,7 @@ void Gradient_dithered (long index,short x_pos,short y_pos); void Gradient_extra_dithered(long index,short x_pos,short y_pos); void Degrade_aleatoire (long index,short x_pos,short y_pos); -void Draw_grad_circle (short center_x,short center_y,short radius,short spot_x,short spot_y); +void Draw_grad_circle (short center_x,short center_y,long sqradius,short spot_x,short spot_y); void Draw_grad_ellipse(short center_x,short center_y,short horizontal_radius,short vertical_radius,short spot_x,short spot_y); void Draw_grad_rectangle(short rax,short ray,short rbx,short rby,short vax,short vay, short vbx, short vby); diff --git a/src/operatio.c b/src/operatio.c index 86daf183..bcd13bf3 100644 --- a/src/operatio.c +++ b/src/operatio.c @@ -996,7 +996,7 @@ void Circle_12_5(void) short center_x; short center_y; short color; - short radius; + long limit; char str[5]; Operation_pop(&tangent_y); @@ -1017,15 +1017,13 @@ void Circle_12_5(void) else Print_coordinates(); - Circle_limit=((tangent_x-center_x)*(tangent_x-center_x))+ - ((tangent_y-center_y)*(tangent_y-center_y)); - radius=sqrt(Circle_limit); - Hide_empty_circle_preview(center_x,center_y,radius); + limit=((tangent_x-center_x)*(tangent_x-center_x))+ + ((tangent_y-center_y)*(tangent_y-center_y)); + Hide_empty_circle_preview(center_x,center_y,limit); - Circle_limit=((Paintbrush_X-center_x)*(Paintbrush_X-center_x))+ - ((Paintbrush_Y-center_y)*(Paintbrush_Y-center_y)); - radius=sqrt(Circle_limit); - Draw_empty_circle_preview(center_x,center_y,radius,color); + limit=((Paintbrush_X-center_x)*(Paintbrush_X-center_x))+ + ((Paintbrush_Y-center_y)*(Paintbrush_Y-center_y)); + Draw_empty_circle_preview(center_x,center_y,limit,color); Display_cursor(); } @@ -1052,7 +1050,7 @@ void Empty_circle_0_5(void) short center_x; short center_y; short color; - short radius; + long limit; Operation_pop(&tangent_y); Operation_pop(&tangent_x); @@ -1060,14 +1058,13 @@ void Empty_circle_0_5(void) Operation_pop(¢er_x); Operation_pop(&color); - Circle_limit=((tangent_x-center_x)*(tangent_x-center_x))+ - ((tangent_y-center_y)*(tangent_y-center_y)); - radius=sqrt(Circle_limit); - Hide_empty_circle_preview(center_x,center_y,radius); + limit=((tangent_x-center_x)*(tangent_x-center_x))+ + ((tangent_y-center_y)*(tangent_y-center_y)); + Hide_empty_circle_preview(center_x,center_y,limit); Paintbrush_shape=Paintbrush_shape_before_operation; - Draw_empty_circle_permanent(center_x,center_y,radius,color); + Draw_empty_circle_permanent(center_x,center_y,limit,color); End_of_modification(); @@ -1094,7 +1091,7 @@ void Filled_circle_0_5(void) short center_x; short center_y; short color; - short radius; + long limit; Operation_pop(&tangent_y); Operation_pop(&tangent_x); @@ -1102,14 +1099,13 @@ void Filled_circle_0_5(void) Operation_pop(¢er_x); Operation_pop(&color); - Circle_limit=((tangent_x-center_x)*(tangent_x-center_x))+ - ((tangent_y-center_y)*(tangent_y-center_y)); - radius=sqrt(Circle_limit); - Hide_empty_circle_preview(center_x,center_y,radius); + limit=((tangent_x-center_x)*(tangent_x-center_x))+ + ((tangent_y-center_y)*(tangent_y-center_y)); + Hide_empty_circle_preview(center_x,center_y,limit); Paintbrush_shape=Paintbrush_shape_before_operation; - Draw_filled_circle(center_x,center_y,radius,color); + Draw_filled_circle(center_x,center_y,limit,color); End_of_modification(); if ( (Config.Coords_rel) && (Menu_is_visible) ) @@ -2983,7 +2979,7 @@ void Grad_circle_12_6(void) short center_x; short center_y; short color; - short radius; + long limit; char str[5]; Operation_pop(&tangent_y); @@ -3005,15 +3001,13 @@ void Grad_circle_12_6(void) else Print_coordinates(); - Circle_limit=((tangent_x-center_x)*(tangent_x-center_x))+ - ((tangent_y-center_y)*(tangent_y-center_y)); - radius=sqrt(Circle_limit); - Hide_empty_circle_preview(center_x,center_y,radius); + limit=((tangent_x-center_x)*(tangent_x-center_x))+ + ((tangent_y-center_y)*(tangent_y-center_y)); + Hide_empty_circle_preview(center_x,center_y,limit); - Circle_limit=((Paintbrush_X-center_x)*(Paintbrush_X-center_x))+ + limit=((Paintbrush_X-center_x)*(Paintbrush_X-center_x))+ ((Paintbrush_Y-center_y)*(Paintbrush_Y-center_y)); - radius=sqrt(Circle_limit); - Draw_empty_circle_preview(center_x,center_y,radius,color); + Draw_empty_circle_preview(center_x,center_y,limit,color); Display_cursor(); } @@ -3041,7 +3035,6 @@ void Grad_circle_0_6(void) short center_y; short color; short click; - short radius; Operation_pop(&tangent_y); Operation_pop(&tangent_x); @@ -3081,15 +3074,15 @@ void Grad_circle_0_6(void) } else { - Circle_limit=((tangent_x-center_x)*(tangent_x-center_x))+ - ((tangent_y-center_y)*(tangent_y-center_y)); - radius=sqrt(Circle_limit); - Hide_empty_circle_preview(center_x,center_y,radius); + long limit; + limit=((tangent_x-center_x)*(tangent_x-center_x))+ + ((tangent_y-center_y)*(tangent_y-center_y)); + Hide_empty_circle_preview(center_x,center_y,limit); Paintbrush_hidden=Paintbrush_hidden_before_scroll; Cursor_shape=CURSOR_SHAPE_TARGET; - Draw_filled_circle(center_x,center_y,radius,Back_color); + Draw_filled_circle(center_x,center_y,limit,Back_color); End_of_modification(); if ((Config.Coords_rel) && (Menu_is_visible)) @@ -3116,8 +3109,7 @@ void Grad_circle_12_8(void) short center_y; short color; short old_mouse_k; - - short radius; + long limit; Operation_stack_size-=2; // On fait sauter les 2 derniers élts de la pile Operation_pop(&tangent_y); @@ -3131,16 +3123,15 @@ void Grad_circle_12_8(void) // On efface la croix XOR au centre du cercle Draw_curve_cross(center_x,center_y); - Circle_limit=((tangent_x-center_x)*(tangent_x-center_x))+ - ((tangent_y-center_y)*(tangent_y-center_y)); - radius=sqrt(Circle_limit); - Hide_empty_circle_preview(center_x,center_y,radius); + limit=((tangent_x-center_x)*(tangent_x-center_x))+ + ((tangent_y-center_y)*(tangent_y-center_y)); + Hide_empty_circle_preview(center_x,center_y,limit); Paintbrush_hidden=Paintbrush_hidden_before_scroll; Cursor_shape=CURSOR_SHAPE_TARGET; if (Mouse_K==old_mouse_k) - Draw_grad_circle(center_x,center_y,radius,Paintbrush_X,Paintbrush_Y); + Draw_grad_circle(center_x,center_y,limit,Paintbrush_X,Paintbrush_Y); Cursor_shape=CURSOR_SHAPE_XOR_TARGET; Display_cursor();