From: Matthew Fernandez Date: Wed, 26 Aug 2020 01:05:38 +0000 (-0700) Subject: use abs() instead of ABS() for taking the absolute value of ints X-Git-Tag: 2.46.0~20^2^2~100^2~1 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=4cf0f141cd5103bbee41dc2c54cce2145926bafe;p=graphviz use abs() instead of ABS() for taking the absolute value of ints Similar to b88ebe0548dd412ea415d6cfc410d91117270277 and the previous commit, this replaces uses of the macro ABS with standard library functionality for readability and maintainability. --- diff --git a/cmd/gvmap/country_graph_coloring.c b/cmd/gvmap/country_graph_coloring.c index 6a7d3e2dc..86db10a58 100644 --- a/cmd/gvmap/country_graph_coloring.c +++ b/cmd/gvmap/country_graph_coloring.c @@ -13,6 +13,7 @@ #define STANDALONE #include "country_graph_coloring.h" +#include #include "power.h" /* #include "general.h" */ @@ -29,9 +30,9 @@ static void get_local_12_norm(int n, int i, int *ia, int *ja, int *p, real *norm norm[0] = n; norm[1] = 0; for (j = ia[i]; j < ia[i+1]; j++){ if (ja[j] == i) continue; - norm[0] = MIN(norm[0], ABS(p[i] - p[ja[j]])); + norm[0] = MIN(norm[0], abs(p[i] - p[ja[j]])); nz++; - norm[1] += ABS(p[i] - p[ja[j]]); + norm[1] += abs(p[i] - p[ja[j]]); } if (nz > 0) norm[1] /= nz; } @@ -47,9 +48,9 @@ static void get_12_norm(int n, int *ia, int *ja, int *p, real *norm){ tmp = n; for (j = ia[i]; j < ia[i+1]; j++){ if (ja[j] == i) continue; - norm[0] = MIN(norm[0], ABS(p[i] - p[ja[j]])); - norm[1] += ABS(p[i] - p[ja[j]]); - tmp = MIN(tmp, ABS(p[i] - p[ja[j]])); + norm[0] = MIN(norm[0], abs(p[i] - p[ja[j]])); + norm[1] += abs(p[i] - p[ja[j]]); + tmp = MIN(tmp, abs(p[i] - p[ja[j]])); nz++; } norm[2] += tmp; @@ -63,9 +64,9 @@ static void update_pmin_pmax_aband(int n, int u, int *ia, int *ja, int *p, int * pmin[u] = n; pmax[u] = -1; aband_u = n; for (j = ia[u]; j < ia[u+1]; j++) { if (ja[j] == u) continue; - pmin[u] = MIN(pmin[u], ABS(p[u] - p[ja[j]])); - pmax[u] = MIN(pmax[u], ABS(p[u] - p[ja[j]])); - aband_u = MIN(aband_u, ABS(p[u] - p[ja[j]])); + pmin[u] = MIN(pmin[u], abs(p[u] - p[ja[j]])); + pmax[u] = MIN(pmax[u], abs(p[u] - p[ja[j]])); + aband_u = MIN(aband_u, abs(p[u] - p[ja[j]])); } aband_local[u] = aband_u; } @@ -83,27 +84,27 @@ static int check_swap(int n, int *ia, int *ja, /* if swaping u and v makes v worse & becomes/remains critical, don't do. We first quick check using the max/min neighbor indices. No need to check the other way around since the calling function have ensured that. */ - if (ABS(p_u - pmin[v]) < aband_v && ABS(p_u - pmin[v]) <= lambda*aband) return FALSE; - if (ABS(p_u - pmax[v]) < aband_v && ABS(p_u - pmax[v]) <= lambda*aband) return FALSE; + if (abs(p_u - pmin[v]) < aband_v && abs(p_u - pmin[v]) <= lambda*aband) return FALSE; + if (abs(p_u - pmax[v]) < aband_v && abs(p_u - pmax[v]) <= lambda*aband) return FALSE; /* now check in details whether v should swap to u. Do not accept if this makes the antiband width of u worse */ aband_u1 = n; for (j = ja[u]; j < ja[u+1]; j++){ if (ja[j] == u) continue; - if (ABS(p_v - p[ja[j]]) < aband_u) { + if (abs(p_v - p[ja[j]]) < aband_u) { return FALSE; } - aband_u1 = MIN(aband_u1, ABS(p_v - p[ja[j]])); + aband_u1 = MIN(aband_u1, abs(p_v - p[ja[j]])); } /* now check in details whether u should swap to v. Do not accept if this makes antibandwidth of v worse && make/keep v in the critical group */ aband_v1 = n; for (j = ja[v]; j < ja[v+1]; j++){ if (ja[j] == v) continue; - if (ABS(p_u - p[ja[j]]) < aband_v && ABS(p_u - p[ja[j]]) <= lambda*aband) { + if (abs(p_u - p[ja[j]]) < aband_v && abs(p_u - p[ja[j]]) <= lambda*aband) { return FALSE; } - aband_v1 = MIN(aband_v1, ABS(p_u - p[ja[j]])); + aband_v1 = MIN(aband_v1, abs(p_u - p[ja[j]])); } /* now check if local antiband width has been improved. By that we mean u is improved, or u unchanged, but v improved. */ @@ -165,7 +166,7 @@ void improve_antibandwidth_by_swapping_cheap(SparseMatrix A, int *p){ if (ja[j] == i) continue; pmax[i] = MAX(pmax[i], p[ja[j]]); pmin[i] = MIN(pmin[i], p[ja[j]]); - aband_local[i] = MIN(aband_local[i], ABS(p[i] - p[ja[j]])); + aband_local[i] = MIN(aband_local[i], abs(p[i] - p[ja[j]])); } aband = MIN(aband, aband_local[i]); } diff --git a/cmd/gvmap/make_map.c b/cmd/gvmap/make_map.c index 3950c7226..1ac91462d 100644 --- a/cmd/gvmap/make_map.c +++ b/cmd/gvmap/make_map.c @@ -14,6 +14,7 @@ #define STANDALONE #include "SparseMatrix.h" #include "general.h" +#include #include "QuadTree.h" #include "string.h" /* #include "types.h" */ @@ -766,13 +767,13 @@ void plot_dot_polygons(char **sbuff, int *len, int *len_max, real line_width, ch yp = MALLOC(sizeof(float)*maxlen); if (Verbose) fprintf(stderr,"npolys = %d\n",npolys); - first = ABS(a[0]); ipoly = first + 1; + first = abs(a[0]); ipoly = first + 1; for (i = 0; i < npolys; i++){ np = 0; for (j = ia[i]; j < ia[i+1]; j++){ assert(ja[j] < nverts && ja[j] >= 0); - if (ABS(a[j]) != ipoly){/* the first poly, or a hole */ - ipoly = ABS(a[j]); + if (abs(a[j]) != ipoly){/* the first poly, or a hole */ + ipoly = abs(a[j]); is_river = (a[j] < 0); if (r && g && b) { rgb2hex(r[polys_groups[i]], g[polys_groups[i]], b[polys_groups[i]], cstring, opacity); @@ -810,13 +811,13 @@ void plot_processing_polygons(FILE *f, real line_width, SparseMatrix polys, real yp = MALLOC(sizeof(float)*maxlen); if (Verbose) fprintf(stderr,"npolys = %d\n",npolys); - first = ABS(a[0]); ipoly = first + 1; + first = abs(a[0]); ipoly = first + 1; for (i = 0; i < npolys; i++){ np = 0; for (j = ia[i]; j < ia[i+1]; j++){ assert(ja[j] < nverts && ja[j] >= 0); - if (ABS(a[j]) != ipoly){/* the first poly, or a hole */ - ipoly = ABS(a[j]); + if (abs(a[j]) != ipoly){/* the first poly, or a hole */ + ipoly = abs(a[j]); is_river = (a[j] < 0); if (r && g && b) { rr = r[polys_groups[i]]; gg = g[polys_groups[i]]; bb = b[polys_groups[i]]; diff --git a/lib/dotgen/dotsplines.c b/lib/dotgen/dotsplines.c index 8fd6ad38e..2a6753c58 100644 --- a/lib/dotgen/dotsplines.c +++ b/lib/dotgen/dotsplines.c @@ -17,6 +17,7 @@ */ #include "dot.h" +#include #ifdef ORTHO #include @@ -605,15 +606,15 @@ static int edgecmp(edge_t** ptr0, edge_t** ptr1) t0 = ND_rank(agtail(le0)) - ND_rank(aghead(le0)); t1 = ND_rank(agtail(le1)) - ND_rank(aghead(le1)); - v0 = ABS((int)t0); /* ugly, but explicit as to how we avoid equality tests on fp numbers */ - v1 = ABS((int)t1); + v0 = abs((int)t0); /* ugly, but explicit as to how we avoid equality tests on fp numbers */ + v1 = abs((int)t1); if (v0 != v1) return (v0 - v1); t0 = ND_coord(agtail(le0)).x - ND_coord(aghead(le0)).x; t1 = ND_coord(agtail(le1)).x - ND_coord(aghead(le1)).x; - v0 = ABS((int)t0); - v1 = ABS((int)t1); + v0 = abs((int)t0); + v1 = abs((int)t1); if (v0 != v1) return (v0 - v1); @@ -1674,7 +1675,7 @@ makeLineEdge(graph_t* g, edge_t* fe, pointf* points, node_t** hp) e = ED_to_orig(e); hn = aghead(e); tn = agtail(e); - delr = ABS(ND_rank(hn)-ND_rank(tn)); + delr = abs(ND_rank(hn)-ND_rank(tn)); if ((delr == 1) || ((delr == 2) && (GD_has_labels(g->root) & EDGE_LABEL))) return 0; if (agtail(fe) == agtail(e)) { @@ -1757,7 +1758,7 @@ make_regular_edge(graph_t* g, spline_info_t* sp, path * P, edge_t ** edges, int sl = 0; e = edges[ind]; hackflag = FALSE; - if (ABS(ND_rank(agtail(e)) - ND_rank(aghead(e))) > 1) { + if (abs(ND_rank(agtail(e)) - ND_rank(aghead(e))) > 1) { fwdedgeai = *(Agedgeinfo_t*)e->base.data; fwdedgea.out = *e; fwdedgea.in = *AGOUT2IN(e); diff --git a/lib/neatogen/legal.c b/lib/neatogen/legal.c index 91ae3b46a..58d85e441 100644 --- a/lib/neatogen/legal.c +++ b/lib/neatogen/legal.c @@ -11,6 +11,7 @@ * Contributors: See CVS logs. Details at http://www.graphviz.org/ *************************************************************************/ +#include #include "neato.h" #include "pathutil.h" #include @@ -231,13 +232,13 @@ static int find_intersection(vertex *l, if (i[2] > 0) return 0; if (!intpoint - (l, m, &x, &y, (i[2] < 0) ? 3 : online(m, l, ABS(i[0])))) + (l, m, &x, &y, (i[2] < 0) ? 3 : online(m, l, abs(i[0])))) return 0; } else if (!intpoint(l, m, &x, &y, (i[0] == i[1]) ? 2 * MAX(online(l, m, 0), - online(l, m, 1)) : online(l, m, ABS(i[0])))) + online(l, m, 1)) : online(l, m, abs(i[0])))) return 0; #ifdef RECORD_INTERSECTS diff --git a/lib/pack/pack.c b/lib/pack/pack.c index 396df0e66..215644eec 100644 --- a/lib/pack/pack.c +++ b/lib/pack/pack.c @@ -117,10 +117,10 @@ static void fillLine(pointf p, pointf q, PointSet * ps) int d, x, y, ax, ay, sx, sy, dx, dy; dx = x2 - x1; - ax = ABS(dx) << 1; + ax = abs(dx) << 1; sx = SGN(dx); dy = y2 - y1; - ay = ABS(dy) << 1; + ay = abs(dy) << 1; sy = SGN(dy); /* fprintf (stderr, "fillLine %d %d - %d %d\n", x1,y1,x2,y2); */ diff --git a/tclpkg/tclpathplan/intersect.c b/tclpkg/tclpathplan/intersect.c index 750813265..40981b974 100644 --- a/tclpkg/tclpathplan/intersect.c +++ b/tclpkg/tclpathplan/intersect.c @@ -11,6 +11,7 @@ * Contributors: See CVS logs. Details at http://www.graphviz.org/ *************************************************************************/ +#include #include #include "simple.h" #include @@ -142,13 +143,13 @@ void find_intersection(struct vertex *l, if (i[2] > 0) return; if (!intpoint - (l, m, &x, &y, (i[2] < 0) ? 3 : online(m, l, ABS(i[0])))) + (l, m, &x, &y, (i[2] < 0) ? 3 : online(m, l, abs(i[0])))) return; } else if (!intpoint(l, m, &x, &y, (i[0] == i[1]) ? 2 * MAX(online(l, m, 0), - online(l, m, 1)) : online(l, m, ABS(i[0])))) + online(l, m, 1)) : online(l, m, abs(i[0])))) return; if (input->ninters >= MAXINTS) {