From d2584ac80ea391964d2d41daa5feadbea3831453 Mon Sep 17 00:00:00 2001 From: Matthew Fernandez Date: Thu, 24 Mar 2022 22:13:05 -0700 Subject: [PATCH] use suffixed literals instead of casts to construct 'GLfloat' values MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit The `GLfloat` type is 32-bit IEEE-754 floating-point.¹ As of C99, the `float` type is also 32-bit IEEE-754 floating-point on all platforms with support.² In contemporary usage, this is effectively all C99 platforms that support floating-point arithmetic. Graphviz has been compiled in C99 mode since commit fe3f9411d2c59b463ab1b64eecfd19f2db55d2fc. Putting those things together, we can abbreviate the way we write `GLfloat` literals, leading to more readable code. ¹ https://www.khronos.org/opengl/wiki/OpenGL_Type ² https://en.wikipedia.org/wiki/C99#IEEE_754_floating-point_support --- cmd/smyrna/topfisheyeview.c | 13 +++--- lib/glcomp/glcompdefs.h | 82 ++++++++++++++++++------------------- lib/glcomp/glcompfont.c | 4 +- lib/glcomp/glcompimage.c | 2 +- lib/glcomp/glutils.c | 4 +- 5 files changed, 51 insertions(+), 54 deletions(-) diff --git a/cmd/smyrna/topfisheyeview.c b/cmd/smyrna/topfisheyeview.c index 347f093aa..43ad3715e 100644 --- a/cmd/smyrna/topfisheyeview.c +++ b/cmd/smyrna/topfisheyeview.c @@ -242,7 +242,7 @@ static void drawtopfishnodes(topview * t) glColor4f(color.R, color.G, color.B, (GLfloat) view->defaultnodealpha); - glVertex3f((GLfloat) x0, (GLfloat) y0, (GLfloat) 0); + glVertex3f((GLfloat) x0, (GLfloat) y0, 0.0f); } } } @@ -287,9 +287,8 @@ static void drawtopfishedges(topview * t) if (get_temp_coords(t, level, n, &x, &y)) { - glVertex3f((GLfloat) x0, (GLfloat) y0, - (GLfloat) 0); - glVertex3f((GLfloat) x, (GLfloat) y, (GLfloat) 0); + glVertex3f((GLfloat) x0, (GLfloat) y0, 0.0f); + glVertex3f((GLfloat) x, (GLfloat) y, 0.0f); } else { int levell, nodee; @@ -310,10 +309,8 @@ static void drawtopfishedges(topview * t) continue; - glVertex3f((GLfloat) x0, (GLfloat) y0, - (GLfloat) 0); - glVertex3f((GLfloat) x, (GLfloat) y, - (GLfloat) 0); + glVertex3f((GLfloat) x0, (GLfloat) y0, 0.0f); + glVertex3f((GLfloat) x, (GLfloat) y, 0.0f); } } } diff --git a/lib/glcomp/glcompdefs.h b/lib/glcomp/glcompdefs.h index dcc89c84e..dbcd0ce8f 100644 --- a/lib/glcomp/glcompdefs.h +++ b/lib/glcomp/glcompdefs.h @@ -28,40 +28,40 @@ extern "C" { #endif -#define GLCOMPSET_PANEL_COLOR_R (GLfloat)0.16 -#define GLCOMPSET_PANEL_COLOR_G (GLfloat)0.44 -#define GLCOMPSET_PANEL_COLOR_B (GLfloat)0.87 -#define GLCOMPSET_PANEL_COLOR_ALPHA (GLfloat)0.5 -#define GLCOMPSET_PANEL_SHADOW_COLOR_R (GLfloat)0 -#define GLCOMPSET_PANEL_SHADOW_COLOR_G (GLfloat)0 -#define GLCOMPSET_PANEL_SHADOW_COLOR_B (GLfloat)0 -#define GLCOMPSET_PANEL_SHADOW_COLOR_A (GLfloat)0.3 -#define GLCOMPSET_PANEL_SHADOW_WIDTH (GLfloat)4 - -#define GLCOMPSET_BUTTON_COLOR_R (GLfloat)0 -#define GLCOMPSET_BUTTON_COLOR_G (GLfloat)1 -#define GLCOMPSET_BUTTON_COLOR_B (GLfloat)0.3 -#define GLCOMPSET_BUTTON_COLOR_ALPHA (GLfloat)0.6 -#define GLCOMPSET_BUTTON_THICKNESS (GLfloat)3 -#define GLCOMPSET_BUTTON_BEVEL_BRIGHTNESS (GLfloat)1.7 -#define GLCOMPSET_FONT_SIZE (GLfloat)14 - -#define GLCOMPSET_BUTTON_FONT_COLOR_R (GLfloat)0 -#define GLCOMPSET_BUTTON_FONT_COLOR_G (GLfloat)0 -#define GLCOMPSET_BUTTON_FONT_COLOR_B (GLfloat)0 -#define GLCOMPSET_BUTTON_FONT_COLOR_ALPHA (GLfloat)1 - -#define GLCOMPSET_FONT_SIZE_FACTOR (GLfloat)0.7 - -#define GLCOMPSET_LABEL_COLOR_R (GLfloat)0 -#define GLCOMPSET_LABEL_COLOR_G (GLfloat)0 -#define GLCOMPSET_LABEL_COLOR_B (GLfloat)0 -#define GLCOMPSET_LABEL_COLOR_ALPHA (GLfloat)1 - -#define GLCOMPSET_FONT_COLOR_R (GLfloat)0 -#define GLCOMPSET_FONT_COLOR_G (GLfloat)0 -#define GLCOMPSET_FONT_COLOR_B (GLfloat)0 -#define GLCOMPSET_FONT_COLOR_ALPHA (GLfloat)1 +#define GLCOMPSET_PANEL_COLOR_R 0.16f +#define GLCOMPSET_PANEL_COLOR_G 0.44f +#define GLCOMPSET_PANEL_COLOR_B 0.87f +#define GLCOMPSET_PANEL_COLOR_ALPHA 0.5f +#define GLCOMPSET_PANEL_SHADOW_COLOR_R 0.0f +#define GLCOMPSET_PANEL_SHADOW_COLOR_G 0.0f +#define GLCOMPSET_PANEL_SHADOW_COLOR_B 0.0f +#define GLCOMPSET_PANEL_SHADOW_COLOR_A 0.3f +#define GLCOMPSET_PANEL_SHADOW_WIDTH 4.0f + +#define GLCOMPSET_BUTTON_COLOR_R 0.0f +#define GLCOMPSET_BUTTON_COLOR_G 1.0f +#define GLCOMPSET_BUTTON_COLOR_B 0.3f +#define GLCOMPSET_BUTTON_COLOR_ALPHA 0.6f +#define GLCOMPSET_BUTTON_THICKNESS 3.0f +#define GLCOMPSET_BUTTON_BEVEL_BRIGHTNESS 1.7f +#define GLCOMPSET_FONT_SIZE 14.0f + +#define GLCOMPSET_BUTTON_FONT_COLOR_R 0.0f +#define GLCOMPSET_BUTTON_FONT_COLOR_G 0.0f +#define GLCOMPSET_BUTTON_FONT_COLOR_B 0.0f +#define GLCOMPSET_BUTTON_FONT_COLOR_ALPHA 1.0f + +#define GLCOMPSET_FONT_SIZE_FACTOR 0.7f + +#define GLCOMPSET_LABEL_COLOR_R 0.0f +#define GLCOMPSET_LABEL_COLOR_G 0.0f +#define GLCOMPSET_LABEL_COLOR_B 0.0f +#define GLCOMPSET_LABEL_COLOR_ALPHA 1.0f + +#define GLCOMPSET_FONT_COLOR_R 0.0f +#define GLCOMPSET_FONT_COLOR_G 0.0f +#define GLCOMPSET_FONT_COLOR_B 0.0f +#define GLCOMPSET_FONT_COLOR_ALPHA 1.0f #define GLCOMPSET_FONT_DESC "Times Italic" #define GL_FONTOPTIMIZE 1 @@ -72,13 +72,13 @@ extern "C" { #define DEFAULT_GLUT_FONT GLUT_BITMAP_HELVETICA_12 -#define GLCOMPSET_BORDERWIDTH (GLfloat)2 -#define GLCOMPSET_PANEL_BORDERWIDTH (GLfloat)3 -#define GLCOMPSET_BUTTON_BEVEL (GLfloat)5 -#define GLCOMPSET_BEVEL_DIFF (GLfloat)0.001 -#define GLCOMPSET_DEFAULT_PAD (GLfloat)3 -#define GLCOMP_DEFAULT_WIDTH (GLfloat)10 -#define GLCOMP_DEFAULT_HEIGHT (GLfloat)10 +#define GLCOMPSET_BORDERWIDTH 2.0f +#define GLCOMPSET_PANEL_BORDERWIDTH 3.0f +#define GLCOMPSET_BUTTON_BEVEL 5.0f +#define GLCOMPSET_BEVEL_DIFF 0.001f +#define GLCOMPSET_DEFAULT_PAD 3.0f +#define GLCOMP_DEFAULT_WIDTH 10.0f +#define GLCOMP_DEFAULT_HEIGHT 10.0f diff --git a/lib/glcomp/glcompfont.c b/lib/glcomp/glcompfont.c index 5c4a00378..7702c34d9 100644 --- a/lib/glcomp/glcompfont.c +++ b/lib/glcomp/glcompfont.c @@ -165,7 +165,7 @@ void glCompRenderText(glCompFont * f, glCompObj * parentObj) x = ref.refPos.x + (ref.width - f->tex->width); break; case glFontHJustifyCenter: - x = ref.refPos.x + (ref.width - f->tex->width) / (GLfloat) 2.0; + x = ref.refPos.x + (ref.width - f->tex->width) / 2.0f; break; } switch (f->justify.VJustify) { @@ -177,7 +177,7 @@ void glCompRenderText(glCompFont * f, glCompObj * parentObj) x = ref.refPos.y + (ref.height - f->tex->height); break; case glFontVJustifyCenter: - y = ref.refPos.y + (ref.height - f->tex->height) / (GLfloat) 2.0; + y = ref.refPos.y + (ref.height - f->tex->height) / 2.0f; break; } diff --git a/lib/glcomp/glcompimage.c b/lib/glcomp/glcompimage.c index 4089c42ae..291a9c052 100644 --- a/lib/glcomp/glcompimage.c +++ b/lib/glcomp/glcompimage.c @@ -106,7 +106,7 @@ void glCompImageDraw(void *obj) { w = p->width; h = p->height; - d=(GLfloat)p->common.layer* (GLfloat)GLCOMPSET_BEVEL_DIFF; + d=(GLfloat)p->common.layer * GLCOMPSET_BEVEL_DIFF; glDisable(GL_BLEND); glEnable(GL_TEXTURE_2D); glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL); diff --git a/lib/glcomp/glutils.c b/lib/glcomp/glutils.c index 4d847be5e..a5ae69fff 100644 --- a/lib/glcomp/glutils.c +++ b/lib/glcomp/glutils.c @@ -325,11 +325,11 @@ void glCompDrawRectPrism(glCompPoint * p, GLfloat w, GLfloat h, GLfloat b, glCompPoint A, B, C, D, E, F, G, H; GLfloat dim = 1.00; if (!bumped) { - color_fac = (GLfloat) 1.3; + color_fac = 1.3f; b = b - 2; dim = 0.5; } else - color_fac = (GLfloat) 1 / (GLfloat) 1.3; + color_fac = 1.0f / 1.3f; A.x = p->x; -- 2.40.0