]> granicus.if.org Git - graphviz/commitdiff
core plugin: suppress 'penwidth' double comparison warning
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Sat, 12 Nov 2022 23:50:03 +0000 (15:50 -0800)
committerMatthew Fernandez <matthew.fernandez@gmail.com>
Sun, 13 Nov 2022 20:59:58 +0000 (12:59 -0800)
`gvprintdouble` prints to two decimal places. So we can take this into account
when deciding whether we need to print a non-default pen width, squashing:

  gvrender_core_svg.c: In function ‘svg_grstyle’:
  gvrender_core_svg.c:191:23: warning: comparing floating-point with ‘==’ or
    ‘!=’ is unsafe [-Wfloat-equal]
    191 |     if (obj->penwidth != PENWIDTH_NORMAL) {
        |                       ^~

plugin/core/gvrender_core_svg.c

index 6505911427f2f324ac843de5e8d91186ab6bdfed..e26bc0d428fdf165890d97827a861c3cdeaf20d4 100644 (file)
@@ -188,7 +188,9 @@ static void svg_grstyle(GVJ_t * job, int filled, int gid)
     }
     gvputs(job, "\" stroke=\"");
     svg_print_paint(job, obj->pencolor);
-    if (obj->penwidth != PENWIDTH_NORMAL) {
+    // will `gvprintdouble` output something different from `PENWIDTH_NORMAL`?
+    const double GVPRINT_DOUBLE_THRESHOLD = 0.005;
+    if (!(fabs(obj->penwidth - PENWIDTH_NORMAL) < GVPRINT_DOUBLE_THRESHOLD)) {
        gvputs(job, "\" stroke-width=\"");
         gvprintdouble(job, obj->penwidth);
     }