]> granicus.if.org Git - graphviz/commitdiff
use abs() instead of ABS() for taking the absolute value of ints
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Wed, 26 Aug 2020 01:05:38 +0000 (18:05 -0700)
committerMatthew Fernandez <matthew.fernandez@gmail.com>
Tue, 1 Sep 2020 00:11:57 +0000 (17:11 -0700)
Similar to b88ebe0548dd412ea415d6cfc410d91117270277 and the previous commit,
this replaces uses of the macro ABS with standard library functionality for
readability and maintainability.

cmd/gvmap/country_graph_coloring.c
cmd/gvmap/make_map.c
lib/dotgen/dotsplines.c
lib/neatogen/legal.c
lib/pack/pack.c
tclpkg/tclpathplan/intersect.c

index 6a7d3e2dcb940a8bb418ccb34e2955dc152db9e8..86db10a58a6100b93f8a93e4de8b90cccb416773 100644 (file)
@@ -13,6 +13,7 @@
 
 #define STANDALONE
 #include "country_graph_coloring.h"
+#include <math.h>
 #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]);
     }
index 3950c722687c61ae50a93a434d543137488e7b5a..1ac91462d1882e35db872895869dd9084fdbe70d 100644 (file)
@@ -14,6 +14,7 @@
 #define STANDALONE
 #include "SparseMatrix.h"
 #include "general.h"
+#include <math.h>
 #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]];
index 8fd6ad38efc1f10a15a94a0ad68a5ecd30aaff84..2a6753c589baa3c09039b5273a310c08e39e7a97 100644 (file)
@@ -17,6 +17,7 @@
  */
 
 #include "dot.h"
+#include <math.h>
 
 #ifdef ORTHO
 #include <ortho.h>
@@ -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);
index 91ae3b46ae6d7e59aca510fc6367fe37547e0066..58d85e4413018cb0200ffac25470a65625975b76 100644 (file)
@@ -11,6 +11,7 @@
  * Contributors: See CVS logs. Details at http://www.graphviz.org/
  *************************************************************************/
 
+#include <math.h>
 #include "neato.h"
 #include "pathutil.h"
 #include <setjmp.h>
@@ -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
index 396df0e660aff7349ee9e5ca17c6578ef5ba8023..215644eec378f9b34d612017242f1d0e080a5aa9 100644 (file)
@@ -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); */
index 75081326598cfe2277b7c48946647bec3c2eb2ec..40981b974e62732620f7fc640b3a5bc7bd2ac200 100644 (file)
@@ -11,6 +11,7 @@
  * Contributors: See CVS logs. Details at http://www.graphviz.org/
  *************************************************************************/
 
+#include <math.h>
 #include <stdio.h>
 #include "simple.h"
 #include <stdlib.h>
@@ -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) {