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/
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;
}
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)));
}
//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;
}