From bf73c13de463ffeaa66dc8e8607d04ac96dad72e Mon Sep 17 00:00:00 2001 From: Matthew Fernandez Date: Sun, 13 Nov 2022 14:22:03 -0800 Subject: [PATCH] use input gradient angle rather than computed gradient angle when checking for 0 MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit When using radial gradients, a value of 0 is interpreted differently to other values:¹ a value of zero causes the colors to transform radially from the center; for non-zero values, the colors transform from a point near the object’s periphery as specified by the value. The code affected in this commit is looking for this situation, but was unnecessarily using the computed gradient angle. If the original is zero, the computed angle will also be zero. So we can simplify this code for both human readers and the compiler by using the original (integer) angle. This squashes the warnings: gvrender_core_dot.c: In function ‘xdot_gradient_fillcolor’: gvrender_core_dot.c:644:19: warning: comparing floating-point with ‘==’ or ‘!=’ is unsafe [-Wfloat-equal] 644 | if (angle == 0) { | ^~ gvrender_core_svg.c: In function ‘svg_rgradstyle’: gvrender_core_svg.c:602:15: warning: comparing floating-point with ‘==’ or ‘!=’ is unsafe [-Wfloat-equal] 602 | if (angle == 0.) { | ^~ gvrender_pango.c:322:19: warning: comparing floating-point with ‘==’ or ‘!=’ is unsafe [-Wfloat-equal] 322 | if (angle == 0) { | ^~ Gitlab: related to #2313 ¹ https://graphviz.org/docs/attrs/gradientangle/ --- plugin/core/gvrender_core_dot.c | 2 +- plugin/core/gvrender_core_svg.c | 4 ++-- plugin/pango/gvrender_pango.c | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/plugin/core/gvrender_core_dot.c b/plugin/core/gvrender_core_dot.c index bf34e3bba..f30269e73 100644 --- a/plugin/core/gvrender_core_dot.c +++ b/plugin/core/gvrender_core_dot.c @@ -641,7 +641,7 @@ static void xdot_gradient_fillcolor (GVJ_t* job, int filled, pointf* A, int n) get_gradient_points(A, G, n, 0, 3); // r2 is outer radius double r2 = G[1].y; - if (angle == 0) { + if (obj->gradient_angle == 0) { c1.x = G[0].x; c1.y = G[0].y; } diff --git a/plugin/core/gvrender_core_svg.c b/plugin/core/gvrender_core_svg.c index a043ddc43..0c746c197 100644 --- a/plugin/core/gvrender_core_svg.c +++ b/plugin/core/gvrender_core_svg.c @@ -598,10 +598,10 @@ static int svg_rgradstyle(GVJ_t * job) int id = rgradId++; obj_state_t *obj = job->obj; - double angle = obj->gradient_angle * M_PI / 180; //angle of gradient line - if (angle == 0.) { + if (obj->gradient_angle == 0) { ifx = ify = 50; } else { + double angle = obj->gradient_angle * M_PI / 180; //angle of gradient line ifx = round(50 * (1 + cos(angle))); ify = round(50 * (1 - sin(angle))); } diff --git a/plugin/pango/gvrender_pango.c b/plugin/pango/gvrender_pango.c index 5b626390d..fcfc78159 100644 --- a/plugin/pango/gvrender_pango.c +++ b/plugin/pango/gvrender_pango.c @@ -319,7 +319,7 @@ static void cairo_gradient_fill (cairo_t* cr, obj_state_t* obj, int filled, poin //r1 is inner radius, r2 is outer radius r1 = G[1].x; /* Set a r2/4 in get_gradient_points */ r2 = G[1].y; - if (angle == 0) { + if (obj->gradient_angle == 0) { c1.x = G[0].x; c1.y = G[0].y; } -- 2.40.0