From c6079f03ebcf9f1fad612351429bffda3e52136c Mon Sep 17 00:00:00 2001 From: Matthew Fernandez Date: Fri, 12 Nov 2021 17:29:12 -0800 Subject: [PATCH] get_gradient_points: take 'angle' as a double instead of a float The originating values used to compute an angle were generally doubles and computation was done in `get_gradient_points` as if this value was a double (e.g. calling `sin` and `cos`). Treating it consistently as a double squashes a number of -Wfloat-conversion compiler warnings and improves precision. --- lib/common/utils.c | 3 +-- lib/common/utils.h | 3 ++- plugin/core/gvrender_core_dot.c | 2 +- plugin/core/gvrender_core_svg.c | 3 +-- plugin/pango/gvrender_pango.c | 2 +- 5 files changed, 6 insertions(+), 7 deletions(-) diff --git a/lib/common/utils.c b/lib/common/utils.c index 0ab5ff7f4..bc6f6144e 100644 --- a/lib/common/utils.c +++ b/lib/common/utils.c @@ -1743,8 +1743,7 @@ void setEdgeType (graph_t* g, int dflt) * By default, this assumes a left-hand coordinate system (for svg); if RHS = 2 flag * is set, use standard coordinate system. */ -void get_gradient_points(pointf * A, pointf * G, int n, float angle, int flags) -{ +void get_gradient_points(pointf *A, pointf *G, int n, double angle, int flags) { int i; double rx, ry; pointf min,max,center; diff --git a/lib/common/utils.h b/lib/common/utils.h index 80d231749..11021b9ed 100644 --- a/lib/common/utils.h +++ b/lib/common/utils.h @@ -106,7 +106,8 @@ extern "C" { UTILS_API bool overlap_label(textlabel_t *lp, boxf b); UTILS_API bool overlap_edge(edge_t *e, boxf b); - UTILS_API void get_gradient_points(pointf * A, pointf * G, int n, float angle, int flags); + UTILS_API void get_gradient_points(pointf *A, pointf *G, int n, + double angle, int flags); UTILS_API void processClusterEdges(graph_t * g); diff --git a/plugin/core/gvrender_core_dot.c b/plugin/core/gvrender_core_dot.c index 9c827a1f0..8eb43e2d8 100644 --- a/plugin/core/gvrender_core_dot.c +++ b/plugin/core/gvrender_core_dot.c @@ -614,7 +614,7 @@ static void xdot_gradient_fillcolor (GVJ_t* job, int filled, pointf* A, int n) unsigned char buf0[BUFSIZ]; agxbuf xb; obj_state_t* obj = job->obj; - float angle = obj->gradient_angle * M_PI / 180; + double angle = obj->gradient_angle * M_PI / 180; float r1,r2; pointf G[2],c1,c2; diff --git a/plugin/core/gvrender_core_svg.c b/plugin/core/gvrender_core_svg.c index 24f3a3959..0fef81c45 100644 --- a/plugin/core/gvrender_core_svg.c +++ b/plugin/core/gvrender_core_svg.c @@ -493,12 +493,11 @@ static void svg_textspan(GVJ_t * job, pointf p, textspan_t * span) static int svg_gradstyle(GVJ_t * job, pointf * A, int n) { pointf G[2]; - float angle; static int gradId; int id = gradId++; obj_state_t *obj = job->obj; - angle = obj->gradient_angle * M_PI / 180; //angle of gradient line + double angle = obj->gradient_angle * M_PI / 180; //angle of gradient line G[0].x = G[0].y = G[1].x = G[1].y = 0.; get_gradient_points(A, G, n, angle, 0); //get points on gradient line diff --git a/plugin/pango/gvrender_pango.c b/plugin/pango/gvrender_pango.c index f3a76a0b9..5b626390d 100644 --- a/plugin/pango/gvrender_pango.c +++ b/plugin/pango/gvrender_pango.c @@ -306,7 +306,7 @@ static void cairogen_set_penstyle(GVJ_t *job, cairo_t *cr) static void cairo_gradient_fill (cairo_t* cr, obj_state_t* obj, int filled, pointf* A, int n) { cairo_pattern_t* pat; - float angle = obj->gradient_angle * M_PI / 180; + double angle = obj->gradient_angle * M_PI / 180; float r1,r2; pointf G[2],c1; -- 2.50.1