]> granicus.if.org Git - graphviz/commitdiff
use suffixed literals instead of casts to construct 'GLfloat' values
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Fri, 25 Mar 2022 05:13:05 +0000 (22:13 -0700)
committerMatthew Fernandez <matthew.fernandez@gmail.com>
Sat, 26 Mar 2022 18:41:09 +0000 (11:41 -0700)
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
lib/glcomp/glcompdefs.h
lib/glcomp/glcompfont.c
lib/glcomp/glcompimage.c
lib/glcomp/glutils.c

index 347f093aa22453ae5731c590f0c1bf574fa77607..43ad3715ecd0ff684a9b3cff54b49f57c851b7c1 100644 (file)
@@ -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);
                        }
                    }
                }
index dcc89c84e10a2c45593c05a8a5c3d11438f9d6b3..dbcd0ce8f54f5c7e948c28c408953c1c66ae4440 100644 (file)
@@ -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
 
 
 
index 5c4a00378c7d24a0aac85fa8e47c7af2b60a0b59..7702c34d9b2e7fe11e2cf6766ae3e9a5f369dea0 100644 (file)
@@ -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;
     }
 
index 4089c42ae4a3641a28a101069f541f151d852e86..291a9c05295f2c2c5f60a2fbb106c2b0d23aca0b 100644 (file)
@@ -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);
index 4d847be5e3b5205ab864168889c44955c017354d..a5ae69fffb8c0a77e405b079e568eb170cd7f833 100644 (file)
@@ -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;